Skip to content

Commit 7e827c9

Browse files
joseegarciaclaude
andcommitted
Support schema deprecated on generated models; bump 6.5.3
OpenAPI 3.x / JSON Schema `deprecated: true` on a property (or enum) is now carried into the generated model as @Schema(deprecated = true); previously it was ignored. Applied at the same property/enum metadata points as description/example. Bumps version 6.5.2 -> 6.5.3. Full multiapi-engine suite: 110/110 (mvn clean test). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 447764e commit 7e827c9

9 files changed

Lines changed: 43 additions & 11 deletions

File tree

multiapi-engine/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.sngular</groupId>
66
<artifactId>multiapi-engine</artifactId>
7-
<version>6.5.2</version>
7+
<version>6.5.3</version>
88
<packaging>jar</packaging>
99

1010
<properties>

multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public class SchemaFieldObject {
3232
private String description;
3333

3434
private String example;
35+
36+
private boolean deprecated;
3537
}

multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ public static String getDescription(final JsonNode schema) {
484484
return getNodeAsString(schema, "description");
485485
}
486486

487+
public static boolean isDeprecated(final JsonNode schema) {
488+
return getNodeAsBoolean(schema, "deprecated");
489+
}
490+
487491
public static String getExample(final JsonNode schema) {
488492
// OpenAPI 3.0 uses a single `example`; OpenAPI 3.1 / JSON Schema 2020-12 use an
489493
// `examples` array. Prefer `example`, otherwise take the first `examples` entry.

multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ private static List<SchemaFieldObject> processObjectProperty(
346346
private static void applyMetadata(final List<SchemaFieldObject> fields, final String fieldName, final JsonNode fieldBody) {
347347
final String description = ApiTool.getDescription(fieldBody);
348348
final String example = ApiTool.getExample(fieldBody);
349-
if (Objects.isNull(description) && Objects.isNull(example)) {
349+
final boolean deprecated = ApiTool.isDeprecated(fieldBody);
350+
if (Objects.isNull(description) && Objects.isNull(example) && !deprecated) {
350351
return;
351352
}
352353
for (final var field : fields) {
@@ -357,6 +358,9 @@ private static void applyMetadata(final List<SchemaFieldObject> fields, final St
357358
if (Objects.nonNull(example)) {
358359
field.setExample(example);
359360
}
361+
if (deprecated) {
362+
field.setDeprecated(true);
363+
}
360364
}
361365
}
362366
}
@@ -873,9 +877,10 @@ private static SchemaFieldObject processEnumField(
873877
}
874878
field.setEnumValues(enumValuesMap);
875879
// Enum fields bypass processObjectProperty's applyMetadata, so carry the schema's
876-
// description/example here too for consistent @Schema annotations.
880+
// description/example/deprecated here too for consistent @Schema annotations.
877881
field.setDescription(ApiTool.getDescription(value));
878882
field.setExample(ApiTool.getExample(value));
883+
field.setDeprecated(ApiTool.isDeprecated(value));
879884
return field;
880885
}
881886

multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public class ${schema.className} {
340340
}
341341

342342
<#list schema.fieldObjectList as field>
343-
@Schema(name = "${field.baseName?uncap_first}", required = <#if field.required?has_content && field.required == true>true<#else>false</#if><#if field.description?has_content>, description = "${field.description?j_string}"</#if><#if field.example?has_content>, example = "${field.example?j_string}"</#if>)
343+
@Schema(name = "${field.baseName?uncap_first}", required = <#if field.required?has_content && field.required == true>true<#else>false</#if><#if field.description?has_content>, description = "${field.description?j_string}"</#if><#if field.example?has_content>, example = "${field.example?j_string}"</#if><#if field.deprecated>, deprecated = true</#if>)
344344
<#if field.dataType.baseType == "array">
345345
public ${field.dataType} get${field.baseName?cap_first}() {
346346
return ${calculateSafeName (field.baseName, ";")}

multiapi-engine/src/test/resources/openapigenerator/testOpenApi31Completeness/api-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ components:
4242
description: The unique gadget identifier
4343
examples:
4444
- "gadget-001"
45+
legacyId:
46+
type: string
47+
deprecated: true
4548
serial:
4649
type: ["string", "null"]
4750
example: "SN-12345"

multiapi-engine/src/test/resources/openapigenerator/testOpenApi31Completeness/assets/GadgetDTO.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public String toString() {
3939
return String.valueOf(value);
4040
}
4141
}
42+
@JsonProperty(value ="legacyId")
43+
private String legacyId;
4244
@JsonProperty(value ="payload")
4345
private MultipartFile payload;
4446
@JsonProperty(value ="nothing")
@@ -56,6 +58,7 @@ public String toString() {
5658

5759
private GadgetDTO(GadgetDTOBuilder builder) {
5860
this.status = builder.status;
61+
this.legacyId = builder.legacyId;
5962
this.payload = builder.payload;
6063
this.nothing = builder.nothing;
6164
this.id = builder.id;
@@ -74,6 +77,7 @@ public static GadgetDTO.GadgetDTOBuilder builder() {
7477
public static class GadgetDTOBuilder {
7578

7679
private Status status;
80+
private String legacyId;
7781
private MultipartFile payload;
7882
private Object nothing;
7983
private String id;
@@ -87,6 +91,11 @@ public GadgetDTO.GadgetDTOBuilder status(Status status) {
8791
return this;
8892
}
8993

94+
public GadgetDTO.GadgetDTOBuilder legacyId(String legacyId) {
95+
this.legacyId = legacyId;
96+
return this;
97+
}
98+
9099
public GadgetDTO.GadgetDTOBuilder payload(MultipartFile payload) {
91100
this.payload = payload;
92101
return this;
@@ -150,6 +159,14 @@ public void setStatus(Status status) {
150159
this.status = status;
151160
}
152161

162+
@Schema(name = "legacyId", required = false, deprecated = true)
163+
public String getLegacyId() {
164+
return legacyId;
165+
}
166+
public void setLegacyId(String legacyId) {
167+
this.legacyId = legacyId;
168+
}
169+
153170
@Schema(name = "payload", required = false)
154171
public MultipartFile getPayload() {
155172
return payload;
@@ -215,19 +232,20 @@ public boolean equals(Object o) {
215232
return false;
216233
}
217234
GadgetDTO gadgetDTO = (GadgetDTO) o;
218-
return Objects.equals(this.status, gadgetDTO.status) && Objects.equals(this.payload, gadgetDTO.payload) && Objects.equals(this.nothing, gadgetDTO.nothing) && Objects.equals(this.id, gadgetDTO.id) && Objects.equals(this.metadata, gadgetDTO.metadata) && Objects.equals(this.coords, gadgetDTO.coords) && Objects.equals(this.owner, gadgetDTO.owner) && Objects.equals(this.serial, gadgetDTO.serial);
235+
return Objects.equals(this.status, gadgetDTO.status) && Objects.equals(this.legacyId, gadgetDTO.legacyId) && Objects.equals(this.payload, gadgetDTO.payload) && Objects.equals(this.nothing, gadgetDTO.nothing) && Objects.equals(this.id, gadgetDTO.id) && Objects.equals(this.metadata, gadgetDTO.metadata) && Objects.equals(this.coords, gadgetDTO.coords) && Objects.equals(this.owner, gadgetDTO.owner) && Objects.equals(this.serial, gadgetDTO.serial);
219236
}
220237

221238
@Override
222239
public int hashCode() {
223-
return Objects.hash(status, payload, nothing, id, metadata, coords, owner, serial);
240+
return Objects.hash(status, legacyId, payload, nothing, id, metadata, coords, owner, serial);
224241
}
225242

226243
@Override
227244
public String toString() {
228245
StringBuilder sb = new StringBuilder();
229246
sb.append("GadgetDTO{");
230247
sb.append(" status:").append(status).append(",");
248+
sb.append(" legacyId:").append(legacyId).append(",");
231249
sb.append(" payload:").append(payload).append(",");
232250
sb.append(" nothing:").append(nothing).append(",");
233251
sb.append(" id:").append(id).append(",");

scs-multiapi-gradle-plugin/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repositories {
2121
}
2222

2323
group = 'com.sngular'
24-
version = '6.5.2'
24+
version = '6.5.3'
2525

2626
def SCSMultiApiPluginGroupId = group
2727
def SCSMultiApiPluginVersion = version
@@ -31,7 +31,7 @@ dependencies {
3131
shadow localGroovy()
3232
shadow gradleApi()
3333

34-
implementation 'com.sngular:multiapi-engine:6.5.2'
34+
implementation 'com.sngular:multiapi-engine:6.5.3'
3535
testImplementation 'org.assertj:assertj-core:3.24.2'
3636
testImplementation 'com.puppycrawl.tools:checkstyle:10.12.3'
3737
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.2'
@@ -100,7 +100,7 @@ testing {
100100

101101
integrationTest(JvmTestSuite) {
102102
dependencies {
103-
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.5.2'
103+
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.5.3'
104104
implementation 'org.assertj:assertj-core:3.24.2'
105105
}
106106

scs-multiapi-maven-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.sngular</groupId>
66
<artifactId>scs-multiapi-maven-plugin</artifactId>
7-
<version>6.5.2</version>
7+
<version>6.5.3</version>
88
<packaging>maven-plugin</packaging>
99

1010
<name>AsyncApi - OpenApi Code Generator Maven Plugin</name>
@@ -271,7 +271,7 @@
271271
<dependency>
272272
<groupId>com.sngular</groupId>
273273
<artifactId>multiapi-engine</artifactId>
274-
<version>6.5.2</version>
274+
<version>6.5.3</version>
275275
</dependency>
276276
<dependency>
277277
<groupId>org.apache.maven</groupId>

0 commit comments

Comments
 (0)