Skip to content

Commit

Permalink
Merge pull request #482 from swagger-api/issue-480
Browse files Browse the repository at this point in the history
added fix, test for #480
  • Loading branch information
fehguy authored Jul 14, 2017
2 parents 98f620c + 8db467e commit b7b6bb4
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1245,10 +1245,18 @@ else if (type.equals("apiKey")) {
output.setDescription(description);
}
}
JsonNode desc = node.get("description");
if(desc != null) {
output.setDescription(desc.textValue());
}
}
else if (type.equals("oauth2")) {
// TODO: parse manually for better feedback
output = Json.mapper().convertValue(node, OAuth2Definition.class);
JsonNode desc = node.get("description");
if(desc != null) {
output.setDescription(desc.textValue());
}
}
else {
result.invalidType(location + ".type", "type", "basic|apiKey|oauth2", node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import io.swagger.models.RefModel;
import io.swagger.models.Response;
import io.swagger.models.Swagger;
import io.swagger.models.auth.ApiKeyAuthDefinition;
import io.swagger.models.auth.OAuth2Definition;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.FormParameter;
import io.swagger.models.parameters.HeaderParameter;
Expand Down Expand Up @@ -830,7 +833,6 @@ public void testIssue357() {
public void testIssue358() {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/issue_358.yaml");
Json.prettyPrint(swagger);
assertNotNull(swagger);
List<Parameter> parms = swagger.getPath("/testApi").getGet().getParameters();
assertEquals(1, parms.size());
Expand Down Expand Up @@ -931,4 +933,22 @@ public void testIssue450() {
assertEquals(petArray.getVendorExtensions().get(xTag),xVal);
}

@Test
public void testIssue480() {
final Swagger swagger = new SwaggerParser().read("src/test/resources/issue-480.yaml");

for(String key : swagger.getSecurityDefinitions().keySet()) {
SecuritySchemeDefinition definition = swagger.getSecurityDefinitions().get(key);
if("petstore_auth".equals(key)) {
assertTrue(definition instanceof OAuth2Definition);
OAuth2Definition oauth = (OAuth2Definition) definition;
assertEquals("This is a description", oauth.getDescription());
}
if("api_key".equals(key)) {
assertTrue(definition instanceof ApiKeyAuthDefinition);
ApiKeyAuthDefinition auth = (ApiKeyAuthDefinition) definition;
assertEquals("This is another description", auth.getDescription());
}
}
}
}
108 changes: 108 additions & 0 deletions modules/swagger-parser/src/test/resources/issue-480.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
swagger: "2.0"
info:
version: "1.0.0"
title: "Swagger Petstore"
basePath: "/v2"
schemes:
- "http"
paths:
/pet:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
405:
description: "Invalid input"
security:
- api_key: []
put:
tags:
- "pet"
summary: "Update an existing pet"
description: ""
operationId: "updatePet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Pet not found"
405:
description: "Validation exception"
security:
- petstore_auth:
- "write:pets"
- "read:pets"

securityDefinitions:
petstore_auth:
type: "oauth2"
description: "This is a description"
authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
flow: "implicit"
scopes:
write:pets: "modify pets in your account"
read:pets: "read your pets"
api_key:
type: "apiKey"
name: "api_key"
description: "This is another description"
in: "header"

definitions:
Pet:
type: "object"
required:
- "name"
- "photoUrls"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
example: "doggie"
photoUrls:
type: "array"
xml:
name: "photoUrl"
wrapped: true
items:
type: "string"
status:
type: "string"
description: "pet status in the store"
enum:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"

0 comments on commit b7b6bb4

Please sign in to comment.