-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python-fastapi] return 500 if not implemented, added some unittests (#…
…19196) * [python-fastapi] Added some tests for FastAPI generator 1. Checks the generation of the implementation package. 2. Checks if the endpoints with and without descriptions generate correct output. Signed-off-by: Nikita Vakula <[email protected]> * [python-fastapi] Raise 500 if there is no implementation Signed-off-by: Nikita Vakula <[email protected]> --------- Signed-off-by: Nikita Vakula <[email protected]>
- Loading branch information
1 parent
f44bc30
commit e542b06
Showing
7 changed files
with
141 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
...api-generator/src/test/java/org/openapitools/codegen/python/PythonFastapiCodegenTest.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,56 @@ | ||
package org.openapitools.codegen.python; | ||
|
||
import org.openapitools.codegen.DefaultGenerator; | ||
import org.openapitools.codegen.TestUtils; | ||
import org.openapitools.codegen.config.CodegenConfigurator; | ||
import org.testng.annotations.Test; | ||
import org.openapitools.codegen.CodegenConstants; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
public class PythonFastapiCodegenTest { | ||
@Test | ||
public void testAdditionalPropertiesPutForConfigValues() throws Exception { | ||
File output = Files.createTempDirectory("test").toFile(); | ||
output.deleteOnExit(); | ||
|
||
final String IMPL_PKG = "impl_package"; | ||
final CodegenConfigurator configurator = new CodegenConfigurator() | ||
.setGeneratorName("python-fastapi") | ||
.setPackageName("nodesc") | ||
.setOutputDir(output.getAbsolutePath().replace("\\", "/")) | ||
.setInputSpec("src/test/resources/3_1/nodesc.yaml") | ||
.addAdditionalProperty(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, IMPL_PKG); | ||
|
||
DefaultGenerator generator = new DefaultGenerator(); | ||
List<File> files = generator.opts(configurator.toClientOptInput()).generate(); | ||
files.forEach(File::deleteOnExit); | ||
|
||
TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "/src", IMPL_PKG, "__init__.py")); | ||
} | ||
|
||
@Test | ||
public void testEndpointSpecsWithoutDescription() throws IOException { | ||
File output = Files.createTempDirectory("test").toFile(); | ||
output.deleteOnExit(); | ||
|
||
final CodegenConfigurator configurator = new CodegenConfigurator() | ||
.setGeneratorName("python-fastapi") | ||
.setPackageName("nodesc") | ||
.setOutputDir(output.getAbsolutePath().replace("\\", "/")) | ||
.setInputSpec("src/test/resources/3_1/nodesc.yaml"); | ||
|
||
DefaultGenerator generator = new DefaultGenerator(); | ||
List<File> files = generator.opts(configurator.toClientOptInput()).generate(); | ||
files.forEach(File::deleteOnExit); | ||
|
||
TestUtils.assertFileContains(Paths.get(output + "/src/nodesc/apis/nodesc_api.py"), | ||
"return await BaseNodescApi.subclasses[0]().nodesc()\n"); | ||
TestUtils.assertFileContains(Paths.get(output + "/src/nodesc/apis/desc_api.py"), | ||
"return await BaseDescApi.subclasses[0]().desc()\n"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
modules/openapi-generator/src/test/resources/3_1/nodesc.yaml
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 @@ | ||
openapi: 3.1.0 | ||
info: | ||
description: >- | ||
Yet another example. | ||
version: 1.0.0 | ||
title: OpenAPI example | ||
tags: | ||
- name: nodesc | ||
description: Endpoints have no description | ||
- name: desc | ||
description: Endpoints have description | ||
paths: | ||
/nodesc: | ||
post: | ||
tags: | ||
- nodesc | ||
summary: dummy operation | ||
operationId: nodesc | ||
responses: | ||
'200': | ||
description: successful operation | ||
'405': | ||
description: Invalid input | ||
/desc: | ||
post: | ||
tags: | ||
- desc | ||
summary: dummy operation | ||
description: 'Description' | ||
operationId: desc | ||
responses: | ||
'200': | ||
description: successful operation | ||
'405': | ||
description: Invalid input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters