-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds openapi v3.0.3 unit test spec, includes test cases, autogenerate…
…s model tests with them (#12619) * Adds draft6 tests and python file reader * Adds processing of multiple files * Moves test examples into a different component so component schemas can be booleans * Excludes boolean schema cases and some others that contain patternProperties * Adds automatic test generation, template not quite working with indentation * Turns on allOf tests, some failing * Adds more generated components and tests * Adds enum tests * Turns on all of themissing tests * Adds exclmax and min exclusion reasons * Adds items test cases * Adds maximum * Adds maxItems * Adds maxLength * Adds maxProperties * Adds minimum * Adds minItems * Adds minLength * Adds minProperties * Adds multipleOf * Adds not * Adds oneOf * Adds pattern * Adds patternProperties * Working on properties examples, partial fix for escaped characters * Further improves example string escaping * Fixes properties test cases * Adds draft6 test samples license * Adds ref * Finishes ref * Adds remoteRef * Adds required * Improves required testing * Fixes build error / javadoc warning * Fixes uniqueItems bug in python-experimental * Turns all tests back on * Fixes 2 failing tests, all python tests pass * Fixes java npe errors * Fixes formatting of tests, indentation fixed * Test fase name fixed to toTestCaseName, docstring added to ObjectWithTypeBooleans * Fixes typo * Adds test deletion to samples generation, samples regenerated * Updates python-exp unit test sample, includes new ref examples
- Loading branch information
Showing
302 changed files
with
26,949 additions
and
53 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/3_0_3_unit_test_spec.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
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
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
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; | ||
|
||
/** | ||
* A wrapper class that is used to store payloads to be ingested by schemas | ||
* This class includes the payload value in the value property | ||
* Other booleans: isUnboundedInteger/isNumber/isString/isMap/isArray/isBoolean/isNull | ||
* allow generator templates to decide how to render each payload into code | ||
* based upon what type it is. The booleans isX describe the value in value. | ||
* @param value the input payload that is stored | ||
*/ | ||
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<ObjectWithTypeBooleans, ObjectWithTypeBooleans> castMap = new LinkedHashMap<>(); | ||
for (Map.Entry entry: castValue.entrySet()) { | ||
ObjectWithTypeBooleans entryKey = new ObjectWithTypeBooleans(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
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/main/resources/python-experimental/comma.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 @@ | ||
, |
35 changes: 35 additions & 0 deletions
35
...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,35 @@ | ||
{{#if isMap}} | ||
{ | ||
{{#each value}} | ||
{{#with @key}} | ||
{{> model_templates/payload_renderer endChar=':'}} | ||
{{/with}} | ||
{{#with this}} | ||
{{> model_templates/payload_renderer endChar=','}} | ||
{{/with}} | ||
{{/each}} | ||
}{{endChar}} | ||
{{/if}} | ||
{{#if isArray}} | ||
[ | ||
{{#each value}} | ||
{{> model_templates/payload_renderer endChar=','}} | ||
{{/each}} | ||
]{{endChar}} | ||
{{/if}} | ||
{{#or isNumber isUnboundedInteger}} | ||
{{value}}{{endChar}} | ||
{{/or}} | ||
{{#if isBoolean}} | ||
{{#if value}} | ||
True{{endChar}} | ||
{{else}} | ||
False{{endChar}} | ||
{{/if}} | ||
{{/if}} | ||
{{#if isNull}} | ||
None{{endChar}} | ||
{{/if}} | ||
{{#if isString}} | ||
"{{{value}}}"{{endChar}} | ||
{{/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
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
Oops, something went wrong.