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

Fix for issue 895 #896

Merged
merged 3 commits into from Oct 31, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -813,6 +813,12 @@ public License getLicense(ObjectNode node, String location, ParseResult result)

value = getString("url", node, false, location, result);
if(StringUtils.isNotBlank(value)) {
try {
new URL(value);
}
catch (Exception e) {
result.warning(location,value);
}
license.setUrl(value);
}

Expand Down Expand Up @@ -844,6 +850,12 @@ public Contact getContact(ObjectNode node, String location, ParseResult result)

value = getString("url", node, false, location, result);
if(StringUtils.isNotBlank(value)) {
try {
new URL(value);
}
catch (Exception e) {
result.warning(location,value);
}
contact.setUrl(value);
}

Expand Down
Expand Up @@ -75,6 +75,16 @@ public void testIssue887() {
assertEquals(result.getMessages().get(0), "attribute tags.sample is repeated");
}

@Test
public void testIssue895() {
SwaggerParseResult result = new OpenAPIParser().readLocation("issue895.yaml", null, null);
assertNotNull(result);
assertNotNull(result.getOpenAPI());
assertEquals(result.getMessages().get(0),"attribute info.contact.test");
assertEquals(result.getMessages().get(1),"attribute info.license.test1");

}

@Test
public void testIssue892() {
SwaggerParseResult result = new OpenAPIParser().readLocation("issue892-main.yaml", null, null);
Expand Down
186 changes: 186 additions & 0 deletions modules/swagger-parser/src/test/resources/issue895.yaml
@@ -0,0 +1,186 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"contact": {
"name": "API Support",
"url": "test",
"email": "support@example.com"
},
"license": {
"name": "Apache 2.0",
"url": "test1"
}
},
"servers": [
{
"url": "http://petstore.swagger.io/v1"
}
],
"tags" : [
{"name":"pet" ,
"description":"+ data"
}
],
"paths": {
"/pets": {
"get": {
"summary": "List all pets",
"operationId": "listPets",
"tags": [
"pets"
],
"parameters": [
{
"name": "limit",
"in": "query",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "A paged array of pets",
"headers": {
"x-next": {
"description": "A link to the next page of responses",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
},
"post": {
"summary": "Create a pet",
"operationId": "createPets",
"tags": [
"pets"
],
"responses": {
"201": {
"description": "Null response"
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/pets/{petId}": {
"get": {
"summary": "Info for a specific pet",
"operationId": "showPetById",
"tags": [
"pets"
],
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"description": "The id of the pet to retrieve",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Expected response to a valid request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Pets": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"Error": {
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
}