Skip to content

Commit aa368c4

Browse files
author
bnasslahsen
committed
Upgrade swagger-api to 2.1.1
1 parent 43d943f commit aa368c4

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
7272
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
7373
<nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
74-
<swagger-api.version>2.1.1</swagger-api.version>
74+
<swagger-api.version>2.1.2</swagger-api.version>
7575
<swagger-ui.version>3.25.0</swagger-ui.version>
7676
<spring-security-oauth2.version>2.3.8.RELEASE</spring-security-oauth2.version>
7777
<classgraph.version>4.8.44</classgraph.version>

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocAnnotationsUtils.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import io.swagger.v3.core.util.AnnotationsUtils;
3232
import io.swagger.v3.oas.annotations.media.ExampleObject;
3333
import io.swagger.v3.oas.models.Components;
34+
import io.swagger.v3.oas.models.media.ArraySchema;
3435
import io.swagger.v3.oas.models.media.Content;
3536
import io.swagger.v3.oas.models.media.MediaType;
3637
import io.swagger.v3.oas.models.media.Schema;
38+
import io.swagger.v3.oas.models.media.StringSchema;
3739
import org.apache.commons.lang3.ArrayUtils;
3840
import org.apache.commons.lang3.StringUtils;
3941

@@ -148,7 +150,15 @@ private static MediaType getMediaType(Schema schema, Components components, Json
148150
MediaType mediaType = new MediaType();
149151
if (!annotationContent.schema().hidden()) {
150152
if (components != null) {
151-
getSchema(annotationContent, components, jsonViewAnnotation).ifPresent(mediaType::setSchema);
153+
try {
154+
getSchema(annotationContent, components, jsonViewAnnotation).ifPresent(mediaType::setSchema);
155+
}
156+
catch (Exception e) {
157+
if (isArray(annotationContent))
158+
mediaType.setSchema(new ArraySchema().items(new StringSchema()));
159+
else
160+
mediaType.setSchema(new StringSchema());
161+
}
152162
}
153163
else {
154164
mediaType.setSchema(schema);
@@ -157,4 +167,16 @@ private static MediaType getMediaType(Schema schema, Components components, Json
157167
return mediaType;
158168
}
159169

170+
private static boolean isArray(io.swagger.v3.oas.annotations.media.Content annotationContent){
171+
Class<?> schemaImplementation = annotationContent.schema().implementation();
172+
boolean isArray = false;
173+
if (schemaImplementation == Void.class) {
174+
schemaImplementation = annotationContent.array().schema().implementation();
175+
if (schemaImplementation != Void.class) {
176+
isArray = true;
177+
}
178+
}
179+
return isArray;
180+
}
181+
160182
}

springdoc-openapi-webmvc-core/src/test/resources/results/app41.json

+15-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"paths": {
1414
"/file": {
1515
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
1619
"description": "Download file",
1720
"operationId": "getFile",
1821
"parameters": [
@@ -27,33 +30,33 @@
2730
}
2831
],
2932
"responses": {
30-
"200": {
31-
"description": "File resource",
33+
"500": {
34+
"description": "Unexpected error",
3235
"content": {
3336
"application/json": {
3437
"schema": {
35-
"type": "string",
36-
"format": "binary"
38+
"type": "string"
3739
}
3840
}
3941
}
4042
},
41-
"400": {
42-
"description": "Wrong request",
43+
"200": {
44+
"description": "File resource",
4345
"content": {
4446
"application/json": {
4547
"schema": {
46-
"type": "error"
48+
"type": "string",
49+
"format": "binary"
4750
}
4851
}
4952
}
5053
},
51-
"500": {
52-
"description": "Unexpected error",
54+
"400": {
55+
"description": "Wrong request",
5356
"content": {
5457
"application/json": {
5558
"schema": {
56-
"type": "error"
59+
"type": "string"
5760
}
5861
}
5962
}
@@ -62,6 +65,5 @@
6265
}
6366
}
6467
},
65-
"components": {
66-
}
67-
}
68+
"components": {}
69+
}

springdoc-openapi-webmvc-core/src/test/resources/results/app6.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"type": "string"
3030
},
3131
{
32-
"type": "integer"
32+
"type": "integer",
33+
"format": "int32"
3334
}
3435
]
3536
},

0 commit comments

Comments
 (0)