Skip to content

Commit fe9ba65

Browse files
committed
fix arraySchema in SchemaProperty. fixes #2373
1 parent d4f99ac commit fe9ba65

File tree

4 files changed

+183
-1
lines changed

4 files changed

+183
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,13 @@ private static MediaType getMediaType(Schema schema, Components components, Json
365365
Schema oSchema = mediaType.getSchema();
366366
for (SchemaProperty sp : annotationContent.schemaProperties()) {
367367
Class<?> schemaImplementation = sp.schema().implementation();
368-
boolean isArray = isArray(annotationContent);
368+
boolean isArray = false;
369+
if (schemaImplementation == Void.class) {
370+
schemaImplementation = sp.array().schema().implementation();
371+
if (schemaImplementation != Void.class) {
372+
isArray = true;
373+
}
374+
}
369375
getSchema(sp.schema(), sp.array(), isArray, schemaImplementation, components, jsonViewAnnotation, openapi31)
370376
.ifPresent(s -> {
371377
if ("array".equals(oSchema.getType())) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2023 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app211;
26+
27+
import io.swagger.v3.oas.annotations.media.ArraySchema;
28+
import io.swagger.v3.oas.annotations.media.Content;
29+
import io.swagger.v3.oas.annotations.media.Schema;
30+
import io.swagger.v3.oas.annotations.media.SchemaProperty;
31+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
32+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
33+
34+
import org.springframework.http.MediaType;
35+
import org.springframework.web.bind.annotation.GetMapping;
36+
import org.springframework.web.bind.annotation.RestController;
37+
38+
@RestController
39+
public class HelloController {
40+
@ApiResponses(value = @ApiResponse(
41+
responseCode = "200",
42+
content = {
43+
@Content(
44+
mediaType = MediaType.APPLICATION_JSON_VALUE,
45+
schemaProperties = {
46+
@SchemaProperty(
47+
name = "items",
48+
array = @ArraySchema(schema = @Schema(implementation = PagedObject.class))),
49+
@SchemaProperty(name = "paging", schema = @Schema(implementation = Paging.class))
50+
}
51+
)
52+
}
53+
))
54+
@GetMapping
55+
public String index() {
56+
return null;
57+
}
58+
59+
record PagedObject(long id, String name) {}
60+
record Paging(int page, int total, int lastPage) {}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2023 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app211;
26+
27+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
28+
29+
import org.springframework.boot.autoconfigure.SpringBootApplication;
30+
31+
public class SpringDocApp211Test extends AbstractSpringDocV30Test {
32+
33+
@SpringBootApplication
34+
static class SpringDocTestApp {}
35+
36+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "index_1",
20+
"responses": {
21+
"200": {
22+
"description": "OK",
23+
"content": {
24+
"application/json": {
25+
"schema": {
26+
"type": "object",
27+
"properties": {
28+
"items": {
29+
"type": "array",
30+
"items": {
31+
"$ref": "#/components/schemas/PagedObject"
32+
}
33+
},
34+
"paging": {
35+
"$ref": "#/components/schemas/Paging"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
},
46+
"components": {
47+
"schemas": {
48+
"PagedObject": {
49+
"type": "object",
50+
"properties": {
51+
"id": {
52+
"type": "integer",
53+
"format": "int64"
54+
},
55+
"name": {
56+
"type": "string"
57+
}
58+
}
59+
},
60+
"Paging": {
61+
"type": "object",
62+
"properties": {
63+
"page": {
64+
"type": "integer",
65+
"format": "int32"
66+
},
67+
"total": {
68+
"type": "integer",
69+
"format": "int32"
70+
},
71+
"lastPage": {
72+
"type": "integer",
73+
"format": "int32"
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)