-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from eBay/byarger/parseOptions
Issue 48 : Support OpenAPISchemaValidator's use of Swagger's ParseOptions
- Loading branch information
Showing
11 changed files
with
371 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
NST/src/test/java/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.ebay.nst.schema.validation; | ||
|
||
import com.ebay.nst.NstRequestType; | ||
import com.ebay.nst.schema.validation.support.SchemaValidationException; | ||
import com.ebay.utility.ResourceParser; | ||
import io.swagger.v3.parser.core.models.ParseOptions; | ||
import org.testng.annotations.Test; | ||
|
||
public class OpenApiSchemaValidatorTest { | ||
|
||
@Test | ||
public void schemaValidatePassWithRelativePathRefs() throws Exception { | ||
|
||
ParseOptions parseOptions = new ParseOptions(); | ||
parseOptions.setResolve(true); | ||
|
||
OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/root.yaml", "/test", NstRequestType.GET) | ||
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO).setParseOptions(parseOptions) | ||
.build(); | ||
|
||
String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/validResponse.json"); | ||
|
||
validator.validate(testResponsePayload); | ||
} | ||
|
||
@Test | ||
public void schemaValidatePassWithAllLocalReferences() throws Exception { | ||
|
||
OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/singleRootDocumentWithReferences.yaml", "/test", NstRequestType.GET) | ||
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO) | ||
.build(); | ||
|
||
String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/validResponse.json"); | ||
|
||
validator.validate(testResponsePayload); | ||
} | ||
|
||
@Test | ||
public void schemaValidatePassEverythingInline() throws Exception { | ||
|
||
OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/singleRootDocumentInlined.yaml", "/test", NstRequestType.GET) | ||
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO) | ||
.build(); | ||
|
||
String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/validResponse.json"); | ||
|
||
validator.validate(testResponsePayload); | ||
} | ||
|
||
@Test(expectedExceptions = SchemaValidationException.class) | ||
public void schemaValidateFailWithRelativePathRefs() throws Exception { | ||
|
||
ParseOptions parseOptions = new ParseOptions(); | ||
parseOptions.setResolve(true); | ||
|
||
OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/root.yaml", "/test", NstRequestType.GET) | ||
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO).setParseOptions(parseOptions) | ||
.build(); | ||
|
||
String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/invalidResponse.json"); | ||
|
||
validator.validate(testResponsePayload); | ||
} | ||
|
||
@Test(expectedExceptions = SchemaValidationException.class) | ||
public void schemaValidateFailWithAllLocalReferences() throws Exception { | ||
|
||
OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/singleRootDocumentWithReferences.yaml", "/test", NstRequestType.GET) | ||
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO) | ||
.build(); | ||
|
||
String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/invalidResponse.json"); | ||
|
||
validator.validate(testResponsePayload); | ||
} | ||
|
||
@Test(expectedExceptions = SchemaValidationException.class) | ||
public void schemaValidateFailEverythingInline() throws Exception { | ||
|
||
OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/singleRootDocumentInlined.yaml", "/test", NstRequestType.GET) | ||
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO) | ||
.build(); | ||
|
||
String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/invalidResponse.json"); | ||
|
||
validator.validate(testResponsePayload); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...urces/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/invalidResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"numberOfFruit": 100, | ||
"typesOfApples": [ | ||
{ | ||
"name": "Fuji", | ||
"color": 1 | ||
}, | ||
{ | ||
"name": "Gala", | ||
"color": "YELLOW" | ||
} | ||
], | ||
"typesOfBananas": [ | ||
{ | ||
"name": "Big Yellow", | ||
"color": "YELLOW" | ||
}, | ||
{ | ||
"name": "Old Brown", | ||
"color": 2 | ||
} | ||
] | ||
} |
23 changes: 23 additions & 0 deletions
23
...sources/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/validResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"numberOfFruit": 100, | ||
"typesOfApples": [ | ||
{ | ||
"name": "Fuji", | ||
"color": "RED" | ||
}, | ||
{ | ||
"name": "Gala", | ||
"color": "YELLOW" | ||
} | ||
], | ||
"typesOfBananas": [ | ||
{ | ||
"name": "Big Yellow", | ||
"color": "YELLOW" | ||
}, | ||
{ | ||
"name": "Old Brown", | ||
"color": "BROWN" | ||
} | ||
] | ||
} |
36 changes: 36 additions & 0 deletions
36
...test/resources/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/root.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Root Schema | ||
description: >- | ||
Root Schema | ||
version: 1.0.0 | ||
servers: | ||
- url: 'http://ebay.com' | ||
description: QATE | ||
paths: | ||
/test: | ||
get: | ||
summary: placeholder summary | ||
responses: | ||
'200': | ||
description: Success | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/TestResponse' | ||
components: | ||
schemas: | ||
TestResponse: | ||
type: object | ||
properties: | ||
numberOfFruit: | ||
type: integer | ||
format: int32 | ||
typesOfApples: | ||
type: array | ||
items: | ||
$ref: "types.yaml#/components/schemas/Apple" | ||
typesOfBananas: | ||
type: array | ||
items: | ||
$ref: "types.yaml#/components/schemas/Banana" |
54 changes: 54 additions & 0 deletions
54
...ay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/singleRootDocumentInlined.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Root Schema | ||
description: >- | ||
Root Schema | ||
version: 1.0.0 | ||
servers: | ||
- url: 'http://ebay.com' | ||
description: QATE | ||
paths: | ||
/test: | ||
get: | ||
summary: placeholder summary | ||
responses: | ||
'200': | ||
description: Success | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/TestResponse' | ||
components: | ||
schemas: | ||
TestResponse: | ||
type: object | ||
properties: | ||
numberOfFruit: | ||
type: integer | ||
format: int32 | ||
typesOfApples: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
color: | ||
type: string | ||
enum: | ||
- RED | ||
- GREEN | ||
- YELLOW | ||
typesOfBananas: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
color: | ||
type: string | ||
enum: | ||
- YELLOW | ||
- GREEN | ||
- BROWN |
Oops, something went wrong.