Skip to content

Commit

Permalink
Duplicated header values when an endpoint can be called with differen…
Browse files Browse the repository at this point in the history
…t headers. Fixes #1801.
  • Loading branch information
bnasslahsen committed Aug 20, 2022
1 parent aaf92ab commit 78df2f5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
Expand Up @@ -334,7 +334,7 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
Entry<String, Parameter> entry = it.next();
Parameter parameter = entry.getValue();
if (!ParameterIn.PATH.toString().equals(parameter.getIn())) {
io.swagger.v3.oas.models.media.Schema<?> itemSchema = new io.swagger.v3.oas.models.media.Schema<>() ;
io.swagger.v3.oas.models.media.Schema<?> itemSchema = new io.swagger.v3.oas.models.media.Schema<>();
itemSchema.setName(entry.getKey());
itemSchema.setDescription(parameter.getDescription());
itemSchema.setDeprecated(parameter.getDeprecated());
Expand Down Expand Up @@ -398,7 +398,10 @@ public static Collection<Parameter> getHeaders(MethodAttributes methodAttributes
Parameter parameter = new Parameter().in(ParameterIn.HEADER.toString()).name(entry.getKey()).schema(schema);
if (map.containsKey(entry.getKey())) {
parameter = map.get(entry.getKey());
if (StringUtils.isNotEmpty(entry.getValue()))
List existingEnum = null;
if (parameter.getSchema() != null && !CollectionUtils.isEmpty(parameter.getSchema().getEnum()))
existingEnum = parameter.getSchema().getEnum();
if (StringUtils.isNotEmpty(entry.getValue()) && (existingEnum==null || !existingEnum.contains(entry.getValue())))
parameter.getSchema().addEnumItemObject(entry.getValue());
parameter.setSchema(parameter.getSchema());
}
Expand Down
@@ -0,0 +1,26 @@
package test.org.springdoc.api.v30.app47;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/")
public class BasicController {

@GetMapping(headers = {"foo=bar"})
public String get1() {
return null;
}

@GetMapping(headers = {"fi=ri"})
public String get2() {
return null;
}

@GetMapping(
headers = {"User-Agent=" + "MyUserAgent"})
public String get3() {
return null;
}
}
Expand Up @@ -40,7 +40,60 @@
}
}
}
},
"/": {
"get": {
"tags": [
"basic-controller"
],
"operationId": "get1_1_1",
"parameters": [
{
"name": "foo",
"in": "header",
"schema": {
"type": "string",
"enum": [
"bar"
]
}
},
{
"name": "fi",
"in": "header",
"schema": {
"type": "string",
"enum": [
"ri"
]
}
},
{
"name": "User-Agent",
"in": "header",
"schema": {
"type": "string",
"enum": [
"MyUserAgent"
]
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {}
}

0 comments on commit 78df2f5

Please sign in to comment.