diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 512d3de9a21f..13265572a931 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -269,10 +269,10 @@ private static void visitContent(OpenAPI openAPI, Content content, OpenAPISchema /** * Invoke the specified visitor function for every schema that matches mimeType in the OpenAPI document. - * + * * To avoid infinite recursion, referenced schemas are visited only once. When a referenced schema is visited, * it is added to visitedSchemas. - * + * * @param openAPI the OpenAPI document that contains schema objects. * @param schema the root schema object to be visited. * @param mimeType the mime type. TODO: does not seem to be used in a meaningful way. @@ -355,14 +355,14 @@ public static String getSimpleRef(String ref) { /** * Return true if the specified schema is an object with a fixed number of properties. - * + * * A ObjectSchema differs from an MapSchema in the following way: * - An ObjectSchema is not extensible, i.e. it has a fixed number of properties. * - A MapSchema is an object that can be extended with an arbitrary set of properties. * The payload may include dynamic properties. - * + * * For example, an OpenAPI schema is considered an ObjectSchema in the following scenarios: - * + * * type: object * additionalProperties: false * properties: @@ -370,7 +370,7 @@ public static String getSimpleRef(String ref) { * type: string * address: * type: string - * + * * @param schema the OAS schema * @return true if the specified schema is an Object schema. */ @@ -394,7 +394,7 @@ public static boolean isObjectSchema(Schema schema) { /** * Return true if the specified schema is composed, i.e. if it uses * 'oneOf', 'anyOf' or 'allOf'. - * + * * @param schema the OAS schema * @return true if the specified schema is a Composed schema. */ @@ -659,7 +659,7 @@ public static boolean isModel(Schema schema) { /** * Check to see if the schema is a free form object. - * + * * A free form object is an object (i.e. 'type: object' in a OAS document) that: * 1) Does not define properties, and * 2) Is not a composed schema (no anyOf, oneOf, allOf), and @@ -737,7 +737,7 @@ public static Schema getSchema(OpenAPI openAPI, String name) { * Return a Map of the schemas defined under /components/schemas in the OAS document. * The returned Map only includes the direct children of /components/schemas in the OAS document; the Map * does not include inlined schemas. - * + * * @param openAPI the OpenAPI document. * @return a map of schemas in the OAS document. */ @@ -767,7 +767,7 @@ public static List getAllSchemas(OpenAPI openAPI) { }); return allSchemas; } - + /** * If a RequestBody contains a reference to an other RequestBody with '$ref', returns the referenced RequestBody if it is found or the actual RequestBody in the other cases. * @@ -906,10 +906,10 @@ public static Schema getSchemaFromResponse(ApiResponse response) { /** * Return the first Schema from a specified OAS 'content' section. - * + * * For example, given the following OAS, this method returns the schema * for the 'application/json' content type because it is listed first in the OAS. - * + * * responses: * '200': * content: @@ -918,8 +918,8 @@ public static Schema getSchemaFromResponse(ApiResponse response) { * $ref: '#/components/schemas/XYZ' * application/xml: * ... - * - * @param content a 'content' section in the OAS specification. + * + * @param content a 'content' section in the OAS specification. * @return the Schema. */ private static Schema getSchemaFromContent(Content content) { @@ -1110,6 +1110,14 @@ public static String getParentName(ComposedSchema composedSchema, Map refedWithoutDiscriminator = new ArrayList<>(); + String schemaName = ""; + for (String thisSchemaName : allSchemas.keySet()) { + Schema sc = allSchemas.get(thisSchemaName); + if (isComposedSchema(sc) && (ComposedSchema) sc == composedSchema) { + schemaName = thisSchemaName; + break; + } + } if (interfaces != null && !interfaces.isEmpty()) { for (Schema schema : interfaces) { @@ -1126,7 +1134,10 @@ public static String getParentName(ComposedSchema composedSchema, Map getNames(List props) { @Test public void testCallbacks() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/callbacks.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/callbacks.yaml"); final CodegenConfig codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -764,7 +764,7 @@ public void testResponseWithNoSchemaInHeaders() { @Test public void testNullableProperty() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/examples.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/examples.yaml"); new InlineModelResolver().flatten(openAPI); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -776,7 +776,7 @@ public void testNullableProperty() { @Test public void testDeprecatedProperty() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/property-deplicated.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/property-deplicated.yaml"); new InlineModelResolver().flatten(openAPI); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -952,7 +952,7 @@ public void numberDoubleSchemaPropertyAndModelTest() { @Test public void testAlias() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/type_alias.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/type_alias.yaml"); new InlineModelResolver().flatten(openAPI); final DefaultCodegen codegen = new DefaultCodegen(); @@ -1052,7 +1052,7 @@ private Map codegenModelWithXEnumVarName() { @Test public void objectQueryParamIdentifyAsObject() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/objectQueryParam.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/objectQueryParam.yaml"); new InlineModelResolver().flatten(openAPI); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -1060,14 +1060,15 @@ public void objectQueryParamIdentifyAsObject() { Set imports = new HashSet<>(); CodegenParameter parameter = codegen.fromParameter(openAPI.getPaths().get("/pony").getGet().getParameters().get(0), imports); - Assert.assertEquals(parameter.dataType, "PageQuery"); + // TODO: This must be updated to work with flattened inline models + Assert.assertEquals(parameter.dataType, "PageQuery1"); Assert.assertEquals(imports.size(), 1); - Assert.assertEquals(imports.iterator().next(), "PageQuery"); + Assert.assertEquals(imports.iterator().next(), "PageQuery1"); } @Test public void mapParamImportInnerObject() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/mapArgs.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/mapArgs.yaml"); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -1142,7 +1143,7 @@ public void modelWithSuffixDoNotContainInheritedVars() { @Test public void arrayInnerReferencedSchemaMarkedAsModel_20() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/arrayRefBody.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/arrayRefBody.yaml"); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -1159,7 +1160,7 @@ public void arrayInnerReferencedSchemaMarkedAsModel_20() { @Test public void arrayInnerReferencedSchemaMarkedAsModel_30() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/arrayRefBody.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/arrayRefBody.yaml"); new InlineModelResolver().flatten(openAPI); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -1213,7 +1214,7 @@ public void convertApiNameWithSuffix() { public static class FromParameter { private CodegenParameter codegenParameter(String path) { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/fromParameter.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/fromParameter.yaml"); new InlineModelResolver().flatten(openAPI); final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); @@ -1341,7 +1342,7 @@ public void testCircularReferencesDetection() { @Test public void testUseOneOfInterfaces() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/composed-oneof.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/composed-oneof.yaml"); final DefaultCodegen cg = new DefaultCodegen(); cg.setUseOneOfInterfaces(true); cg.preprocessOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java index 46449c74a3ab..c6ee5c077d7d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java @@ -82,7 +82,7 @@ public void testNonStrictProcessPaths() throws Exception { @Test public void testRefModelValidationProperties(){ - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/refAliasedPrimitiveWithValidation.yml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/refAliasedPrimitiveWithValidation.yml"); ClientOptInput opts = new ClientOptInput(); opts.setOpenAPI(openAPI); DefaultCodegen config = new DefaultCodegen(); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ExampleGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ExampleGeneratorTest.java index 5d68214c0db1..661ddb2fb65d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ExampleGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ExampleGeneratorTest.java @@ -12,7 +12,7 @@ public class ExampleGeneratorTest { @Test public void generateFromResponseSchemaWithPrimitiveType() { - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/example_generator_test.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml"); new InlineModelResolver().flatten(openAPI); @@ -41,7 +41,7 @@ public void generateFromResponseSchemaWithPrimitiveType() { @Test public void generateFromResponseSchemaWithNoExample() { - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/example_generator_test.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml"); new InlineModelResolver().flatten(openAPI); @@ -67,7 +67,7 @@ public void generateFromResponseSchemaWithNoExample() { @Test public void generateFromResponseSchemaWithArrayOfModel() { - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/example_generator_test.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml"); new InlineModelResolver().flatten(openAPI); @@ -96,7 +96,7 @@ public void generateFromResponseSchemaWithArrayOfModel() { @Test public void generateFromResponseSchemaWithArrayOfPrimitiveTypes() { - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/example_generator_test.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml"); new InlineModelResolver().flatten(openAPI); @@ -125,7 +125,7 @@ public void generateFromResponseSchemaWithArrayOfPrimitiveTypes() { @Test public void generateFromResponseSchemaWithModel() { - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/example_generator_test.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml"); new InlineModelResolver().flatten(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java index 676d0fa922b0..e32a45252ede 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java @@ -313,7 +313,7 @@ public void resolveInlineRequestBodyWhenNoComponents() { assertNotNull(openAPI.getComponents()); assertNotNull(openAPI.getComponents().getRequestBodies()); } - + @Test public void resolveInlineArraySchemaWithTitle() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); @@ -329,7 +329,7 @@ public void resolveInlineArraySchemaWithTitle() { assertTrue(user.getProperties().get("street") instanceof StringSchema); assertTrue(user.getProperties().get("city") instanceof StringSchema); } - + @Test public void resolveInlineRequestBody() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java index 9f970a6597d8..077268f2408b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java @@ -28,6 +28,29 @@ public class TestUtils { + /** + * Helper method for parsing specs as a generator would be presented at runtime (inline models resolved, flattened). + * + * @param specFilePath The path to the specification file + * @return A processed OpenAPI document + */ + public static OpenAPI parseFlattenSpec(String specFilePath) { + OpenAPI openAPI = parseSpec(specFilePath); + InlineModelResolver inlineModelResolver = new InlineModelResolver(); + inlineModelResolver.flatten(openAPI); + return openAPI; + } + + /** + * Helper method for parsing specs into an intermediary OpenAPI structure for pre-processing. + * + * Use this method only for tests targeting processing helpers such as {@link org.openapitools.codegen.utils.ModelUtils} + * or {@link InlineModelResolver}. Using this for testing generators will mean you're not testing the OpenAPI document + * in a state the generator will be presented at runtime. + * + * @param specFilePath The path to the specification file + * @return A "raw" OpenAPI document + */ public static OpenAPI parseSpec(String specFilePath) { return new OpenAPIParser().readLocation(specFilePath, null, new ParseOptions()).getOpenAPI(); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java index a685a47e4286..dda37d669bab 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java @@ -29,7 +29,7 @@ public class AsciidocGeneratorTest { @Test public void testPingSpecTitle() throws Exception { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/ping.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml"); AsciidocDocumentationCodegen codeGen = new AsciidocDocumentationCodegen(); codeGen.preprocessOpenAPI(openAPI); @@ -61,7 +61,7 @@ public void testGenerateIndexAsciidocMarkupContent() throws Exception { output.mkdirs(); output.deleteOnExit(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/ping.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml"); CodegenConfig codegenConfig = new AsciidocDocumentationCodegen(); codegenConfig.setOutputDir(output.getAbsolutePath()); ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/bash/BashTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/bash/BashTest.java index f320818b3922..2e6e6586569b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/bash/BashTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/bash/BashTest.java @@ -34,7 +34,7 @@ public class BashTest { public void petstoreOperationTest() { final OpenAPI openAPI - = TestUtils.parseSpec("src/test/resources/2_0/petstore-bash.json"); + = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-bash.json"); final DefaultCodegen codegen = new BashClientCodegen(); codegen.setOpenAPI(openAPI); final Operation findPetsByStatusOperation @@ -63,7 +63,7 @@ public void petstoreOperationTest() { public void petstoreParameterExampleTest() { final OpenAPI openAPI - = TestUtils.parseSpec("src/test/resources/2_0/petstore-bash.json"); + = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-bash.json"); final DefaultCodegen codegen = new BashClientCodegen(); codegen.setOpenAPI(openAPI); final Operation addPetOperation diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharp/CsharpModelEnumTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharp/CsharpModelEnumTest.java index 4ca0398798be..77d81bd7f6b1 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharp/CsharpModelEnumTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharp/CsharpModelEnumTest.java @@ -99,7 +99,7 @@ public void useCustomEnumSuffixes() { codegen.setEnumNameSuffix("EnumName"); codegen.setEnumValueSuffix("EnumValue"); - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.setOpenAPI(openAPI); final Schema petSchema = openAPI.getComponents().getSchemas().get("Pet"); @@ -116,7 +116,7 @@ public void useCustomEnumSuffixes() { public void useDefaultEnumSuffixes() { final AspNetCoreServerCodegen codegen = new AspNetCoreServerCodegen(); - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.setOpenAPI(openAPI); final Schema petSchema = openAPI.getComponents().getSchemas().get("Pet"); @@ -135,7 +135,7 @@ public void useEmptyEnumSuffixes() { codegen.setEnumNameSuffix(""); codegen.setEnumValueSuffix(""); - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.setOpenAPI(openAPI); final Schema petSchema = openAPI.getComponents().getSchemas().get("Pet"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java index 32c987583902..66931fa5d500 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java @@ -309,7 +309,7 @@ public void testReservedWord() throws Exception { // datetime (or primitive type) not yet supported in HTTP request body @Test(description = "returns DateTime when using `--model-name-prefix`") public void dateTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/datePropertyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); final DefaultCodegen codegen = new DartClientCodegen(); codegen.setModelNamePrefix("foo"); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java index 7776cf9ccf5e..19cb56f510e7 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java @@ -397,7 +397,7 @@ public void testReservedWord() throws Exception { // datetime (or primitive type) not yet supported in HTTP request body @Test(description = "returns DateTime when using `--model-name-prefix`") public void dateTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/datePropertyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); final DefaultCodegen codegen = new DartDioClientCodegen(); codegen.setModelNamePrefix("foo"); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java index d64e3fd79f76..417cd43ccd32 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java @@ -60,7 +60,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { @Test(description = "test example value for body parameter") public void bodyParameterTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final GoClientCodegen codegen = new GoClientCodegen(); codegen.setOpenAPI(openAPI); final String path = "/fake"; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/html/StaticHtmlGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/html/StaticHtmlGeneratorTest.java index 3a68dea4275b..2f70262d7f68 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/html/StaticHtmlGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/html/StaticHtmlGeneratorTest.java @@ -48,7 +48,7 @@ public void testAdditionalPropertiesFalse() { @Test public void testSpecWithoutSchema() throws Exception { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/ping.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml"); final StaticHtmlGenerator codegen = new StaticHtmlGenerator(); codegen.preprocessOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java index 85b63e947557..e18dff76f813 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java @@ -66,7 +66,7 @@ public void toModelNameUsesPascalCase() throws Exception { @Test public void testPreprocessOpenAPI() throws Exception { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); codegen.preprocessOpenAPI(openAPI); @@ -77,7 +77,7 @@ public void testPreprocessOpenAPI() throws Exception { @Test public void testPreprocessOpenAPINumVersion() throws Exception { - final OpenAPI openAPIOtherNumVersion = TestUtils.parseSpec("src/test/resources/2_0/duplicateOperationIds.yaml"); + final OpenAPI openAPIOtherNumVersion = TestUtils.parseFlattenSpec("src/test/resources/2_0/duplicateOperationIds.yaml"); final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); codegen.preprocessOpenAPI(openAPIOtherNumVersion); @@ -461,7 +461,7 @@ public void getTypeDeclarationTest() { @Test public void processOptsBooleanTrueFromString() { final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "true"); codegen.preprocessOpenAPI(openAPI); Assert.assertTrue((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION)); @@ -470,7 +470,7 @@ public void processOptsBooleanTrueFromString() { @Test public void processOptsBooleanTrueFromBoolean() { final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, true); codegen.preprocessOpenAPI(openAPI); Assert.assertTrue((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION)); @@ -479,7 +479,7 @@ public void processOptsBooleanTrueFromBoolean() { @Test public void processOptsBooleanFalseFromString() { final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "false"); codegen.preprocessOpenAPI(openAPI); Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION)); @@ -488,7 +488,7 @@ public void processOptsBooleanFalseFromString() { @Test public void processOptsBooleanFalseFromBoolean() { final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, false); codegen.preprocessOpenAPI(openAPI); Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION)); @@ -497,7 +497,7 @@ public void processOptsBooleanFalseFromBoolean() { @Test public void processOptsBooleanFalseFromGarbage() { final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "blibb"); codegen.preprocessOpenAPI(openAPI); Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION)); @@ -506,7 +506,7 @@ public void processOptsBooleanFalseFromGarbage() { @Test public void processOptsBooleanFalseFromNumeric() { final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, 42L); codegen.preprocessOpenAPI(openAPI); Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION)); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index cff4cbc696ed..070748e97b51 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -207,7 +207,7 @@ public void testPackageNamesSetInvokerDerivedFromModel() { @Test public void testGetSchemaTypeWithComposedSchemaWithAllOf() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/composed-allof.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/composed-allof.yaml"); final JavaClientCodegen codegen = new JavaClientCodegen(); Operation operation = openAPI.getPaths().get("/ping").getPost(); @@ -433,7 +433,7 @@ public void testJdkHttpClient() throws Exception { @Test public void testReferencedHeader() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue855.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue855.yaml"); JavaClientCodegen codegen = new JavaClientCodegen(); codegen.setOpenAPI(openAPI); @@ -448,7 +448,7 @@ public void testReferencedHeader() { @Test public void testAuthorizationScopeValues_Issue392() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue392.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue392.yaml"); final DefaultGenerator defaultGenerator = new DefaultGenerator(); @@ -476,7 +476,7 @@ public void testAuthorizationScopeValues_Issue392() { @Test public void testAuthorizationsHasMoreWhenFiltered() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue4584.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue4584.yaml"); final DefaultGenerator defaultGenerator = new DefaultGenerator(); @@ -496,7 +496,7 @@ public void testAuthorizationsHasMoreWhenFiltered() { @Test public void testFreeFormObjects() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue796.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue796.yaml"); JavaClientCodegen codegen = new JavaClientCodegen(); Schema test1 = openAPI.getComponents().getSchemas().get("MapTest1"); @@ -578,7 +578,7 @@ public void testImportMapping() throws IOException { @Test public void testBearerAuth() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/pingBearerAuth.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/pingBearerAuth.yaml"); JavaClientCodegen codegen = new JavaClientCodegen(); List security = codegen.fromSecurity(openAPI.getComponents().getSecuritySchemes()); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java index 7d6d9bc8eab6..e7226d707734 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java @@ -167,7 +167,7 @@ public void overrideEnumTest() { @Test public void testEnumTestSchema() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml"); JavaClientCodegen codegen = new JavaClientCodegen(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java index e8a461b705ac..1d01d7d2d6e9 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java @@ -1275,7 +1275,7 @@ public void generateEmpty() throws Exception { config.setHideGenerationTimestamp(true); config.setOutputDir(output.getAbsolutePath()); - final OpenAPI openAPI = TestUtils.parseSpec(inputSpec); + final OpenAPI openAPI = TestUtils.parseFlattenSpec(inputSpec); final ClientOptInput opts = new ClientOptInput(); opts.setConfig(config); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java index 9fda8ba592d2..f05fcec1cb18 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java @@ -92,7 +92,7 @@ public void testAddOperationToGroupUseTagsFalse() throws Exception { File output = Files.createTempDirectory("test").toFile(); output.deleteOnExit(); - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/tags.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/tags.yaml"); ((JavaJerseyServerCodegen) codegen).setUseTags(false); codegen.setOutputDir(output.getAbsolutePath()); @@ -169,7 +169,7 @@ public void testAddOperationToGroupUseTagsTrue() throws Exception { File output = Files.createTempDirectory("test").toFile(); output.deleteOnExit(); - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/tags.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/tags.yaml"); ((JavaJerseyServerCodegen) codegen).setUseTags(true); codegen.setOutputDir(output.getAbsolutePath()); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index a8f75d7cbe3c..8843e4cbb5dc 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -485,7 +485,7 @@ public void testDefaultValuesFixed() { // we had an issue where int64, float, and double values were having single character string suffixes // included in their defaultValues // This test verifies that those characters are no longer present - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/issue1226.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/issue1226.yaml"); final SpringCodegen codegen = new SpringCodegen(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java index 6f5959c62bfd..22c31066baf6 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java @@ -66,7 +66,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { @Test(description = "test defaultValueWithParam for model's properties") public void bodyParameterTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore.yaml"); final JavascriptClientCodegen codegen = new JavascriptClientCodegen(); final Schema pet = openAPI.getComponents().getSchemas().get("Pet"); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java index 3a54bc8994aa..58727aa38032 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java @@ -16,7 +16,7 @@ @SuppressWarnings("rawtypes") public class KotlinReservedWordsTest { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/kotlin/reserved_words.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/kotlin/reserved_words.yaml"); @DataProvider(name = "reservedWords") static Object[][] reservedWords() { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java index 9a4f3357feeb..e2b87d84d3f1 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java @@ -28,7 +28,7 @@ public class KotlinSpringServerCodegenTest { public void embeddedEnumArrayTest() throws Exception { String baseModelPackage = "zz"; File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); //may be move to /build - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue______kotlinArrayEnumEmbedded.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue______kotlinArrayEnumEmbedded.yaml"); KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, baseModelPackage + ".yyyy.model.xxxx"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java index b99756d27762..d2f3127d3a68 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java @@ -302,7 +302,7 @@ public void mapModelTest() { @Test(description = "test udid") public void udidAndPasswordDataModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new ObjcClientCodegen(); codegen.setOpenAPI(openAPI); final Schema definition = openAPI.getComponents().getSchemas().get("format_test"); @@ -317,7 +317,7 @@ public void udidAndPasswordDataModelTest() { @Test(description = "test mixedProperties") public void mixedPropertiesDataModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new ObjcClientCodegen(); codegen.setOpenAPI(openAPI); final Schema definition = openAPI.getComponents().getSchemas().get("MixedPropertiesAndAdditionalPropertiesClass"); @@ -329,7 +329,7 @@ public void mixedPropertiesDataModelTest() { @Test(description = "test isArrayModel") public void isArrayModelModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new ObjcClientCodegen(); final Schema definition = openAPI.getComponents().getSchemas().get("AnimalFarm"); codegen.setOpenAPI(openAPI); @@ -342,7 +342,7 @@ public void isArrayModelModelTest() { @Test(description = "test binary data") public void binaryDataModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/binaryDataTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/binaryDataTest.json"); final DefaultCodegen codegen = new ObjcClientCodegen(); final String path = "/tests/binaryResponse"; final Operation p = openAPI.getPaths().get(path).getPost(); @@ -357,7 +357,7 @@ public void binaryDataModelTest() { @Test(description = "create proper imports per #316") public void issue316Test() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/postBodyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/postBodyTest.json"); final DefaultCodegen codegen = new ObjcClientCodegen(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java index e8a3204d1d7f..7f646b1278b6 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java @@ -59,7 +59,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { @Test public void testIssue677() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue677.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue677.yaml"); final PerlClientCodegen codegen = new PerlClientCodegen(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java index 56886d76716c..989e0ca84b0f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java @@ -302,7 +302,7 @@ public void modelNameTest(String name, String expectedName) { @Test(description = "test enum array model") public void enumArrayModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new PhpClientCodegen(); codegen.setOpenAPI(openAPI); final Map schemas = openAPI.getComponents().getSchemas(); @@ -337,7 +337,7 @@ public void enumArrayModelTest() { @Test(description = "test enum model for values (numeric, string, etc)") public void enumMdoelValueTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new PhpClientCodegen(); codegen.setOpenAPI(openAPI); final Schema definition = openAPI.getComponents().getSchemas().get("Enum_Test"); @@ -376,7 +376,7 @@ public void testReservedWord() throws Exception { // datetime (or primitive type) not yet supported in HTTP request body @Test(description = "returns DateTime when using `--model-name-prefix`") public void dateTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/datePropertyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); final DefaultCodegen codegen = new PhpClientCodegen(); codegen.setModelNamePrefix("foo"); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java index 29bf03c5937e..565e6848f64b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java @@ -63,7 +63,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { @Test(description = "test enum null/nullable patterns") public void testEnumNull() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue_1997.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_1997.yaml"); StringSchema prop = (StringSchema) openAPI.getComponents().getSchemas().get("Type").getProperties().get("prop"); ArrayList expected = new ArrayList<>(Arrays.asList("A", "B", "C")); @@ -73,7 +73,7 @@ public void testEnumNull() { @Test(description = "test regex patterns") public void testRegularExpressionOpenAPISchemaVersion3() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue_1517.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_1517.yaml"); final PythonClientCodegen codegen = new PythonClientCodegen(); codegen.setOpenAPI(openAPI); final String path = "/ping"; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java index 71cfa40a47ef..c040b61b33ec 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java @@ -31,7 +31,7 @@ public class PythonClientExperimentalTest { @Test(description = "convert a python model with dots") public void modelTest() { - final OpenAPI openAPI= TestUtils.parseSpec("src/test/resources/2_0/v1beta3.json"); + final OpenAPI openAPI= TestUtils.parseFlattenSpec("src/test/resources/2_0/v1beta3.json"); final DefaultCodegen codegen = new PythonClientExperimentalCodegen(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java index 1e8fd72541de..b9cfe3e0bad0 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java @@ -32,7 +32,7 @@ public class PythonTest { @Test(description = "convert a python model with dots") public void modelTest() { - final OpenAPI openAPI= TestUtils.parseSpec("src/test/resources/2_0/v1beta3.json"); + final OpenAPI openAPI= TestUtils.parseFlattenSpec("src/test/resources/2_0/v1beta3.json"); final DefaultCodegen codegen = new PythonClientCodegen(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java index e51b20cdbda9..7191f6e5ee0c 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java @@ -29,9 +29,11 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import java.util.TreeSet; import static org.testng.Assert.assertTrue; @@ -49,7 +51,7 @@ public void testGenerateRubyClientWithHtmlEntity() throws Exception { output.mkdirs(); output.deleteOnExit(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/pathWithHtmlEntity.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/pathWithHtmlEntity.yaml"); CodegenConfig codegenConfig = new RubyClientCodegen(); codegenConfig.setOutputDir(output.getAbsolutePath()); @@ -113,7 +115,7 @@ public void testBooleanDefaultValue() throws Exception { output.mkdirs(); output.deleteOnExit(); - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/npe1.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/npe1.yaml"); CodegenConfig codegenConfig = new RubyClientCodegen(); codegenConfig.setOutputDir(output.getAbsolutePath()); @@ -136,7 +138,7 @@ public void testBooleanDefaultValue() throws Exception { @Test(description = "verify enum parameters (query, form, header)") public void enumParameterTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new RubyClientCodegen(); codegen.setOpenAPI(openAPI); final String path = "/fake"; @@ -151,7 +153,7 @@ public void enumParameterTest() { @Test(description = "test example value for body parameter") public void bodyParameterTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); codegen.setOpenAPI(openAPI); @@ -166,7 +168,7 @@ public void bodyParameterTest() { @Test(description = "test nullable for properties") public void nullablePropertyTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); final String path = "/pet"; @@ -195,7 +197,7 @@ public void nullablePropertyTest() { @Test(description = "test properties without nullable") public void propertiesWithoutNullableTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); final String path = "/pet"; @@ -281,7 +283,7 @@ public void propertiesWithoutNullableTest() { @Test(description = "test nullable for parameters (OAS3)") public void nullableParameterOAS3Test() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); codegen.setOpenAPI(openAPI); @@ -303,7 +305,7 @@ public void nullableParameterOAS3Test() { @Test(description = "test nullable for parameters (OAS2)") public void nullableParameterOAS2Test() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-nullable.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-nullable.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); codegen.setOpenAPI(openAPI); @@ -327,7 +329,7 @@ public void nullableParameterOAS2Test() { @Test(description = "test anyOf (OAS3)") public void anyOfTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/anyOf.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/anyOf.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -343,7 +345,7 @@ public void anyOfTest() { @Test(description = "test oneOf (OAS3)") public void oneOfTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/oneOf.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/oneOf.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -359,7 +361,7 @@ public void oneOfTest() { @Test(description = "test allOf (OAS3)") public void allOfTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOf.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -379,7 +381,7 @@ public void allOfTest() { @Test(description = "test allOf with only allOf and duplicated properties(OAS3)") public void allOfDuplicatedPropertiesTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOfDuplicatedProperties.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOfDuplicatedProperties.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -408,7 +410,7 @@ public void allOfDuplicatedPropertiesTest() { @Test(description = "test allOf with discriminator and duplicated properties(OAS3) for Child model") public void allOfMappingDuplicatedPropertiesTestForChild() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -418,52 +420,50 @@ public void allOfMappingDuplicatedPropertiesTestForChild() { Assert.assertNotNull(child); // to test allVars (without parent's properties) - Assert.assertEquals(child.getAllVars().size(), 7); - - CodegenProperty cp0 = child.getAllVars().get(0); - Assert.assertEquals(cp0.name, "_type"); - - CodegenProperty cp1 = child.getAllVars().get(1); - Assert.assertEquals(cp1.name, "last_name"); - - CodegenProperty cp2 = child.getAllVars().get(2); - Assert.assertEquals(cp2.name, "first_name"); - - CodegenProperty cp3 = child.getAllVars().get(3); - Assert.assertEquals(cp3.name, "duplicated_optional"); - - CodegenProperty cp4 = child.getAllVars().get(4); - Assert.assertEquals(cp4.name, "duplicated_required"); - - CodegenProperty cp5 = child.getAllVars().get(5); - Assert.assertEquals(cp5.name, "person_required"); - - CodegenProperty cp6 = child.getAllVars().get(6); - Assert.assertEquals(cp6.name, "age"); + List allVars = + child.getAllVars().stream() + .map(CodegenProperty::getName) + .collect(Collectors.toList()); + List allVarsExpected = Arrays.asList( + "age", + "first_name", + "_type", + "last_name", + "duplicated_optional", + "duplicated_required", + "person_required" + ); + Assert.assertEquals(allVars.size(), allVarsExpected.size()); + Assert.assertTrue(allVars.containsAll(allVarsExpected)); // to test vars (without parent's properties) - Assert.assertEquals(child.getVars().size(), 2); - - cp0 = child.getVars().get(0); - Assert.assertEquals(cp0.name, "age"); - - cp1 = child.getVars().get(1); - Assert.assertEquals(cp1.name, "first_name"); + List vars = + child.getVars().stream() + .map(CodegenProperty::getName) + .collect(Collectors.toList()); + List varsExpected = Arrays.asList( + "age", + "first_name" + ); + Assert.assertEquals(vars.size(), varsExpected.size()); + Assert.assertTrue(vars.containsAll(varsExpected)); // to test requiredVars - Assert.assertEquals(child.getRequiredVars().size(), 2); - - cp0 = child.getRequiredVars().get(0); - Assert.assertEquals(cp0.name, "duplicated_required"); - - cp1 = child.getRequiredVars().get(1); - Assert.assertEquals(cp1.name, "person_required"); - + List requiredVars = + child.getRequiredVars().stream() + .map(CodegenProperty::getName) + .collect(Collectors.toList()); + List requiredVarsExpected = Arrays.asList( + "duplicated_required", + "person_required" + ); + Assert.assertEquals(vars.size(), requiredVarsExpected.size()); + Assert.assertTrue(requiredVars.containsAll(requiredVarsExpected)); } @Test(description = "test allOf with discriminator and duplicated properties(OAS3) for Adult model") public void allOfMappingDuplicatedPropertiesTestForAdult() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -523,7 +523,7 @@ public void allOfMappingDuplicatedPropertiesTestForAdult() { @Test(description = "test allOf composition") public void allOfCompositionTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOf_composition.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf_composition.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); @@ -591,7 +591,7 @@ public void allOfCompositionTest() { @Test(description = "test example string imported from x-example parameterr (OAS2)") public void exampleStringFromExampleParameterOAS2Test() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-nullable.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-nullable.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); codegen.setOpenAPI(openAPI); @@ -606,7 +606,7 @@ public void exampleStringFromExampleParameterOAS2Test() { @Test(description = "test example string imported from example in schema (OAS3)") public void exampleStringFromXExampleParameterOAS3Test() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore_oas3_test.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setModuleName("OnlinePetstore"); codegen.setOpenAPI(openAPI); @@ -627,7 +627,7 @@ public void exampleStringFromXExampleParameterOAS3Test() { */ @Test(description = "test regex patterns") public void exampleRegexParameterValidationOAS3Test() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/test_regex.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/test_regex.yaml"); final RubyClientCodegen codegen = new RubyClientCodegen(); codegen.setOpenAPI(openAPI); final String path = "/ping"; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift3/Swift3CodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift3/Swift3CodegenTest.java index 078e19c93b8a..1b5b2fa272c9 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift3/Swift3CodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift3/Swift3CodegenTest.java @@ -89,7 +89,7 @@ public void testStartingWithNumber() throws Exception { @Test(description = "returns NSData when response format is binary", enabled = false) public void binaryDataTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/binaryDataTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/binaryDataTest.json"); final DefaultCodegen codegen = new Swift3Codegen(); codegen.setOpenAPI(openAPI); final String path = "/tests/binaryResponse"; @@ -104,7 +104,7 @@ public void binaryDataTest() { @Test(description = "returns ISOFullDate when response format is date", enabled = false) public void dateTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/datePropertyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); final DefaultCodegen codegen = new Swift3Codegen(); codegen.setOpenAPI(openAPI); final String path = "/tests/dateResponse"; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift4/Swift4CodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift4/Swift4CodegenTest.java index 8a4cd3b91fde..aeef2b73edbc 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift4/Swift4CodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift4/Swift4CodegenTest.java @@ -92,7 +92,7 @@ public void testStartingWithNumber() throws Exception { public void binaryDataTest() { // TODO update json file - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/binaryDataTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/binaryDataTest.json"); final DefaultCodegen codegen = new Swift4Codegen(); codegen.setOpenAPI(openAPI); final String path = "/tests/binaryResponse"; @@ -107,7 +107,7 @@ public void binaryDataTest() { @Test(description = "returns Date when response format is date", enabled = true) public void dateTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/datePropertyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); final DefaultCodegen codegen = new Swift4Codegen(); codegen.setOpenAPI(openAPI); final String path = "/tests/dateResponse"; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java index 81cab7cdc9bc..22ca23059cd0 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java @@ -92,7 +92,7 @@ public void testStartingWithNumber() throws Exception { public void binaryDataTest() { // TODO update json file - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/binaryDataTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/binaryDataTest.json"); final DefaultCodegen codegen = new Swift5ClientCodegen(); codegen.setOpenAPI(openAPI); final String path = "/tests/binaryResponse"; @@ -107,7 +107,7 @@ public void binaryDataTest() { @Test(description = "returns Date when response format is date", enabled = true) public void dateTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/datePropertyTest.json"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); final DefaultCodegen codegen = new Swift5ClientCodegen(); codegen.setOpenAPI(openAPI); final String path = "/tests/dateResponse"; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java index 1cd429fbeb9b..1317a43af639 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java @@ -225,7 +225,7 @@ public void mapModelTest() { @Test(description = "test enum array model") public void enumArrayMdoelTest() { // TODO: update yaml file. - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new TypeScriptFetchClientCodegen(); codegen.processOpts(); codegen.setOpenAPI(openAPI); @@ -263,7 +263,7 @@ public void enumArrayMdoelTest() { @Test(description = "test enum model for values (numeric, string, etc)") public void enumMdoelValueTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"); final DefaultCodegen codegen = new TypeScriptFetchClientCodegen(); codegen.processOpts(); codegen.setOpenAPI(openAPI); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java index 1f84c738b21e..e2f3b7c40d56 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java @@ -258,7 +258,7 @@ public void arrayModelAdditionalPropertiesComplexTest() { @Test(description = "prepend imports with ./ by default") public void defaultFromModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); final DefaultCodegen codegen = new TypeScriptNodeClientCodegen(); codegen.setOpenAPI(openAPI); final Schema categorySchema = openAPI.getComponents().getSchemas().get("ApiResponse"); @@ -270,7 +270,7 @@ public void defaultFromModelTest() { @Test(description = "use mapped imports for type") public void mappedFromModelTest() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); final DefaultCodegen codegen = new TypeScriptNodeClientCodegen(); final String mappedName = "@namespace/dir/response"; codegen.importMapping().put("ApiResponse", mappedName); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java index b51dc54a3ef2..5b0114d96ac4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java @@ -26,86 +26,84 @@ import org.testng.Assert; import org.testng.annotations.Test; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ModelUtilsTest { @Test public void testGetAllUsedSchemas() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/unusedSchemas.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/unusedSchemas.yaml"); List allUsedSchemas = ModelUtils.getAllUsedSchemas(openAPI); - Assert.assertEquals(allUsedSchemas.size(), 41); - - Assert.assertTrue(allUsedSchemas.contains("SomeObjShared"), "contains 'SomeObjShared'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj1"), "contains 'UnusedObj1'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj2"), "contains 'SomeObj2'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj3"), "contains 'SomeObj3'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj6"), "contains 'SomeObj6'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj7"), "contains 'SomeObj7'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj8"), "contains 'SomeObj8'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj9A"), "contains 'SomeObj9A'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj9B"), "contains 'SomeObj9B'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj10A"), "contains 'SomeObj10A'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj10B"), "contains 'SomeObj10B'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj11"), "contains 'SomeObj11'"); - Assert.assertTrue(allUsedSchemas.contains("SomeArrayObj12"), "contains 'SomeArrayObj12'"); - Assert.assertTrue(allUsedSchemas.contains("ArrayItem12"), "contains 'ArrayItem12'"); - Assert.assertTrue(allUsedSchemas.contains("SomeArrayObj13"), "contains 'SomeArrayObj13'"); - Assert.assertTrue(allUsedSchemas.contains("ArrayItem13"), "contains 'ArrayItem13'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj14"), "contains 'SomeObj14'"); - Assert.assertTrue(allUsedSchemas.contains("PropertyObj14"), "contains 'PropertyObj14'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj15"), "contains 'SomeObj15'"); - Assert.assertTrue(allUsedSchemas.contains("SomeMapObj16"), "contains 'SomeMapObj16'"); - Assert.assertTrue(allUsedSchemas.contains("MapItem16"), "contains 'MapItem16'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj17"), "contains 'SomeObj17'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj18"), "contains 'SomeObj18'"); - Assert.assertTrue(allUsedSchemas.contains("Common18"), "contains 'Common18'"); - Assert.assertTrue(allUsedSchemas.contains("Obj19ByAge"), "contains 'Obj19ByAge'"); - Assert.assertTrue(allUsedSchemas.contains("Obj19ByType"), "contains 'Obj19ByType'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj20"), "contains 'SomeObj20'"); - Assert.assertTrue(allUsedSchemas.contains("OtherObj20"), "contains 'OtherObj20'"); - Assert.assertTrue(allUsedSchemas.contains("PingDataInput21"), "contains 'PingDataInput21'"); - Assert.assertTrue(allUsedSchemas.contains("PingDataOutput21"), "contains 'PingDataOutput21'"); - Assert.assertTrue(allUsedSchemas.contains("SInput22"), "contains 'SInput22'"); - Assert.assertTrue(allUsedSchemas.contains("SOutput22"), "contains 'SInput22'"); - Assert.assertTrue(allUsedSchemas.contains("SomeHeader23"), "contains 'SomeHeader23'"); - Assert.assertTrue(allUsedSchemas.contains("SomeHeader24"), "contains 'SomeHeader24'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj25"), "contains 'SomeObj25'"); - Assert.assertTrue(allUsedSchemas.contains("SomeObj26"), "contains 'SomeObj26'"); - Assert.assertTrue(allUsedSchemas.contains("Param27"), "contains 'Param27'"); - Assert.assertTrue(allUsedSchemas.contains("Param28"), "contains 'Param28'"); - Assert.assertTrue(allUsedSchemas.contains("Parent30"), "contains 'Parent30'"); - Assert.assertTrue(allUsedSchemas.contains("AChild30"), "contains 'AChild30'"); - Assert.assertTrue(allUsedSchemas.contains("BChild30"), "contains 'BChild30'"); + List expectedallUsedSchemas = Arrays.asList( + "SomeObj1", + "SomeObj2", + "SomeObj3", + "SomeObjShared", + "SomeObj6", + "SomeObj7", + "SomeObj8", + "SomeObj9A", + "SomeObj9B", + "SomeObj10A", + "SomeObj10B", + "SomeObj11", + "SomeArrayObj12", + "ArrayItem12", + "SomeArrayObj13", + "ArrayItem13", + "SomeObj14", + "PropertyObj14", + "SomeObj15", + "SomeMapObj16", + "MapItem16", + "SomeObj17", + "SomeObj18", + "Common18", + "SomeObj18_allOf", + "Obj19ByAge", + "Obj19ByType", + "SomeObj20", + "OtherObj20", + "PingDataInput21", + "PingDataOutput21", + "SInput22", + "SOutput22", + "SomeHeader23", + "SomeHeader24", + "SomeObj25", + "SomeObj26", + "Param27", + "Param28", + "Parent30", + "AChild30", + "BChild30" + ); + Assert.assertEquals(allUsedSchemas.size(), expectedallUsedSchemas.size()); + Assert.assertTrue(allUsedSchemas.containsAll(expectedallUsedSchemas)); } @Test public void testGetUnusedSchemas() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/unusedSchemas.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/unusedSchemas.yaml"); List unusedSchemas = ModelUtils.getUnusedSchemas(openAPI); - Assert.assertEquals(unusedSchemas.size(), 7); - //UnusedObj1 is not used at all: - Assert.assertTrue(unusedSchemas.contains("UnusedObj1"), "contains 'UnusedObj1'"); - //UnusedObj2 is used in a request body that is not used. - Assert.assertTrue(unusedSchemas.contains("UnusedObj2"), "contains 'UnusedObj2'"); - //UnusedObj3 is used in a response that is not used. - Assert.assertTrue(unusedSchemas.contains("UnusedObj3"), "contains 'UnusedObj3'"); - //UnusedObj4 is used in a parameter that is not used. - Assert.assertTrue(unusedSchemas.contains("UnusedObj4"), "contains 'UnusedObj4'"); - //Parent29 is not used at all (only unused children AChild29 and BChild29 are referencing him): - Assert.assertTrue(unusedSchemas.contains("Parent29"), "contains 'Parent29'"); - //AChild29 is not used at all: - Assert.assertTrue(unusedSchemas.contains("AChild29"), "contains 'AChild29'"); - //BChild29 is not used at all: - Assert.assertTrue(unusedSchemas.contains("BChild29"), "contains 'BChild29'"); + List expectedUnusedSchemas = Arrays.asList( + "UnusedObj1", + "UnusedObj2", + "UnusedObj3", + "UnusedObj4", + "Parent29", + "AChild29", + "BChild29", + "AChild29_allOf", + "BChild29_allOf" + ); + Assert.assertEquals(unusedSchemas.size(), expectedUnusedSchemas.size()); + Assert.assertTrue(unusedSchemas.containsAll(expectedUnusedSchemas)); } @Test public void testSchemasUsedOnlyInFormParam() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/unusedSchemas.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/unusedSchemas.yaml"); List unusedSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI); Assert.assertEquals(unusedSchemas.size(), 3); //SomeObj2 is only used in an 'application/x-www-form-urlencoded' request @@ -118,14 +116,14 @@ public void testSchemasUsedOnlyInFormParam() { @Test public void testNoComponentsSection() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/ping.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml"); List unusedSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI); Assert.assertEquals(unusedSchemas.size(), 0); } @Test public void testGlobalProducesConsumes() { - final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/globalProducesConsumesTest.yaml"); + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/globalProducesConsumesTest.yaml"); List unusedSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI); Assert.assertEquals(unusedSchemas.size(), 0); } @@ -272,4 +270,4 @@ public void testIsSetFailsForNullSchema() { ArraySchema as = null; Assert.assertFalse(ModelUtils.isSet(as)); } -} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/validations/oas/OpenApiSchemaTypeTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/validations/oas/OpenApiSchemaTypeTest.java index ac8e207fb62e..cc7dfe2fc513 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/validations/oas/OpenApiSchemaTypeTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/validations/oas/OpenApiSchemaTypeTest.java @@ -37,7 +37,7 @@ public void testOas30DocumentWithNullType(final OpenAPI openAPI, boolean matches @DataProvider(name = "oas31RecommendationExpectations") public Object[][] oas31RecommendationExpectations() { return new Object[][]{ - {TestUtils.parseSpec("src/test/resources/3_1/null-types.yaml"), true} + {TestUtils.parseFlattenSpec("src/test/resources/3_1/null-types.yaml"), true} }; } } \ No newline at end of file diff --git a/samples/client/petstore/python-experimental/docs/Child.md b/samples/client/petstore/python-experimental/docs/Child.md index bc3c7f3922d3..f208f06a0593 100644 --- a/samples/client/petstore/python-experimental/docs/Child.md +++ b/samples/client/petstore/python-experimental/docs/Child.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**inter_net** | **bool** | | [optional] **radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] -**inter_net** | **bool** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Parent.md b/samples/client/petstore/python-experimental/docs/Parent.md index 2437d3c81ac9..48d2dc6c78f2 100644 --- a/samples/client/petstore/python-experimental/docs/Parent.md +++ b/samples/client/petstore/python-experimental/docs/Parent.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] +**radio_waves** | **bool** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child.py b/samples/client/petstore/python-experimental/petstore_api/models/child.py index 501c22427916..3d3b71839347 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child.py @@ -84,9 +84,9 @@ def openapi_types(): and the value is attribute type. """ return { + 'inter_net': (bool,), # noqa: E501 'radio_waves': (bool,), # noqa: E501 'tele_vision': (bool,), # noqa: E501 - 'inter_net': (bool,), # noqa: E501 } @staticmethod @@ -94,9 +94,9 @@ def discriminator(): return None attribute_map = { + 'inter_net': 'interNet', # noqa: E501 'radio_waves': 'radioWaves', # noqa: E501 'tele_vision': 'teleVision', # noqa: E501 - 'inter_net': 'interNet', # noqa: E501 } required_properties = set([ @@ -127,9 +127,9 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done. + inter_net (bool): [optional] # noqa: E501 radio_waves (bool): [optional] # noqa: E501 tele_vision (bool): [optional] # noqa: E501 - inter_net (bool): [optional] # noqa: E501 """ self._data_store = {} diff --git a/samples/client/petstore/python-experimental/petstore_api/models/parent.py b/samples/client/petstore/python-experimental/petstore_api/models/parent.py index f62abd94ceed..443b134d1cf3 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/parent.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/parent.py @@ -84,8 +84,8 @@ def openapi_types(): and the value is attribute type. """ return { - 'radio_waves': (bool,), # noqa: E501 'tele_vision': (bool,), # noqa: E501 + 'radio_waves': (bool,), # noqa: E501 } @staticmethod @@ -93,8 +93,8 @@ def discriminator(): return None attribute_map = { - 'radio_waves': 'radioWaves', # noqa: E501 'tele_vision': 'teleVision', # noqa: E501 + 'radio_waves': 'radioWaves', # noqa: E501 } required_properties = set([ @@ -125,8 +125,8 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done. - radio_waves (bool): [optional] # noqa: E501 tele_vision (bool): [optional] # noqa: E501 + radio_waves (bool): [optional] # noqa: E501 """ self._data_store = {}