From 1aec291e750f2186be81c4a721a71a2453f581e1 Mon Sep 17 00:00:00 2001 From: Philippe Laflamme Date: Fri, 20 Feb 2026 17:19:57 -0500 Subject: [PATCH 1/2] test: add failing test for missing @deprecated on array properties in OAS 3.1 The typescript-axios generator drops the @deprecated JSDoc annotation for array-type properties when processing OpenAPI 3.1 specs. This test reproduces the issue by asserting that deprecated scalar, array-of-primitives, and array-of-refs properties all receive the annotation. --- .../TypeScriptAxiosClientCodegenTest.java | 48 ++++++++ .../deprecated-array-attribute.yaml | 104 ++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_1/typescript-axios/deprecated-array-attribute.yaml diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java index 185366b9b0d3..1713e2ca4a4d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java @@ -1,11 +1,21 @@ package org.openapitools.codegen.typescript.axios; +import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.DefaultGenerator; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen; import org.openapitools.codegen.typescript.TypeScriptGroups; import org.testng.annotations.Test; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; import static org.testng.Assert.assertEquals; @@ -130,4 +140,42 @@ public void testAppliesCustomAxiosVersion() { assertEquals(codegen.additionalProperties().get("axiosVersion"), "^1.2.3"); } + + @Test(description = "Verify @deprecated annotation is generated for array-type properties") + public void testDeprecatedArrayAttribute() throws Exception { + final File output = Files.createTempDirectory("typescript_axios_deprecated_array_").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("typescript-axios") + .setInputSpec("src/test/resources/3_1/typescript-axios/deprecated-array-attribute.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + final DefaultGenerator generator = new DefaultGenerator(); + final List files = generator.opts(clientOptInput).generate(); + files.forEach(File::deleteOnExit); + + Path file = Paths.get(output + "/api.ts"); + String content = Files.readString(file); + + // The model has three deprecated properties: + // 'age' (integer), 'tags' (array of strings), 'oldTags' (array of $ref Tag objects) + // and one non-deprecated array property: 'nicknames' + // There should be exactly 3 occurrences of @deprecated in the model file + assertEquals(TestUtils.countOccurrences(content, "@deprecated"), 3, + "Expected @deprecated on 'age' (scalar), 'tags' (array of strings), and 'oldTags' (array of $ref objects)"); + + // Verify the @deprecated annotation appears in the generated output + TestUtils.assertFileContains(file, "* @deprecated"); + + // Verify the deprecated array property 'tags' (array of primitives) is present with correct type + TestUtils.assertFileContains(file, "'tags'?: Array"); + + // Verify the deprecated array property 'oldTags' (array of $ref objects) is present with correct type + TestUtils.assertFileContains(file, "'oldTags'?: Array"); + + // Verify the non-deprecated array property 'nicknames' is also present + TestUtils.assertFileContains(file, "'nicknames'?: Array"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_1/typescript-axios/deprecated-array-attribute.yaml b/modules/openapi-generator/src/test/resources/3_1/typescript-axios/deprecated-array-attribute.yaml new file mode 100644 index 000000000000..06131b6eb0b8 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/typescript-axios/deprecated-array-attribute.yaml @@ -0,0 +1,104 @@ +openapi: 3.1.0 +info: + description: Test deprecated annotation on array-type properties + version: 1.0.0 + title: Test deprecated array attribute + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' + +paths: + /pets: + get: + tags: + - default + summary: Finds Pets + operationId: findPets + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + + patch: + tags: + - default + summary: Update a Pet + operationId: updatePet + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PetUpdateRequest' + responses: + '200': + description: Pet updated successfully + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + +components: + schemas: + Tag: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + + PetUpdateRequest: + type: object + description: Payload for updating a pet + properties: + name: + type: string + description: New name for the pet + age: + type: integer + format: int32 + description: Updated age + deprecated: true + tags: + type: array + description: List of tags + deprecated: true + items: + type: string + oldTags: + type: array + description: List of old tag objects + deprecated: true + items: + $ref: '#/components/schemas/Tag' + nicknames: + type: array + description: List of nicknames (not deprecated) + items: + type: string + required: + - name + + Pet: + type: object + description: Pet object + properties: + id: + type: integer + format: int64 + name: + type: string + age: + type: integer + format: int32 + tags: + type: array + items: + type: string From d1c3c9eedfc35a5a740bc690e84016e7e473e33f Mon Sep 17 00:00:00 2001 From: Philippe Laflamme Date: Fri, 20 Feb 2026 17:26:15 -0500 Subject: [PATCH 2/2] fix: preserve deprecated, readOnly, writeOnly when normalizing OAS 3.1 array schemas The OpenAPINormalizer.processNormalize31Spec method converts OAS 3.1 JsonSchema array types into legacy ArraySchema objects, but was not copying the deprecated, readOnly, or writeOnly flags during conversion. This caused @deprecated annotations to be silently dropped for array-type properties in all generators when processing OAS 3.1 specs. --- .../main/java/org/openapitools/codegen/OpenAPINormalizer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java index ed279831c7ef..65ac8af06506 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java @@ -1839,6 +1839,9 @@ protected Schema processNormalize31Spec(Schema schema, Set visitedSchema as.setXml(schema.getXml()); as.setNullable(schema.getNullable()); as.setUniqueItems(schema.getUniqueItems()); + as.setDeprecated(schema.getDeprecated()); + as.setReadOnly(schema.getReadOnly()); + as.setWriteOnly(schema.getWriteOnly()); if (schema.getItems() != null) { // `items` is also a json schema if (StringUtils.isNotEmpty(schema.getItems().get$ref())) {