Skip to content

Commit c586362

Browse files
karlo0klcoba
andauthored
Bugfix #17149: Asciidoc generator sets not defined example values wrongly to the string value "null" instead of the expected not set value (#20670)
Co-authored-by: Karsten Leonhardt <[email protected]>
1 parent a6280d9 commit c586362

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java

+23
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package org.openapitools.codegen.languages;
1818

19+
import io.swagger.v3.oas.models.media.Schema;
1920
import lombok.Getter;
2021
import lombok.Setter;
22+
import io.swagger.v3.oas.models.media.Schema;
2123
import org.openapitools.codegen.*;
2224

2325
import java.io.File;
@@ -326,6 +328,27 @@ private void processBooleanFlag(String flag, boolean value) {
326328
}
327329
}
328330

331+
// override to avoid printing of string "null"
332+
// when no example exists
333+
@Override
334+
public String toExampleValue(Schema schema) {
335+
if (schema.getExample() != null) {
336+
return schema.getExample().toString();
337+
}
338+
return null;
339+
}
340+
341+
// Avoid additional escapes of \ -> \\, " -> \"
342+
// in regular expressions that are
343+
// introduced by the `escapeText` method.
344+
// Note: We don't need this here since we want to print
345+
// the plain regular expression
346+
// Therefore, override this method to skip `escapeText`.
347+
@Override
348+
public String toRegularExpression(String pattern) {
349+
return addRegularExpressionDelimiter(pattern);
350+
}
351+
329352
@Override
330353
public void processOpenAPI(OpenAPI openAPI) {
331354
if (this.includeSpecMarkupLambda != null) {

0 commit comments

Comments
 (0)