From c5863629c0a9b6b04d3ad6ce4edf13ad32f783a4 Mon Sep 17 00:00:00 2001 From: Karsten Leonhardt <43497013+karlo0@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:18:37 +0100 Subject: [PATCH] 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 --- .../AsciidocDocumentationCodegen.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java index abd15101b14..e022e232a1d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java @@ -16,8 +16,10 @@ package org.openapitools.codegen.languages; +import io.swagger.v3.oas.models.media.Schema; import lombok.Getter; import lombok.Setter; +import io.swagger.v3.oas.models.media.Schema; import org.openapitools.codegen.*; import java.io.File; @@ -326,6 +328,27 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code } } + // override to avoid printing of string "null" + // when no example exists + @Override + public String toExampleValue(Schema schema) { + if (schema.getExample() != null) { + return schema.getExample().toString(); + } + return null; + } + + // Avoid additional escapes of \ -> \\, " -> \" + // in regular expressions that are + // introduced by the `escapeText` method. + // Note: We don't need this here since we want to print + // the plain regular expression + // Therefore, override this method to skip `escapeText`. + @Override + public String toRegularExpression(String pattern) { + return addRegularExpressionDelimiter(pattern); + } + @Override public void processOpenAPI(OpenAPI openAPI) { if (this.includeSpecMarkupLambda != null) {