Skip to content

Commit

Permalink
[Typescript-Node] Mark deprecated model attributes (#19756)
Browse files Browse the repository at this point in the history
* Add @deprecated tag for deprecated fields

* Add tests

* Generate samples from OpenAPI 3.0 file

* Revert to generate with previous OpenAPI 2.0 file

* Add new config 3.0 and generate samples

* Regenerate samples
  • Loading branch information
gcatanese authored Oct 2, 2024
1 parent 90bc100 commit 168a1d5
Show file tree
Hide file tree
Showing 25 changed files with 2,606 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/configs/typescript-node-3.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
generatorName: typescript-node
outputDir: samples/client/petstore/typescript-node/3_0
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-node/SampleProject.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-node
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
{{#description}}
/**
* {{{.}}}
{{#deprecated}}
*
* @deprecated
{{/deprecated}}
*/
{{/description}}
{{^description}}
{{#deprecated}}
/**
* @deprecated
*/
{{/deprecated}}
{{/description}}
'{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}{{#defaultValue}} = {{#isEnum}}{{classname}}.{{/isEnum}}{{{.}}}{{/defaultValue}};
{{/vars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.TestUtils;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
Expand All @@ -16,6 +19,10 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

@Test(groups = {TypeScriptGroups.TYPESCRIPT, TypeScriptGroups.TYPESCRIPT_NODE})
Expand Down Expand Up @@ -227,6 +234,68 @@ public void postProcessOperationsWithModelsTestWithModelNamePrefix() {
Assert.assertEquals(tsImports.get(0).get("filename"), "./prefixChild");
}

@Test
public void testApisGeneration() throws IOException {

File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("typescript-node")
.setInputSpec("src/test/resources/3_0/typescript-node/SampleProject.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(clientOptInput).generate();
files.forEach(File::deleteOnExit);

TestUtils.assertFileContains(Paths.get(output + "/api/basicApi.ts"),
"* Sample project");
TestUtils.assertFileContains(Paths.get(output + "/api/basicApi.ts"),
"export class BasicApi {");
}

@Test
public void testModelsGeneration() throws IOException {

File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("typescript-node")
.setInputSpec("src/test/resources/3_0/typescript-node/SampleProject.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(clientOptInput).generate();
files.forEach(File::deleteOnExit);

TestUtils.assertFileContains(Paths.get(output + "/model/group.ts"),
"export class Group {");
}

@Test
public void testDeprecatedAttribute() throws IOException {

File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("typescript-node")
.setInputSpec("src/test/resources/3_0/typescript-node/SampleProject.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(clientOptInput).generate();
files.forEach(File::deleteOnExit);

TestUtils.assertFileContains(Paths.get(output + "/model/group.ts"),
"* @deprecated");
}

private OperationsMap createPostProcessOperationsMapWithImportName(String importName) {
OperationMap operations = new OperationMap();
operations.setClassname("Pet");
Expand Down
Loading

0 comments on commit 168a1d5

Please sign in to comment.