Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,9 @@ protected Schema processNormalize31Spec(Schema schema, Set<Schema> 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())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<File> 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<string>");

// Verify the deprecated array property 'oldTags' (array of $ref objects) is present with correct type
TestUtils.assertFileContains(file, "'oldTags'?: Array<Tag>");

// Verify the non-deprecated array property 'nicknames' is also present
TestUtils.assertFileContains(file, "'nicknames'?: Array<string>");
}
}
Original file line number Diff line number Diff line change
@@ -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
Loading