Skip to content

Commit b7b6bb4

Browse files
authored
Merge pull request #482 from swagger-api/issue-480
added fix, test for #480
2 parents 98f620c + 8db467e commit b7b6bb4

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,10 +1245,18 @@ else if (type.equals("apiKey")) {
12451245
output.setDescription(description);
12461246
}
12471247
}
1248+
JsonNode desc = node.get("description");
1249+
if(desc != null) {
1250+
output.setDescription(desc.textValue());
1251+
}
12481252
}
12491253
else if (type.equals("oauth2")) {
12501254
// TODO: parse manually for better feedback
12511255
output = Json.mapper().convertValue(node, OAuth2Definition.class);
1256+
JsonNode desc = node.get("description");
1257+
if(desc != null) {
1258+
output.setDescription(desc.textValue());
1259+
}
12521260
}
12531261
else {
12541262
result.invalidType(location + ".type", "type", "basic|apiKey|oauth2", node);

modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import io.swagger.models.RefModel;
1010
import io.swagger.models.Response;
1111
import io.swagger.models.Swagger;
12+
import io.swagger.models.auth.ApiKeyAuthDefinition;
13+
import io.swagger.models.auth.OAuth2Definition;
14+
import io.swagger.models.auth.SecuritySchemeDefinition;
1215
import io.swagger.models.parameters.BodyParameter;
1316
import io.swagger.models.parameters.FormParameter;
1417
import io.swagger.models.parameters.HeaderParameter;
@@ -830,7 +833,6 @@ public void testIssue357() {
830833
public void testIssue358() {
831834
SwaggerParser parser = new SwaggerParser();
832835
final Swagger swagger = parser.read("src/test/resources/issue_358.yaml");
833-
Json.prettyPrint(swagger);
834836
assertNotNull(swagger);
835837
List<Parameter> parms = swagger.getPath("/testApi").getGet().getParameters();
836838
assertEquals(1, parms.size());
@@ -931,4 +933,22 @@ public void testIssue450() {
931933
assertEquals(petArray.getVendorExtensions().get(xTag),xVal);
932934
}
933935

936+
@Test
937+
public void testIssue480() {
938+
final Swagger swagger = new SwaggerParser().read("src/test/resources/issue-480.yaml");
939+
940+
for(String key : swagger.getSecurityDefinitions().keySet()) {
941+
SecuritySchemeDefinition definition = swagger.getSecurityDefinitions().get(key);
942+
if("petstore_auth".equals(key)) {
943+
assertTrue(definition instanceof OAuth2Definition);
944+
OAuth2Definition oauth = (OAuth2Definition) definition;
945+
assertEquals("This is a description", oauth.getDescription());
946+
}
947+
if("api_key".equals(key)) {
948+
assertTrue(definition instanceof ApiKeyAuthDefinition);
949+
ApiKeyAuthDefinition auth = (ApiKeyAuthDefinition) definition;
950+
assertEquals("This is another description", auth.getDescription());
951+
}
952+
}
953+
}
934954
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
swagger: "2.0"
2+
info:
3+
version: "1.0.0"
4+
title: "Swagger Petstore"
5+
basePath: "/v2"
6+
schemes:
7+
- "http"
8+
paths:
9+
/pet:
10+
post:
11+
tags:
12+
- "pet"
13+
summary: "Add a new pet to the store"
14+
description: ""
15+
operationId: "addPet"
16+
consumes:
17+
- "application/json"
18+
- "application/xml"
19+
produces:
20+
- "application/xml"
21+
- "application/json"
22+
parameters:
23+
- in: "body"
24+
name: "body"
25+
description: "Pet object that needs to be added to the store"
26+
required: true
27+
schema:
28+
$ref: "#/definitions/Pet"
29+
responses:
30+
405:
31+
description: "Invalid input"
32+
security:
33+
- api_key: []
34+
put:
35+
tags:
36+
- "pet"
37+
summary: "Update an existing pet"
38+
description: ""
39+
operationId: "updatePet"
40+
consumes:
41+
- "application/json"
42+
- "application/xml"
43+
produces:
44+
- "application/xml"
45+
- "application/json"
46+
parameters:
47+
- in: "body"
48+
name: "body"
49+
description: "Pet object that needs to be added to the store"
50+
required: true
51+
schema:
52+
$ref: "#/definitions/Pet"
53+
responses:
54+
400:
55+
description: "Invalid ID supplied"
56+
404:
57+
description: "Pet not found"
58+
405:
59+
description: "Validation exception"
60+
security:
61+
- petstore_auth:
62+
- "write:pets"
63+
- "read:pets"
64+
65+
securityDefinitions:
66+
petstore_auth:
67+
type: "oauth2"
68+
description: "This is a description"
69+
authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
70+
flow: "implicit"
71+
scopes:
72+
write:pets: "modify pets in your account"
73+
read:pets: "read your pets"
74+
api_key:
75+
type: "apiKey"
76+
name: "api_key"
77+
description: "This is another description"
78+
in: "header"
79+
80+
definitions:
81+
Pet:
82+
type: "object"
83+
required:
84+
- "name"
85+
- "photoUrls"
86+
properties:
87+
id:
88+
type: "integer"
89+
format: "int64"
90+
name:
91+
type: "string"
92+
example: "doggie"
93+
photoUrls:
94+
type: "array"
95+
xml:
96+
name: "photoUrl"
97+
wrapped: true
98+
items:
99+
type: "string"
100+
status:
101+
type: "string"
102+
description: "pet status in the store"
103+
enum:
104+
- "available"
105+
- "pending"
106+
- "sold"
107+
xml:
108+
name: "Pet"

0 commit comments

Comments
 (0)