From 7c6615d55c08361022d661b3560ef7d99c043ac3 Mon Sep 17 00:00:00 2001 From: peter-em Date: Tue, 22 Sep 2026 17:23:58 +0200 Subject: [PATCH 1/3] Add examples parameter in @Schema annotation for OAS 3.1 spec --- .../openapitools/codegen/CodegenProperty.java | 12 +++- .../openapitools/codegen/DefaultCodegen.java | 65 ++++++++++++++++++- .../main/resources/JavaSpring/pojo.mustache | 2 +- .../codegen/DefaultCodegenTest.java | 17 +++++ .../java/spring/SpringCodegenTest.java | 13 ++++ .../src/test/resources/3_1/issue_24755.yaml | 41 ++++++++++++ 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index c854389be7b2..792cdba08032 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -98,6 +98,11 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti */ @Getter @Setter public String example; + /** + * A free-form property to include a list of examples of an instance for this schema. + */ + @Getter @Setter + public List examples; @Getter @Setter public String jsonSchema; @@ -615,6 +620,9 @@ public CodegenProperty clone() { if (this.allowableValues != null) { cp.allowableValues = new HashMap(this.allowableValues); } + if (this.examples != null) { + cp.examples = new ArrayList(this.examples); + } if (this.items != null) { cp.items = this.items; } @@ -996,6 +1004,7 @@ public String toString() { sb.append(", minLength=").append(minLength); sb.append(", pattern='").append(pattern).append('\''); sb.append(", example='").append(example).append('\''); + sb.append(", examples=").append(examples); sb.append(", jsonSchema='").append(jsonSchema).append('\''); sb.append(", minimum='").append(minimum).append('\''); sb.append(", maximum='").append(maximum).append('\''); @@ -1183,6 +1192,7 @@ public boolean equals(Object o) { Objects.equals(minLength, that.minLength) && Objects.equals(pattern, that.pattern) && Objects.equals(example, that.example) && + Objects.equals(examples, that.examples) && Objects.equals(jsonSchema, that.jsonSchema) && Objects.equals(minimum, that.minimum) && Objects.equals(maximum, that.maximum) && @@ -1213,7 +1223,7 @@ public int hashCode() { return Objects.hash(openApiType, baseName, complexType, getter, setter, description, dataType, datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam, baseType, containerType, containerTypeMapped, title, unescapedDescription, - maxLength, minLength, pattern, example, jsonSchema, minimum, maximum, + maxLength, minLength, pattern, example, examples, jsonSchema, minimum, maximum, exclusiveMinimum, exclusiveMaximum, required, deprecated, isPrimitiveType, isModel, isContainer, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile, diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 0a281b9211b6..858f987457a8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -25,6 +25,7 @@ import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Mustache.Compiler; import com.samskivert.mustache.Mustache.Lambda; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.core.util.Json; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; @@ -2560,6 +2561,45 @@ public String toExampleValue(Schema schema) { return "null"; } + /** + * Return the list of example values of the property. + *

+ * This method should be overridden in the generator to meet its requirement. + * + * @param schema Property schema + * @return a string list of the example values of the property + */ + public List toExampleValues(Schema schema) { + List schemaExamples = schema.getExamples(); + if (schemaExamples == null || schemaExamples.isEmpty()) { + return null; + } + List examples = schemaExamples.stream() + .map(this::getExampleValueString) + .collect(Collectors.toList()); + + return examples.isEmpty() ? null : examples; + } + + /** + * Return the string presentation of a single example value. + *

+ * For value nodes, {@link JsonNode#asText()} is used to get the string without duplicated quotes. + * + * @param example the raw example value coming from the parsed schema + * @return string presentation of the example value + */ + protected String getExampleValueString(Object example) { + if (example == null) { + return "null"; + } + if (example instanceof JsonNode) { + JsonNode node = (JsonNode) example; + return node.isValueNode() ? node.asText() : node.toString(); + } + return example.toString(); + } + /** * Return the default value of the property *

@@ -4286,9 +4326,19 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo try { property.example = toExampleValue(p); } catch (Exception e) { - LOGGER.error("Error in generating `example` for the property {}. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.", property.baseName); - LOGGER.debug("Exception from toExampleValue: {}", e.getMessage()); - property.example = "ERROR_TO_EXAMPLE_VALUE"; + property.example = handleExampleException(property.baseName, e); + } + + if (p.getExamples() != null) { + List examples = new ArrayList<>(); + for (Object example : p.getExamples()) { + try { + examples.add(getExampleValueString(example)); + } catch (Exception e) { + examples.add(handleExampleException(property.baseName, e)); + } + } + property.examples = examples; } property.jsonSchema = Json.pretty(Json.mapper().convertValue(p, TreeMap.class)); @@ -4513,6 +4563,9 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo if (original.getExample() != null) { property.example = toExampleValue(original); } + if (original.getExamples() != null) { + property.examples = toExampleValues(original); + } } // override defaultValue if it's not set and defaultToEmptyContainer is set @@ -4529,6 +4582,12 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo return property; } + private String handleExampleException(String propertyName, Exception e) { + LOGGER.error("Error in generating `example` for the property {}. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.", propertyName); + LOGGER.debug("Exception from toExampleValue: {}", e.getMessage()); + return "ERROR_TO_EXAMPLE_VALUE"; + } + /** * update container's default to empty container according rules provided by the user. * diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache index b0ac0565b6f9..a5bac6c7e47b 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache @@ -228,7 +228,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}} {{>beanValidation}}{{! prevent indent}} {{/useBeanValidation}} {{#swagger2AnnotationLibrary}} - @Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}{{#deprecated}}, deprecated = true{{/deprecated}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}{{#isNullable}}, nullable = true{{/isNullable}}) + @Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#examples.0}}, examples = { {{#examples}}"{{{.}}}"{{^-last}}, {{/-last}}{{/examples}} }{{/examples.0}}{{#description}}, description = "{{{.}}}"{{/description}}{{#deprecated}}, deprecated = true{{/deprecated}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}{{#isNullable}}, nullable = true{{/isNullable}}) {{/swagger2AnnotationLibrary}} {{#swagger1AnnotationLibrary}} @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}") diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index ae92cae3a940..a633e581520a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -2296,6 +2296,23 @@ public void testAllOfSingleRefSiblingExample() { assertEquals("Ref-Property-Example", codegen.fromProperty("refProperty", (Schema) testProperties.get("refProperty")).example); } + @Test + public void testOas31SchemaExamplesHandling() { + final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/issue_24755.yaml"); + final DefaultCodegen codegen = new DefaultCodegen(); + codegen.setOpenAPI(openAPI); + + final Map properties = openAPI.getComponents().getSchemas().get("Pet").getProperties(); + + assertThat(codegen.fromProperty("name", (Schema) properties.get("name")).examples) + .containsExactly("Fluffy", "Rex"); + assertThat(codegen.fromProperty("age", (Schema) properties.get("age")).examples) + .containsExactly("3"); + assertThat(codegen.fromProperty("tags", (Schema) properties.get("tags")).examples) + .containsExactly("[\"a\",\"b\"]"); + assertNull(codegen.fromProperty("height", (Schema) properties.get("height")).examples); + } + @Test public void testDeprecatedRef() { final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/model-deprecated.yaml"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 1a75ebd3c779..b3bfc86ad0e1 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -11592,4 +11592,17 @@ public void useRecordsLogsNoModelThatHasNoFile() throws IOException { assertThat(messages).noneMatch(m -> m.contains("model 'URI'")); } + + @Test + public void shouldRenderOas31SchemaExamples() throws IOException { + Map files = generateFromContract("src/test/resources/3_1/issue_24755.yaml", SPRING_BOOT); + + JavaFileAssert.assertThat(files.get("Pet.java")) + .fileContains( + "example = \"Fluffy\"", + "examples = { \"Fluffy\", \"Rex\" }", + "examples = { \"3\" }", + "examples = { \"[a, b]\" }" + ).fileDoesNotContain("examples = {}"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml new file mode 100644 index 000000000000..5983d996021a --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml @@ -0,0 +1,41 @@ +openapi: 3.1.0 +info: + title: Example API + version: 1.0.0 +paths: + /pets: + get: + operationId: listPets + responses: + '200': + description: ok + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' +components: + schemas: + Pet: + type: object + properties: + name: + type: string + example: 'Fluffy' + examples: + - 'Fluffy' + - 'Rex' + age: + type: integer + examples: + - 3 + height: + type: integer + examples: [] + tags: + type: array + items: + type: string + examples: + - ['a', 'b'] From 7f0febbe7b44254e4032201f17403f299716e29d Mon Sep 17 00:00:00 2001 From: peter-em Date: Fri, 25 Sep 2026 15:58:18 +0200 Subject: [PATCH 2/3] Apply PR comments, update example parsing logic, add missing sample --- .../openapitools/codegen/DefaultCodegen.java | 23 ++++++++----------- .../languages/AbstractJavaCodegen.java | 15 ++++++------ .../codegen/DefaultCodegenTest.java | 6 ++--- .../java/spring/SpringCodegenTest.java | 8 +++---- .../src/test/resources/3_1/issue_24755.yaml | 6 ++--- .../handler/PathHandlerInterface.java | 6 ++--- 6 files changed, 29 insertions(+), 35 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 858f987457a8..e169998181aa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2554,11 +2554,7 @@ public void setParameterEncodingValues(CodegenParameter codegenParameter, MediaT * @return string presentation of the example value of the property */ public String toExampleValue(Schema schema) { - if (schema.getExample() != null) { - return schema.getExample().toString(); - } - - return "null"; + return getExampleValueToString(schema.getExample()); } /** @@ -2574,22 +2570,21 @@ public List toExampleValues(Schema schema) { if (schemaExamples == null || schemaExamples.isEmpty()) { return null; } - List examples = schemaExamples.stream() - .map(this::getExampleValueString) - .collect(Collectors.toList()); - - return examples.isEmpty() ? null : examples; + return schemaExamples.stream() + .map(this::getExampleValueToString) + .collect(Collectors.toList()); } /** * Return the string presentation of a single example value. *

+ * This method should be overridden in the generator to meet its requirement. * For value nodes, {@link JsonNode#asText()} is used to get the string without duplicated quotes. * * @param example the raw example value coming from the parsed schema * @return string presentation of the example value */ - protected String getExampleValueString(Object example) { + protected String getExampleValueToString(Object example) { if (example == null) { return "null"; } @@ -4333,7 +4328,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo List examples = new ArrayList<>(); for (Object example : p.getExamples()) { try { - examples.add(getExampleValueString(example)); + examples.add(getExampleValueToString(example)); } catch (Exception e) { examples.add(handleExampleException(property.baseName, e)); } @@ -4583,8 +4578,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo } private String handleExampleException(String propertyName, Exception e) { - LOGGER.error("Error in generating `example` for the property {}. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.", propertyName); - LOGGER.debug("Exception from toExampleValue: {}", e.getMessage()); + LOGGER.error("Error in generating example for the property {}. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.", propertyName); + LOGGER.debug("Exception from example handling: {}", e.getMessage()); return "ERROR_TO_EXAMPLE_VALUE"; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index e48d7347c82c..3c6a2f1f0c32 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -1971,16 +1971,15 @@ private String escapeStringLiteral(String input) { } @Override - public String toExampleValue(Schema p) { - if (p.getExample() != null) { - if (p.getExample() instanceof Date) { - Date date = (Date) p.getExample(); - return DateTimeFormatter.ISO_LOCAL_DATE.format(ZonedDateTime.ofInstant(date.toInstant(), UTC)); - } - return escapeText(p.getExample().toString()); - } else { + protected String getExampleValueToString(Object example) { + if (example == null) { return null; } + if (example instanceof Date) { + Date date = (Date) example; + return DateTimeFormatter.ISO_LOCAL_DATE.format(ZonedDateTime.ofInstant(date.toInstant(), UTC)); + } + return escapeText(super.getExampleValueToString(example)); } @Override diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index a633e581520a..df4132487867 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -2305,12 +2305,12 @@ public void testOas31SchemaExamplesHandling() { final Map properties = openAPI.getComponents().getSchemas().get("Pet").getProperties(); assertThat(codegen.fromProperty("name", (Schema) properties.get("name")).examples) - .containsExactly("Fluffy", "Rex"); + .containsExactly("Fluffy-\\s;]\"a", "Rex"); assertThat(codegen.fromProperty("age", (Schema) properties.get("age")).examples) .containsExactly("3"); assertThat(codegen.fromProperty("tags", (Schema) properties.get("tags")).examples) - .containsExactly("[\"a\",\"b\"]"); - assertNull(codegen.fromProperty("height", (Schema) properties.get("height")).examples); + .containsExactly("[\"a\\\"c\",\"b\"]"); + assertThat(codegen.fromProperty("height", (Schema) properties.get("height")).examples).isNullOrEmpty(); } @Test diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index b3bfc86ad0e1..f68034ff4f4b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -11599,10 +11599,10 @@ public void shouldRenderOas31SchemaExamples() throws IOException { JavaFileAssert.assertThat(files.get("Pet.java")) .fileContains( - "example = \"Fluffy\"", - "examples = { \"Fluffy\", \"Rex\" }", + "example = \"Fluffy-\\\\s;]\\\"a\"", + "examples = { \"Fluffy-\\\\s;]\\\"a\", \"Rex\" }", "examples = { \"3\" }", - "examples = { \"[a, b]\" }" - ).fileDoesNotContain("examples = {}"); + "examples = { \"[a\\\"c, b]\" }" + ).fileDoesNotContain("examples = { }"); } } diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml index 5983d996021a..02f614a749e2 100644 --- a/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/issue_24755.yaml @@ -22,9 +22,9 @@ components: properties: name: type: string - example: 'Fluffy' + example: 'Fluffy-\s;]"a' examples: - - 'Fluffy' + - 'Fluffy-\s;]"a' - 'Rex' age: type: integer @@ -38,4 +38,4 @@ components: items: type: string examples: - - ['a', 'b'] + - ['a"c', 'b'] diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java index d5faaeaaa5fe..827ade4c58da 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java @@ -574,13 +574,13 @@ public interface PathHandlerInterface { *

* * - *

Response headers: [CodegenProperty{openApiType='string', baseName='Set-Cookie', complexType='null', getter='getSetCookie', setter='setSetCookie', description='Cookie authentication key for use with the `api_key` apiKey authentication.', dataType='String', datatypeWithEnum='String', dataFormat='null', name='setCookie', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.Set-Cookie;', baseType='String', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='Cookie authentication key for use with the `api_key` apiKey authentication.', maxLength=null, minLength=null, pattern='null', example='AUTH_KEY=abcde12345; Path=/; HttpOnly', jsonSchema='{ + *

Response headers: [CodegenProperty{openApiType='string', baseName='Set-Cookie', complexType='null', getter='getSetCookie', setter='setSetCookie', description='Cookie authentication key for use with the `api_key` apiKey authentication.', dataType='String', datatypeWithEnum='String', dataFormat='null', name='setCookie', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.Set-Cookie;', baseType='String', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='Cookie authentication key for use with the `api_key` apiKey authentication.', maxLength=null, minLength=null, pattern='null', example='AUTH_KEY=abcde12345; Path=/; HttpOnly', examples=null, jsonSchema='{ "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", "type" : "string" -}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='setCookie', nameInPascalCase='SetCookie', nameInSnakeCase='SET_COOKIE', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}, CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='setCookie', nameInPascalCase='SetCookie', nameInSnakeCase='SET_COOKIE', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}, CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', examples=null, jsonSchema='{ "format" : "int32", "type" : "integer" -}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xRateLimit', nameInPascalCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xRateLimit', nameInPascalCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', examples=null, jsonSchema='{ "format" : "date-time", "type" : "string" }', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xExpiresAfter', nameInPascalCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=date-time, dependentRequired=null, contains=null}]

From 34b43add8e931126c4e9d8d4c20b6ba2dcdcaa3d Mon Sep 17 00:00:00 2001 From: peter-em Date: Tue, 29 Sep 2026 15:43:58 +0200 Subject: [PATCH 3/3] Sync missing sample for typescript --- .../date-library-date/src/models/Holidays.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/src/models/Holidays.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/src/models/Holidays.ts index cbd3b5cd29ab..f1f6cbafd67f 100644 --- a/samples/client/petstore/typescript-fetch/builds/date-library-date/src/models/Holidays.ts +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/src/models/Holidays.ts @@ -29,13 +29,13 @@ export function HolidaysFromJSONTyped(json: any, ignoreDiscriminator: boolean): return json; } if (Array.isArray(json)) { - if (json.every(item => !(isNaN(parseDate(item).getTime())))) { - return json.map(value => parseDate(value)); + if (json.every(item => typeof item === 'number')) { + return json; } } if (Array.isArray(json)) { - if (json.every(item => typeof item === 'number')) { - return json; + if (json.every(item => !(isNaN(parseDate(item).getTime())))) { + return json.map(value => parseDate(value)); } } return {} as any; @@ -50,13 +50,13 @@ export function HolidaysToJSONTyped(value?: Holidays | null, ignoreDiscriminator return value; } if (Array.isArray(value)) { - if (value.every(item => item instanceof Date)) { - return value.map(value => serializeDate(value)); + if (value.every(item => typeof item === 'number')) { + return value; } } if (Array.isArray(value)) { - if (value.every(item => typeof item === 'number')) { - return value; + if (value.every(item => item instanceof Date)) { + return value.map(value => serializeDate(value)); } } return {};