mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-30 12:40:52 +00:00
[JAVA] Jersey3 deprecated field only deprecates getter method (#17221)
* Deprecate build and setter methods * Generate samples
This commit is contained in:
parent
9184560597
commit
fd58539fe9
@ -116,6 +116,9 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
));
|
||||
|
||||
{{/vendorExtensions.x-enum-as-string}}
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
@ -256,6 +259,9 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
{{^isReadOnly}}
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
|
@ -2436,6 +2436,47 @@ public class JavaClientCodegenTest {
|
||||
output.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecatedPropertyJersey3() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.JERSEY3)
|
||||
.setInputSpec("src/test/resources/3_0/deprecated-properties.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(clientOptInput).generate();
|
||||
|
||||
validateJavaSourceFiles(files);
|
||||
|
||||
// deprecated builder method
|
||||
TestUtils.assertFileContains(
|
||||
Paths.get(output + "/src/main/java/org/openapitools/client/model/BigDog.java"),
|
||||
"@Deprecated\n" + " public BigDog declawed(Boolean declawed) {");
|
||||
|
||||
// deprecated getter
|
||||
TestUtils.assertFileContains(
|
||||
Paths.get(output + "/src/main/java/org/openapitools/client/model/BigDog.java"),
|
||||
"@Deprecated\n"
|
||||
+ " @jakarta.annotation.Nullable\n"
|
||||
+ " @JsonProperty(JSON_PROPERTY_DECLAWED)\n"
|
||||
+ " @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)\n"
|
||||
+ "\n"
|
||||
+ " public Boolean getDeclawed() {");
|
||||
// deprecated setter
|
||||
TestUtils.assertFileContains(
|
||||
Paths.get(output + "/src/main/java/org/openapitools/client/model/BigDog.java"),
|
||||
"@Deprecated\n"
|
||||
+ " @JsonProperty(JSON_PROPERTY_DECLAWED)\n"
|
||||
+ " @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)\n"
|
||||
+ " public void setDeclawed(Boolean declawed) {");
|
||||
|
||||
output.deleteOnExit();
|
||||
}
|
||||
|
||||
@DataProvider(name = "shouldNotAddAdditionalModelAnnotationsToAbstractOpenApiSchema_issue15684")
|
||||
public static Object[][] shouldNotAddAdditionalModelAnnotationsToAbstractOpenApiSchema_issue15684_dataProvider() {
|
||||
return new Object[][]{{"okhttp-gson"}, {"jersey2"}, {"jersey3"}, {"native"}};
|
||||
|
@ -81,6 +81,7 @@ public class ObjectWithDeprecatedFields {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public ObjectWithDeprecatedFields id(BigDecimal id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
@ -101,6 +102,7 @@ public class ObjectWithDeprecatedFields {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
@JsonProperty(JSON_PROPERTY_ID)
|
||||
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
|
||||
public void setId(BigDecimal id) {
|
||||
@ -108,6 +110,7 @@ public class ObjectWithDeprecatedFields {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public ObjectWithDeprecatedFields deprecatedRef(DeprecatedObject deprecatedRef) {
|
||||
this.deprecatedRef = deprecatedRef;
|
||||
return this;
|
||||
@ -128,6 +131,7 @@ public class ObjectWithDeprecatedFields {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
@JsonProperty(JSON_PROPERTY_DEPRECATED_REF)
|
||||
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
|
||||
public void setDeprecatedRef(DeprecatedObject deprecatedRef) {
|
||||
@ -135,6 +139,7 @@ public class ObjectWithDeprecatedFields {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public ObjectWithDeprecatedFields bars(List<String> bars) {
|
||||
this.bars = bars;
|
||||
return this;
|
||||
@ -163,6 +168,7 @@ public class ObjectWithDeprecatedFields {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
@JsonProperty(JSON_PROPERTY_BARS)
|
||||
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
|
||||
public void setBars(List<String> bars) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user