Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openapi, openapi-yaml] - option not to flatten resolved spec, added … #9818

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,84 @@ public void testGeneratorServiceJavaClient2() {
Assert.assertFalse(files.isEmpty());
}

@Test(description = "test generator service resolved spec (openapi, openapi-yaml")
public void testGeneratorService_ResolvedSpec() throws IOException {

String path = getTmpFolder().getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.DOCUMENTATION)
.lang("openapi")
.spec(loadSpecAsNode("3_0_0/flattentest.yaml", true, false))
.options(
new Options()
.outputDir(path)
.addAdditionalProperty("flattenSpec", false)
);

new GeneratorService().generationRequest(request).generate();
String spec = FileUtils.readFileToString(new File(path + File.separator + "openapi.json"));
Assert.assertFalse(spec.contains("#/components/schemas/inline_response_200"));
Assert.assertFalse(spec.contains("#/components/schemas/body"));

path = getTmpFolder().getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.DOCUMENTATION)
.lang("openapi-yaml")
.spec(loadSpecAsNode("3_0_0/flattentest.yaml", true, false))
.options(
new Options()
.outputDir(path)
.addAdditionalProperty("flattenSpec", "false")
);


new GeneratorService().generationRequest(request).generate();
spec = FileUtils.readFileToString(new File(path + File.separator + "openapi.yaml"));
Assert.assertFalse(spec.contains("#/components/schemas/inline_response_200"));
Assert.assertFalse(spec.contains("#/components/schemas/body"));


path = getTmpFolder().getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.DOCUMENTATION)
.lang("openapi")
.spec(loadSpecAsNode("3_0_0/flattentest.yaml", true, false))
.options(
new Options()
.outputDir(path)
);

new GeneratorService().generationRequest(request).generate();
spec = FileUtils.readFileToString(new File(path + File.separator + "openapi.json"));
Assert.assertTrue(spec.contains("#/components/schemas/inline_response_200"));
Assert.assertTrue(spec.contains("#/components/schemas/body"));


path = getTmpFolder().getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.DOCUMENTATION)
.lang("openapi-yaml")
.spec(loadSpecAsNode("3_0_0/flattentest.yaml", true, false))
.options(
new Options()
.outputDir(path)
);

new GeneratorService().generationRequest(request).generate();
spec = FileUtils.readFileToString(new File(path + File.separator + "openapi.yaml"));
Assert.assertTrue(spec.contains("#/components/schemas/inline_response_200"));
Assert.assertTrue(spec.contains("#/components/schemas/body"));

}

protected static File getTmpFolder() {
try {
File outputFolder = File.createTempFile("codegentest-", "-tmp");
Expand Down
88 changes: 88 additions & 0 deletions modules/swagger-codegen/src/test/resources/3_0_0/flattentest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
openapi: 3.0.1
info:
version: "v2.0"
title: Test
paths:
/product:
get:
operationId: getProduct
summary: Gets a Product by ID.
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Product'
put:
operationId: updateProduct
summary: Updates a Product by ID.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Product'
responses:
'201':
description: Created
/productflatten:
get:
operationId: getProduct
summary: Gets a Product by ID.
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
name:
type: object
additionalProperties:
type: string
active:
type: boolean
example: true
foo:
type: object
additionalProperties: true
put:
operationId: updateProduct
summary: Updates a Product by ID.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: object
additionalProperties:
type: string
active:
type: boolean
example: true
foo:
type: object
additionalProperties: true
responses:
'201':
description: Created
components:
schemas:
Product:
type: object
properties:
name:
type: object
additionalProperties:
type: string
active:
type: boolean
example: true
foo:
type: object
additionalProperties: true