Skip to content
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 @@ -78,15 +78,15 @@ public abstract class EbaySchemaTransformer {
static void applyToChildSchemas(final JsonNode schemaObject, final Consumer<JsonNode> consumer) {
if (isArrayDefinition(schemaObject)) {
consumer.accept(itemsDefinition(schemaObject));
return;
} else {
properties(schemaObject).forEachRemaining(consumer);
allOf(schemaObject).forEachRemaining(consumer);
anyOf(schemaObject).forEachRemaining(consumer);
oneOf(schemaObject).forEachRemaining(consumer);
schemaComponents(schemaObject).forEachRemaining(consumer);
additionalProperties(schemaObject).forEachRemaining(consumer);
}
properties(schemaObject).forEachRemaining(consumer);
allOf(schemaObject).forEachRemaining(consumer);
anyOf(schemaObject).forEachRemaining(consumer);
oneOf(schemaObject).forEachRemaining(consumer);
schemaComponents(schemaObject).forEachRemaining(consumer);
definitions(schemaObject).forEachRemaining(consumer);
additionalProperties(schemaObject).forEachRemaining(consumer);
}

protected static boolean hasAllOfField(final JsonNode n) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public void convert() {
throw new IllegalStateException(String.format("Status code [%s] is not present for request method [%s] and path [%s] in file: %s", statusCode, requestMethod, requestPath, openApiSpecFilePath));
}

//added below check to fix NPE
if(response.getContent() != null) {
//added below check to fix NPE
if(response.getContent() != null) {
MediaType mediaType = response.getContent().get(MEDIA_TYPE);
if (mediaType == null) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,28 @@ public void schemaValidatePassNullableArrayItem() throws Exception {

validator.validate(testResponsePayload);
}

@Test
public void schemaValidateNullableProperties() throws Exception {

OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/nullableProperties.yaml", "/test", NstRequestType.GET)
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO)
.build();

String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/validResponseNullableProperties.json");

validator.validate(testResponsePayload);
}

@Test
public void schemaValidateNullablePropertiesWithValues() throws Exception {

OpenApiSchemaValidator validator = new OpenApiSchemaValidator.Builder("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/schema/nullableProperties.yaml", "/test", NstRequestType.GET)
.allowAdditionalProperties(OpenApiSchemaValidator.AllowAdditionalProperties.NO)
.build();

String testResponsePayload = ResourceParser.readInResourceFile("/com/ebay/nst/schema/validation/OpenApiSchemaValidatorTest/json/validResponseNullablePropertiesWithValues.json");

validator.validate(testResponsePayload);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"rank": null,
"price": 1,
"name": null,
"rate": null,
"url": null
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"rank": 1,
"price": 1,
"name": "bob",
"rate": 2,
"url": "https://www.ebay.com"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
openapi: 3.0.0
info:
title: Type Definitions
description: >-
Type Definitions
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/NullablePropertyResponse'
components:
schemas:
NullablePropertyResponse:
type: array
items:
$ref: '#/components/schemas/NullablePropertyObject'
NullablePropertyObject:
type: object
additionalProperties: true
required:
- rank
- price
properties:
rank:
type: integer
nullable: true
price:
type: number
minimum: 0
name:
type: string
nullable: true
rate:
type: number
nullable: true
url:
type: string
format: uri
nullable: true
2 changes: 1 addition & 1 deletion NSTTutorials/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<maven.compiler.plugin.version>3.6.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>2.9</maven.surefire.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nstest.version>1.3.1</nstest.version>
<nstest.version>1.3.6</nstest.version>
<nsttutorials.version>0.0.1-SNAPSHOT</nsttutorials.version>
<testng.version>7.5</testng.version>
<maven.deploy.skip>true</maven.deploy.skip>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<maven.compiler.plugin.version>3.6.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>2.9</maven.surefire.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nstest.version>1.3.5</nstest.version>
<nstest.version>1.3.6</nstest.version>
<testng.version>7.5</testng.version>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
Expand Down