-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds draft6 tests and python file reader
- Loading branch information
Showing
112 changed files
with
14,738 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
generatorName: python-experimental | ||
outputDir: samples/openapi3/client/3_0_3_unit_test/python-experimental | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/unit_test_spec/type.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/python-experimental | ||
additionalProperties: | ||
packageName: unit_test_api |
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
54 changes: 54 additions & 0 deletions
54
modules/openapi-generator/src/main/java/org/openapitools/codegen/ObjectWithTypeBooleans.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,54 @@ | ||
package org.openapitools.codegen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class ObjectWithTypeBooleans { | ||
public boolean isUnboundedInteger; | ||
public boolean isNumber; | ||
public boolean isString; | ||
public boolean isMap; | ||
public boolean isArray; | ||
public boolean isBoolean; | ||
public boolean isNull; | ||
public Object value; | ||
|
||
public ObjectWithTypeBooleans(Object value) { | ||
Object usedValue = null; | ||
if (value instanceof Integer){ | ||
this.isUnboundedInteger = true; | ||
this.value = value; | ||
} else if (value instanceof Double || value instanceof Float){ | ||
this.isNumber = true; | ||
this.value = value; | ||
} else if (value instanceof String) { | ||
this.isString = true; | ||
this.value = value; | ||
} else if (value instanceof LinkedHashMap) { | ||
LinkedHashMap<String, Object> castValue = (LinkedHashMap<String, Object>) value; | ||
LinkedHashMap<String, ObjectWithTypeBooleans> castMap = new LinkedHashMap<>(); | ||
for (Map.Entry entry: castValue.entrySet()) { | ||
String entryKey = (String) entry.getKey(); | ||
ObjectWithTypeBooleans entryValue = new ObjectWithTypeBooleans(entry.getValue()); | ||
castMap.put(entryKey, entryValue); | ||
} | ||
this.value = castMap; | ||
this.isMap = true; | ||
} else if (value instanceof ArrayList) { | ||
ArrayList<ObjectWithTypeBooleans> castList = new ArrayList<>(); | ||
for (Object item: (ArrayList<Object>) value) { | ||
castList.add(new ObjectWithTypeBooleans(item)); | ||
} | ||
this.value = castList; | ||
this.isArray = true; | ||
} else if (value instanceof Boolean) { | ||
this.isBoolean = true; | ||
this.value = value; | ||
} else if (value == null) { | ||
this.isNull = true; | ||
this.value = value; | ||
} | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
modules/openapi-generator/src/main/java/org/openapitools/codegen/SchemaTestCase.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,14 @@ | ||
package org.openapitools.codegen; | ||
|
||
public class SchemaTestCase { | ||
public String description; | ||
public ObjectWithTypeBooleans data; | ||
// true means the test case should pass, false means it should fail | ||
public boolean valid; | ||
|
||
public SchemaTestCase(String description, ObjectWithTypeBooleans data, boolean valid) { | ||
this.description = description; | ||
this.data = data; | ||
this.valid = valid; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...erator/src/main/resources/python-experimental/model_templates/payload_renderer.handlebars
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,33 @@ | ||
{{#or isNumber isUnboundedInteger}} | ||
{{value}} | ||
{{/or}} | ||
{{#if isBoolean}} | ||
{{#if value}} | ||
True | ||
{{else}} | ||
False | ||
{{/if}} | ||
{{/if}} | ||
{{#if isNull}} | ||
None | ||
{{/if}} | ||
{{#if isString}} | ||
"{{value}}" | ||
{{/if}} | ||
{{#if isArray}} | ||
[ | ||
{{#each value}} | ||
{{> model_templates/payload_renderer }} | ||
{{/each}} | ||
] | ||
{{/if}} | ||
{{#if isMap}} | ||
{ | ||
{{#each value}} | ||
"{{@key}}": | ||
{{#with this}} | ||
{{> model_templates/payload_renderer }}, | ||
{{/with}} | ||
{{/each}} | ||
} | ||
{{/if}} |
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
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/test/resources/3_0/unit_test_spec/.gitignore
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 @@ | ||
venv |
149 changes: 149 additions & 0 deletions
149
modules/openapi-generator/src/test/resources/3_0/unit_test_spec/draft6/additionalItems.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,149 @@ | ||
[ | ||
{ | ||
"description": "additionalItems as schema", | ||
"schema": { | ||
"items": [{}], | ||
"additionalItems": {"type": "integer"} | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "additional items match schema", | ||
"data": [ null, 2, 3, 4 ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "additional items do not match schema", | ||
"data": [ null, 2, 3, "foo" ], | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "when items is schema, additionalItems does nothing", | ||
"schema": { | ||
"items": {}, | ||
"additionalItems": false | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "all items match schema", | ||
"data": [ 1, 2, 3, 4, 5 ], | ||
"valid": true | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "array of items with no additionalItems permitted", | ||
"schema": { | ||
"items": [{}, {}, {}], | ||
"additionalItems": false | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "empty array", | ||
"data": [ ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "fewer number of items present (1)", | ||
"data": [ 1 ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "fewer number of items present (2)", | ||
"data": [ 1, 2 ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "equal number of items present", | ||
"data": [ 1, 2, 3 ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "additional items are not permitted", | ||
"data": [ 1, 2, 3, 4 ], | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "additionalItems as false without items", | ||
"schema": {"additionalItems": false}, | ||
"tests": [ | ||
{ | ||
"description": | ||
"items defaults to empty schema so everything is valid", | ||
"data": [ 1, 2, 3, 4, 5 ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "ignores non-arrays", | ||
"data": {"foo" : "bar"}, | ||
"valid": true | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "additionalItems are allowed by default", | ||
"schema": {"items": [{"type": "integer"}]}, | ||
"tests": [ | ||
{ | ||
"description": "only the first item is validated", | ||
"data": [1, "foo", false], | ||
"valid": true | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "additionalItems should not look in applicators, valid case", | ||
"schema": { | ||
"allOf": [ | ||
{ "items": [ { "type": "integer" } ] } | ||
], | ||
"additionalItems": { "type": "boolean" } | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "items defined in allOf are not examined", | ||
"data": [ 1, null ], | ||
"valid": true | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "additionalItems should not look in applicators, invalid case", | ||
"schema": { | ||
"allOf": [ | ||
{ "items": [ { "type": "integer" }, { "type": "string" } ] } | ||
], | ||
"items": [ {"type": "integer" } ], | ||
"additionalItems": { "type": "boolean" } | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "items defined in allOf are not examined", | ||
"data": [ 1, "hello" ], | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "items validation adjusts the starting index for additionalItems", | ||
"schema": { | ||
"items": [ { "type": "string" } ], | ||
"additionalItems": { "type": "integer" } | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "valid items", | ||
"data": [ "x", 2, 3 ], | ||
"valid": true | ||
}, | ||
{ | ||
"description": "wrong type of second item", | ||
"data": [ "x", "y" ], | ||
"valid": false | ||
} | ||
] | ||
} | ||
] |
Oops, something went wrong.