Skip to content

Commit abce111

Browse files
authored
fix(fastapi): use correct impl & package name with custom values (#20970)
Signed-off-by: Henrik Gerdes <[email protected]>
1 parent ee7927a commit abce111

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void serialize(Boolean value, JsonGenerator gen, SerializerProvider seria
7171
private static final int DEFAULT_SERVER_PORT = 8080;
7272
private static final String DEFAULT_PACKAGE_NAME = "openapi_server";
7373
private static final String DEFAULT_SOURCE_FOLDER = "src";
74+
private static final String DEFAULT_IMPL_FOLDER = "impl";
7475
private static final String DEFAULT_PACKAGE_VERSION = "1.0.0";
7576

7677
private String implPackage;
@@ -109,7 +110,7 @@ public PythonFastAPIServerCodegen() {
109110
additionalProperties.put("baseSuffix", BASE_CLASS_SUFFIX);
110111
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, DEFAULT_SOURCE_FOLDER);
111112
additionalProperties.put(CodegenConstants.PACKAGE_NAME, DEFAULT_PACKAGE_NAME);
112-
additionalProperties.put(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, DEFAULT_PACKAGE_NAME.concat(".impl"));
113+
additionalProperties.put(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, DEFAULT_IMPL_FOLDER);
113114

114115
languageSpecificPrimitives.add("List");
115116
languageSpecificPrimitives.add("Dict");
@@ -124,7 +125,7 @@ public PythonFastAPIServerCodegen() {
124125
apiPackage = "apis";
125126
modelPackage = "models";
126127
testPackage = "tests";
127-
implPackage = "impl";
128+
implPackage = DEFAULT_IMPL_FOLDER;
128129
apiTestTemplateFiles().put("api_test.mustache", ".py");
129130

130131
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case).")
@@ -153,10 +154,14 @@ public void processOpts() {
153154

154155
if (additionalProperties.containsKey(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE)) {
155156
this.implPackage = ((String) additionalProperties.get(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE));
157+
// Prefix templating value with the package name
158+
additionalProperties.put(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE,
159+
this.packageName + "." + this.implPackage);
156160
}
157161

158162
modelPackage = packageName + "." + modelPackage;
159163
apiPackage = packageName + "." + apiPackage;
164+
implPackage = packageName + "." + implPackage;
160165

161166
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
162167
supportingFiles.add(new SupportingFile("openapi.mustache", "", "openapi.yaml"));

modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonFastapiCodegenTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
3030
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
3131
files.forEach(File::deleteOnExit);
3232

33-
TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "/src", IMPL_PKG, "__init__.py"));
33+
TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "/src", "/nodesc", IMPL_PKG, "__init__.py"));
3434
}
3535

3636
@Test

0 commit comments

Comments
 (0)