Skip to content

Commit 4e07c6b

Browse files
committed
Improve array management when using @parameter
1 parent 7fe1a21 commit 4e07c6b

File tree

6 files changed

+191
-1
lines changed

6 files changed

+191
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private void setSchema(io.swagger.v3.oas.annotations.Parameter parameterDoc, Com
270270
LOGGER.warn(Constants.GRACEFUL_EXCEPTION_OCCURRED, e);
271271
}
272272
if (schema == null) {
273-
schema = AnnotationsUtils.getArraySchema(parameterDoc.array(), components, jsonView).orElse(null);
273+
schema =AnnotationsUtils.getSchema(parameterDoc.schema(), parameterDoc.array(), true, parameterDoc.array().schema().implementation(), components, jsonView).orElse(null);
274274
// default value not set by swagger-core for array !
275275
if (schema != null) {
276276
Object defaultValue = SpringDocAnnotationsUtils.resolveDefaultValue(parameterDoc.array().arraySchema().defaultValue());
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package test.org.springdoc.api.app156;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
import io.swagger.v3.oas.annotations.media.ArraySchema;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import static io.swagger.v3.oas.annotations.enums.ParameterIn.QUERY;
11+
12+
@RestController
13+
public class HelloController {
14+
@GetMapping("/hello")
15+
@Parameter(name = "someEnums", in = QUERY, description = "SomeEum decs",
16+
array = @ArraySchema(schema = @Schema(implementation = SomeEnum.class)))
17+
@Parameter(name = "textSet", in = QUERY, description = "First decs",
18+
array = @ArraySchema(schema = @Schema(implementation = String.class)))
19+
@Parameter(name = "someText", in = QUERY, description = "Second decs",
20+
schema = @Schema(type = "string"))
21+
public String hello(@Parameter(hidden = true) User user) {
22+
String forReturn = "Hello ";
23+
StringBuilder stringBuilder = new StringBuilder(forReturn);
24+
25+
if (user.getSomeEnums() != null) {
26+
for (SomeEnum some : user.getSomeEnums()) {
27+
stringBuilder.append(some);
28+
stringBuilder.append(" ");
29+
}
30+
}
31+
32+
if (user.getSomeText() != null) {
33+
for (String text : user.getTextSet()) {
34+
stringBuilder.append(text);
35+
stringBuilder.append(" ");
36+
}
37+
}
38+
39+
if (user.getSomeText() != null) {
40+
stringBuilder.append(user.getSomeText());
41+
}
42+
43+
return stringBuilder.toString();
44+
}
45+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package test.org.springdoc.api.app156;
2+
3+
public enum SomeEnum {
4+
FIRST,
5+
SECOND
6+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app156;
20+
21+
22+
import test.org.springdoc.api.AbstractSpringDocTest;
23+
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
26+
/**
27+
* Tests Spring meta-annotations as method parameters
28+
*/
29+
public class SpringDocApp156Test extends AbstractSpringDocTest {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package test.org.springdoc.api.app156;
2+
3+
import java.util.Set;
4+
5+
public class User {
6+
private String someText;
7+
private Set<String> textSet;
8+
private Set<SomeEnum> someEnums;
9+
10+
public String getSomeText() {
11+
return someText;
12+
}
13+
14+
public void setSomeText(String someText) {
15+
this.someText = someText;
16+
}
17+
18+
public Set<String> getTextSet() {
19+
return textSet;
20+
}
21+
22+
public void setTextSet(Set<String> textSet) {
23+
this.textSet = textSet;
24+
}
25+
26+
public Set<SomeEnum> getSomeEnums() {
27+
return someEnums;
28+
}
29+
30+
public void setSomeEnums(Set<SomeEnum> someEnums) {
31+
this.someEnums = someEnums;
32+
}
33+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
"/hello": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "hello",
20+
"parameters": [
21+
{
22+
"name": "someEnums",
23+
"in": "query",
24+
"description": "SomeEum decs",
25+
"schema": {
26+
"type": "array",
27+
"items": {
28+
"type": "string",
29+
"enum": [
30+
"FIRST",
31+
"SECOND"
32+
]
33+
}
34+
}
35+
},
36+
{
37+
"name": "textSet",
38+
"in": "query",
39+
"description": "First decs",
40+
"schema": {
41+
"type": "array",
42+
"items": {
43+
"type": "string"
44+
}
45+
}
46+
},
47+
{
48+
"name": "someText",
49+
"in": "query",
50+
"description": "Second decs",
51+
"schema": {
52+
"type": "string"
53+
}
54+
}
55+
],
56+
"responses": {
57+
"200": {
58+
"description": "OK",
59+
"content": {
60+
"*/*": {
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"components": {}
72+
}

0 commit comments

Comments
 (0)