forked from everit-org/json-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
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 everit-org#398 from dab-libs/master
Fixes the issue everit-org#382: The 'default' can't be used in 'oneOf'
- Loading branch information
Showing
10 changed files
with
232 additions
and
9 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
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
53 changes: 53 additions & 0 deletions
53
core/src/test/java/org/everit/json/schema/DefaultInOneOfTest.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,53 @@ | ||
package org.everit.json.schema; | ||
|
||
import org.everit.json.schema.loader.SchemaLoader; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.json.JSONTokener; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.everit.json.schema.TestSupport.loadAsV6; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class DefaultInOneOfTest { | ||
|
||
private static final ResourceLoader LOADER = ResourceLoader.DEFAULT; | ||
|
||
@Test | ||
public void defaultInFirstOneOf() { | ||
JSONObject jsonSchema = LOADER.readObj("default-in-first-oneof-schema.json"); | ||
JSONObject jsonSpecification = LOADER.readObj("default-in-oneof.json"); | ||
Schema schema = SchemaLoader | ||
.builder() | ||
.useDefaults(true) | ||
.schemaJson(jsonSchema) | ||
.build() | ||
.load() | ||
.build(); | ||
assertDoesNotThrow(() -> schema.validate(jsonSpecification)); | ||
assertTrue(jsonSpecification.getJSONObject("parameter1").has("allowEmptyValue")); | ||
assertFalse(jsonSpecification.getJSONObject("parameter1").getBoolean("allowEmptyValue")); | ||
assertFalse(jsonSpecification.getJSONObject("parameter2").has("allowEmptyValue")); | ||
} | ||
|
||
@Test | ||
public void defaultInLastOneOf() { | ||
JSONObject jsonSchema = LOADER.readObj("default-in-last-oneof-schema.json"); | ||
JSONObject jsonSpecification = LOADER.readObj("default-in-oneof.json"); | ||
Schema schema = SchemaLoader | ||
.builder() | ||
.useDefaults(true) | ||
.schemaJson(jsonSchema) | ||
.build() | ||
.load() | ||
.build(); | ||
assertDoesNotThrow(() -> schema.validate(jsonSpecification)); | ||
assertTrue(jsonSpecification.getJSONObject("parameter1").has("allowEmptyValue")); | ||
assertFalse(jsonSpecification.getJSONObject("parameter1").getBoolean("allowEmptyValue")); | ||
assertFalse(jsonSpecification.getJSONObject("parameter2").has("allowEmptyValue")); | ||
} | ||
|
||
} |
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
61 changes: 61 additions & 0 deletions
61
core/src/test/resources/org/everit/jsonvalidator/default-in-first-oneof-schema.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,61 @@ | ||
{ | ||
"title": "A Bug Schema is a part for Swagger 2.0 API.", | ||
"id": "http://bug-schema.org/schema.json#", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"required": [ | ||
"parameter1", | ||
"parameter2" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"parameter1": { | ||
"$ref": "#/definitions/nonBodyParameter" | ||
}, | ||
"parameter2": { | ||
"$ref": "#/definitions/nonBodyParameter" | ||
} | ||
}, | ||
"definitions": { | ||
"nonBodyParameter": { | ||
"type": "object", | ||
"required": [ | ||
"in" | ||
], | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/queryParameterSubSchema" | ||
}, | ||
{ | ||
"$ref": "#/definitions/pathParameterSubSchema" | ||
} | ||
] | ||
}, | ||
"queryParameterSubSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"in": { | ||
"type": "string", | ||
"enum": [ | ||
"query" | ||
] | ||
}, | ||
"allowEmptyValue": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
} | ||
}, | ||
"pathParameterSubSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"in": { | ||
"type": "string", | ||
"enum": [ | ||
"path" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
core/src/test/resources/org/everit/jsonvalidator/default-in-last-oneof-schema.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,61 @@ | ||
{ | ||
"title": "A Bug Schema is a part for Swagger 2.0 API.", | ||
"id": "http://bug-schema.org/schema.json#", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"required": [ | ||
"parameter1", | ||
"parameter2" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"parameter1": { | ||
"$ref": "#/definitions/nonBodyParameter" | ||
}, | ||
"parameter2": { | ||
"$ref": "#/definitions/nonBodyParameter" | ||
} | ||
}, | ||
"definitions": { | ||
"nonBodyParameter": { | ||
"type": "object", | ||
"required": [ | ||
"in" | ||
], | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/pathParameterSubSchema" | ||
}, | ||
{ | ||
"$ref": "#/definitions/queryParameterSubSchema" | ||
} | ||
] | ||
}, | ||
"queryParameterSubSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"in": { | ||
"type": "string", | ||
"enum": [ | ||
"query" | ||
] | ||
}, | ||
"allowEmptyValue": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
} | ||
}, | ||
"pathParameterSubSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"in": { | ||
"type": "string", | ||
"enum": [ | ||
"path" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
core/src/test/resources/org/everit/jsonvalidator/default-in-oneof.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,8 @@ | ||
{ | ||
"parameter1": { | ||
"in": "query" | ||
}, | ||
"parameter2": { | ||
"in": "path" | ||
} | ||
} |