Skip to content

Commit

Permalink
[JAVA] Jersey3 deprecated field only deprecates getter method (OpenAP…
Browse files Browse the repository at this point in the history
…ITools#17221)

* Deprecate build and setter methods

* Generate samples
  • Loading branch information
gcatanese authored Nov 29, 2023
1 parent 9184560 commit fd58539
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}})) {
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,47 @@ public void testDeprecatedProperty() throws Exception {
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"}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void setUuid(String uuid) {
}


@Deprecated
public ObjectWithDeprecatedFields id(BigDecimal id) {
this.id = id;
return this;
Expand All @@ -101,13 +102,15 @@ public BigDecimal getId() {
}


@Deprecated
@JsonProperty(JSON_PROPERTY_ID)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setId(BigDecimal id) {
this.id = id;
}


@Deprecated
public ObjectWithDeprecatedFields deprecatedRef(DeprecatedObject deprecatedRef) {
this.deprecatedRef = deprecatedRef;
return this;
Expand All @@ -128,13 +131,15 @@ public DeprecatedObject getDeprecatedRef() {
}


@Deprecated
@JsonProperty(JSON_PROPERTY_DEPRECATED_REF)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setDeprecatedRef(DeprecatedObject deprecatedRef) {
this.deprecatedRef = deprecatedRef;
}


@Deprecated
public ObjectWithDeprecatedFields bars(List<String> bars) {
this.bars = bars;
return this;
Expand Down Expand Up @@ -163,6 +168,7 @@ public List<String> getBars() {
}


@Deprecated
@JsonProperty(JSON_PROPERTY_BARS)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setBars(List<String> bars) {
Expand Down

0 comments on commit fd58539

Please sign in to comment.