Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/gradle-portal-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: "17"
java-version: "21"
distribution: "adopt"
server-id: ossrh
server-username: MAVEN_USERNAME
Expand Down
2 changes: 1 addition & 1 deletion multiapi-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>6.5.1</version>
<version>6.5.3</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public class SchemaFieldObject {
private String description;

private String example;

private boolean deprecated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ public static String getDescription(final JsonNode schema) {
return getNodeAsString(schema, "description");
}

public static boolean isDeprecated(final JsonNode schema) {
return getNodeAsBoolean(schema, "deprecated");
}

public static String getExample(final JsonNode schema) {
// OpenAPI 3.0 uses a single `example`; OpenAPI 3.1 / JSON Schema 2020-12 use an
// `examples` array. Prefer `example`, otherwise take the first `examples` entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ private static List<SchemaFieldObject> processObjectProperty(
private static void applyMetadata(final List<SchemaFieldObject> fields, final String fieldName, final JsonNode fieldBody) {
final String description = ApiTool.getDescription(fieldBody);
final String example = ApiTool.getExample(fieldBody);
if (Objects.isNull(description) && Objects.isNull(example)) {
final boolean deprecated = ApiTool.isDeprecated(fieldBody);
if (Objects.isNull(description) && Objects.isNull(example) && !deprecated) {
return;
}
for (final var field : fields) {
Expand All @@ -357,6 +358,9 @@ private static void applyMetadata(final List<SchemaFieldObject> fields, final St
if (Objects.nonNull(example)) {
field.setExample(example);
}
if (deprecated) {
field.setDeprecated(true);
}
}
}
}
Expand Down Expand Up @@ -872,6 +876,11 @@ private static SchemaFieldObject processEnumField(
throw new BadDefinedEnumException(name);
}
field.setEnumValues(enumValuesMap);
// Enum fields bypass processObjectProperty's applyMetadata, so carry the schema's
// description/example/deprecated here too for consistent @Schema annotations.
field.setDescription(ApiTool.getDescription(value));
field.setExample(ApiTool.getExample(value));
field.setDeprecated(ApiTool.isDeprecated(value));
return field;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public class ${schema.className} {
}

<#list schema.fieldObjectList as field>
@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>)
@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>)
<#if field.dataType.baseType == "array">
public ${field.dataType} get${field.baseName?cap_first}() {
return ${calculateSafeName (field.baseName, ";")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ components:
description: The unique gadget identifier
examples:
- "gadget-001"
legacyId:
type: string
deprecated: true
serial:
type: ["string", "null"]
example: "SN-12345"
Expand All @@ -58,6 +61,12 @@ components:
patternProperties:
"^x-":
type: string
status:
type: string
description: Lifecycle status of the gadget
enum:
- ACTIVE
- RETIRED
nothing:
type: "null"
owner:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
Expand All @@ -16,6 +17,30 @@
@JsonDeserialize(builder = GadgetDTO.GadgetDTOBuilder.class)
public class GadgetDTO {

@JsonProperty(value ="status")
private Status status;
public enum Status {
ACTIVE("ACTIVE"),
RETIRED("RETIRED");

private String value;

Status(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}
}
@JsonProperty(value ="legacyId")
private String legacyId;
@JsonProperty(value ="payload")
private MultipartFile payload;
@JsonProperty(value ="nothing")
Expand All @@ -32,6 +57,8 @@ public class GadgetDTO {
private String serial;

private GadgetDTO(GadgetDTOBuilder builder) {
this.status = builder.status;
this.legacyId = builder.legacyId;
this.payload = builder.payload;
this.nothing = builder.nothing;
this.id = builder.id;
Expand All @@ -49,6 +76,8 @@ public static GadgetDTO.GadgetDTOBuilder builder() {
@JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
public static class GadgetDTOBuilder {

private Status status;
private String legacyId;
private MultipartFile payload;
private Object nothing;
private String id;
Expand All @@ -57,6 +86,16 @@ public static class GadgetDTOBuilder {
private PersonDTO owner;
private String serial;

public GadgetDTO.GadgetDTOBuilder status(Status status) {
this.status = status;
return this;
}

public GadgetDTO.GadgetDTOBuilder legacyId(String legacyId) {
this.legacyId = legacyId;
return this;
}

public GadgetDTO.GadgetDTOBuilder payload(MultipartFile payload) {
this.payload = payload;
return this;
Expand Down Expand Up @@ -112,6 +151,22 @@ public GadgetDTO build() {
}
}

@Schema(name = "status", required = false, description = "Lifecycle status of the gadget")
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}

@Schema(name = "legacyId", required = false, deprecated = true)
public String getLegacyId() {
return legacyId;
}
public void setLegacyId(String legacyId) {
this.legacyId = legacyId;
}

@Schema(name = "payload", required = false)
public MultipartFile getPayload() {
return payload;
Expand Down Expand Up @@ -177,18 +232,20 @@ public boolean equals(Object o) {
return false;
}
GadgetDTO gadgetDTO = (GadgetDTO) o;
return 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);
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);
}

@Override
public int hashCode() {
return Objects.hash(payload, nothing, id, metadata, coords, owner, serial);
return Objects.hash(status, legacyId, payload, nothing, id, metadata, coords, owner, serial);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("GadgetDTO{");
sb.append(" status:").append(status).append(",");
sb.append(" legacyId:").append(legacyId).append(",");
sb.append(" payload:").append(payload).append(",");
sb.append(" nothing:").append(nothing).append(",");
sb.append(" id:").append(id).append(",");
Expand Down
6 changes: 3 additions & 3 deletions scs-multiapi-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repositories {
}

group = 'com.sngular'
version = '6.5.1'
version = '6.5.3'

def SCSMultiApiPluginGroupId = group
def SCSMultiApiPluginVersion = version
Expand All @@ -31,7 +31,7 @@ dependencies {
shadow localGroovy()
shadow gradleApi()

implementation 'com.sngular:multiapi-engine:6.5.1'
implementation 'com.sngular:multiapi-engine:6.5.3'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'com.puppycrawl.tools:checkstyle:10.12.3'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.2'
Expand Down Expand Up @@ -100,7 +100,7 @@ testing {

integrationTest(JvmTestSuite) {
dependencies {
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.5.1'
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.5.3'
implementation 'org.assertj:assertj-core:3.24.2'
}

Expand Down
4 changes: 2 additions & 2 deletions scs-multiapi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>6.5.1</version>
<version>6.5.3</version>
<packaging>maven-plugin</packaging>

<name>AsyncApi - OpenApi Code Generator Maven Plugin</name>
Expand Down Expand Up @@ -271,7 +271,7 @@
<dependency>
<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>6.5.1</version>
<version>6.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
Loading