add override to java native pojo (#15125)

This commit is contained in:
William Cheng 2023-04-06 15:00:14 +08:00 committed by GitHub
parent 07227d4650
commit ba2c42e34b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 118 additions and 1 deletions

View File

@ -267,6 +267,23 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{/vars}}
{{>libraries/native/additional_properties}}
{{#parent}}
{{#allVars}}
{{#isOverridden}}
@Override
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
{{#vendorExtensions.x-is-jackson-optional-nullable}}
this.{{setter}}(JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}));
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
this.{{setter}}({{name}});
{{/vendorExtensions.x-is-jackson-optional-nullable}}
return this;
}
{{/isOverridden}}
{{/allVars}}
{{/parent}}
/**
* Return true if this {{name}} object is equal to o.
*/

View File

@ -1954,4 +1954,32 @@ public class JavaClientCodegenTest {
" public Pet petType(String petType) {\n");
}
}
@Test
public void testForJavaNativeClientOverrideSetter() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/3_0/allOf_composition_discriminator.yaml", null, new ParseOptions()).getOpenAPI();
JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setOutputDir(output.getAbsolutePath());
ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
codegen.setLibrary(JavaClientCodegen.NATIVE);
generator.opts(input).generate();
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/client/model/Cat.java"), " @Override\n" +
" public Cat petType(String petType) {");
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/client/model/Pet.java"), " }\n" +
"\n" +
" public Pet petType(String petType) {\n");
}
}

View File

@ -129,6 +129,18 @@ public class DataQuery extends Query {
}
@Override
public DataQuery id(Long id) {
this.setId(id);
return this;
}
@Override
public DataQuery outcomes(List<OutcomesEnum> outcomes) {
this.setOutcomes(outcomes);
return this;
}
/**
* Return true if this DataQuery object is equal to o.
*/

View File

@ -78,6 +78,18 @@ public class Cat extends Animal {
}
@Override
public Cat className(String className) {
this.setClassName(className);
return this;
}
@Override
public Cat color(String color) {
this.setColor(color);
return this;
}
/**
* Return true if this Cat object is equal to o.
*/

View File

@ -78,6 +78,18 @@ public class Dog extends Animal {
}
@Override
public Dog className(String className) {
this.setClassName(className);
return this;
}
@Override
public Dog color(String color) {
this.setColor(color);
return this;
}
/**
* Return true if this Dog object is equal to o.
*/

View File

@ -52,6 +52,12 @@ public class ParentPet extends GrandparentAnimal {
public ParentPet() {
}
@Override
public ParentPet petType(String petType) {
this.setPetType(petType);
return this;
}
/**
* Return true if this ParentPet object is equal to o.
*/

View File

@ -78,6 +78,18 @@ public class Cat extends Animal {
}
@Override
public Cat className(String className) {
this.setClassName(className);
return this;
}
@Override
public Cat color(String color) {
this.setColor(color);
return this;
}
/**
* Return true if this Cat object is equal to o.
*/

View File

@ -78,6 +78,18 @@ public class Dog extends Animal {
}
@Override
public Dog className(String className) {
this.setClassName(className);
return this;
}
@Override
public Dog color(String color) {
this.setColor(color);
return this;
}
/**
* Return true if this Dog object is equal to o.
*/

View File

@ -52,6 +52,12 @@ public class ParentPet extends GrandparentAnimal {
public ParentPet() {
}
@Override
public ParentPet petType(String petType) {
this.setPetType(petType);
return this;
}
/**
* Return true if this ParentPet object is equal to o.
*/