Skip to content

Add test for unevaluatedProperties and update to light-4j 2.1.35 (Fixes #48) #61

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.json-schema-validator>1.3.3</version.json-schema-validator>
<version.light-4j>2.1.34</version.light-4j>
<version.light-4j>2.1.35</version.light-4j>
<version.jackson>2.16.1</version.jackson>
<version.snakeyaml>2.2</version.snakeyaml>
<version.slf4j>2.0.12</version.slf4j>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.networknt.status.Status;
import org.junit.Assert;

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
Expand All @@ -22,10 +22,10 @@

public class OpenApiValidatorTest {

static OpenApiValidator openApiValidator;
private OpenApiValidator openApiValidator;

@BeforeClass
public static void setUp() {
@Before
public void setUp() {
openApiValidator = new OpenApiValidator("openapi.yaml");
}

Expand Down Expand Up @@ -503,4 +503,20 @@ public void testResponseHeader2() {
// {"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - $: string found, integer expected","severity":"ERROR"}
}


@Test
public void testOpenApi3UnevaluatedProperties() {
openApiValidator = new OpenApiValidator("config/openapi3-unevaluatedProperties.yaml");
InputStream in = this.getClass().getClassLoader().getResourceAsStream("json/person_bad_req.json");
String req1 = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));

RequestEntity requestEntity = new RequestEntity();
requestEntity.setRequestBody(req1);
requestEntity.setContentType("application/json");
Status status = openApiValidator.validateRequestPath("/pets", "post", requestEntity);
Assert.assertNotNull(status);
Assert.assertEquals(status.getDescription(), "Schema Validation Error - $: property 'invalid' is not evaluated and the schema does not allow unevaluated properties");
}


}
63 changes: 63 additions & 0 deletions src/test/resources/config/openapi3-unevaluatedProperties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
openapi: 3.1.0
info:
version: 1.0.0
title: Swagger Petstore
paths:
/pets:
post:
summary: Create a pet
operationId: createPets
requestBody:
description: Pet to add to the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Person'
responses:
'201':
description: Null response
components:

schemas:
address:
properties:
residence:
$ref: '#/components/schemas/residence'
description: Residence details where the person lives
city:
type: string
description: City where the person lives.
street:
type: string
description: street where the person lives.
pinCode:
type: number
description: pincode of street
unevaluatedProperties: false
residence:
properties:
flatNumber:
type: string
flatName:
type: string
landmark:
type: string
unevaluatedProperties: false
Person:
properties:
firstName:
type: string
description: The person's first name.
lastName:
type: string
description: The person's last name.
age:
description: Age in years which must be equal to or greater than zero.
type: integer
minimum: 0
address:
description: Address of the person.
$ref: '#/components/schemas/address'
unevaluatedProperties: false

9 changes: 9 additions & 0 deletions src/test/resources/json/person_bad_req.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"firstName": "First Name",
"invalid": 18,
"lastName": "Last Name",
"address": {
"city": "Hyderabad",
"pinCode": 500025
}
}