-
-
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.
Merge branch 'fix_fastapi' of https://github.com/diorcety/openapi-gen…
…erator into diorcety-fix_fastapi
- Loading branch information
Showing
5 changed files
with
102 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
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
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/python-fastapi/param_type.mustache
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 |
---|---|---|
@@ -1 +1 @@ | ||
{{#isString}}str{{/isString}}{{#isInteger}}int{{/isInteger}}{{#isLong}}int{{/isLong}}{{#isFloat}}float{{/isFloat}}{{#isDouble}}float{{/isDouble}}{{#isByteArray}}str{{/isByteArray}}{{#isBinary}}str{{/isBinary}}{{#isBoolean}}bool{{/isBoolean}}{{#isDate}}str{{/isDate}}{{#isDateTime}}str{{/isDateTime}}{{#isModel}}{{dataType}}{{/isModel}}{{#isContainer}}{{dataType}}{{/isContainer}} | ||
{{{vendorExtensions.x-py-typing}}} |
60 changes: 60 additions & 0 deletions
60
...nerator/src/test/java/org/openapitools/codegen/python/PythonFastAPIServerCodegenTest.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,60 @@ | ||
package org.openapitools.codegen.python; | ||
|
||
import com.google.common.collect.Sets; | ||
import io.swagger.parser.OpenAPIParser; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.Operation; | ||
import io.swagger.v3.oas.models.media.ArraySchema; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import io.swagger.v3.parser.core.models.ParseOptions; | ||
import org.openapitools.codegen.*; | ||
import org.openapitools.codegen.languages.PythonClientCodegen; | ||
import org.openapitools.codegen.languages.PythonFastAPIServerCodegen; | ||
import org.openapitools.codegen.languages.features.CXFServerFeatures; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import static org.openapitools.codegen.TestUtils.assertFileContains; | ||
import static org.openapitools.codegen.TestUtils.assertFileExists; | ||
|
||
public class PythonFastAPIServerCodegenTest { | ||
|
||
// Helper function, intended to reduce boilerplate | ||
static private String generateFiles(DefaultCodegen codegen, String filePath) throws IOException { | ||
final File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); | ||
output.deleteOnExit(); | ||
final String outputPath = output.getAbsolutePath().replace('\\', '/'); | ||
|
||
codegen.setOutputDir(output.getAbsolutePath()); | ||
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); | ||
|
||
final ClientOptInput input = new ClientOptInput(); | ||
final OpenAPI openAPI = new OpenAPIParser().readLocation(filePath, null, new ParseOptions()).getOpenAPI(); | ||
input.openAPI(openAPI); | ||
input.config(codegen); | ||
|
||
final DefaultGenerator generator = new DefaultGenerator(); | ||
final List<File> files = generator.opts(input).generate(); | ||
|
||
Assert.assertTrue(files.size() > 0); | ||
return outputPath + "/"; | ||
} | ||
|
||
|
||
@Test(description = "test containerType in parameters") | ||
public void testContainerType() throws IOException { | ||
final DefaultCodegen codegen = new PythonFastAPIServerCodegen(); | ||
final String outputPath = generateFiles(codegen, "src/test/resources/bugs/pr_18691.json"); | ||
final Path p = Paths.get(outputPath + "src/openapi_server/apis/default_api.py"); | ||
|
||
assertFileExists(p); | ||
assertFileContains(p, "body: Optional[Dict[str, Any]] = Body(None, description=\"\"),"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/openapi-generator/src/test/resources/bugs/pr_18691.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "OpenAPI definition", | ||
"version": "v0" | ||
}, | ||
"paths": { | ||
"/licensing/token/renew": { | ||
"post": { | ||
"description": "Manually ask license issuer for a new token. Available in Grafana Enterprise v7.4+.\n\nYou need to have a permission with action `licensing:update`.", | ||
"operationId": "postRenewLicenseToken", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |