Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix, test for #480 #482

Merged
merged 2 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"