Skip to content

Commit

Permalink
Upgrade swagger-api to 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Apr 5, 2020
1 parent 43d943f commit aa368c4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
<swagger-api.version>2.1.1</swagger-api.version>
<swagger-api.version>2.1.2</swagger-api.version>
<swagger-ui.version>3.25.0</swagger-ui.version>
<spring-security-oauth2.version>2.3.8.RELEASE</spring-security-oauth2.version>
<classgraph.version>4.8.44</classgraph.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import io.swagger.v3.core.util.AnnotationsUtils;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -148,7 +150,15 @@ private static MediaType getMediaType(Schema schema, Components components, Json
MediaType mediaType = new MediaType();
if (!annotationContent.schema().hidden()) {
if (components != null) {
getSchema(annotationContent, components, jsonViewAnnotation).ifPresent(mediaType::setSchema);
try {
getSchema(annotationContent, components, jsonViewAnnotation).ifPresent(mediaType::setSchema);
}
catch (Exception e) {
if (isArray(annotationContent))
mediaType.setSchema(new ArraySchema().items(new StringSchema()));
else
mediaType.setSchema(new StringSchema());
}
}
else {
mediaType.setSchema(schema);
Expand All @@ -157,4 +167,16 @@ private static MediaType getMediaType(Schema schema, Components components, Json
return mediaType;
}

private static boolean isArray(io.swagger.v3.oas.annotations.media.Content annotationContent){
Class<?> schemaImplementation = annotationContent.schema().implementation();
boolean isArray = false;
if (schemaImplementation == Void.class) {
schemaImplementation = annotationContent.array().schema().implementation();
if (schemaImplementation != Void.class) {
isArray = true;
}
}
return isArray;
}

}
28 changes: 15 additions & 13 deletions springdoc-openapi-webmvc-core/src/test/resources/results/app41.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"paths": {
"/file": {
"get": {
"tags": [
"hello-controller"
],
"description": "Download file",
"operationId": "getFile",
"parameters": [
Expand All @@ -27,33 +30,33 @@
}
],
"responses": {
"200": {
"description": "File resource",
"500": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"type": "string",
"format": "binary"
"type": "string"
}
}
}
},
"400": {
"description": "Wrong request",
"200": {
"description": "File resource",
"content": {
"application/json": {
"schema": {
"type": "error"
"type": "string",
"format": "binary"
}
}
}
},
"500": {
"description": "Unexpected error",
"400": {
"description": "Wrong request",
"content": {
"application/json": {
"schema": {
"type": "error"
"type": "string"
}
}
}
Expand All @@ -62,6 +65,5 @@
}
}
},
"components": {
}
}
"components": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"type": "string"
},
{
"type": "integer"
"type": "integer",
"format": "int32"
}
]
},
Expand Down

0 comments on commit aa368c4

Please sign in to comment.