Skip to content

Commit 49cadfe

Browse files
sickingaThomas Sickinger
andauthored
fix(python-fastapi): remove 200 fallback code and use default (#12481) (#21333)
Co-authored-by: Thomas Sickinger <[email protected]>
1 parent 81cdc82 commit 49cadfe

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,6 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
232232
if (operations != null) {
233233
List<CodegenOperation> ops = operations.getOperation();
234234
for (final CodegenOperation operation : ops) {
235-
List<CodegenResponse> responses = operation.responses;
236-
if (responses != null) {
237-
for (final CodegenResponse resp : responses) {
238-
// Convert "default" value (0) to OK (200).
239-
if ("0".equals(resp.code)) {
240-
resp.code = "200";
241-
}
242-
}
243-
}
244235
List<CodegenSecurity> securityMethods = operation.authMethods;
245236
if (securityMethods != null) {
246237
for (final CodegenSecurity securityMethod : securityMethods) {

modules/openapi-generator/src/main/resources/python-fastapi/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
4141
"{{{path}}}",
4242
responses={
4343
{{#responses}}
44-
{{code}}: {{=<% %>=}}{<%#dataType%>"model": <%dataType%>, "description": "<%message%>"<%/dataType%><%^dataType%>"description": "<%message%>"<%/dataType%>}<%={{ }}=%>,
44+
{{#isDefault}}"default"{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}: {{=<% %>=}}{<%#dataType%>"model": <%dataType%>, "description": "<%message%>"<%/dataType%><%^dataType%>"description": "<%message%>"<%/dataType%>}<%={{ }}=%>,
4545
{{/responses}}
4646
},
4747
tags=[{{#tags}}"{{name}}"{{^-last}},{{/-last}}{{/tags}}],

samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@router.post(
4040
"/user",
4141
responses={
42-
200: {"description": "successful operation"},
42+
"default": {"description": "successful operation"},
4343
},
4444
tags=["user"],
4545
summary="Create user",
@@ -60,7 +60,7 @@ async def create_user(
6060
@router.post(
6161
"/user/createWithArray",
6262
responses={
63-
200: {"description": "successful operation"},
63+
"default": {"description": "successful operation"},
6464
},
6565
tags=["user"],
6666
summary="Creates list of users with given input array",
@@ -81,7 +81,7 @@ async def create_users_with_array_input(
8181
@router.post(
8282
"/user/createWithList",
8383
responses={
84-
200: {"description": "successful operation"},
84+
"default": {"description": "successful operation"},
8585
},
8686
tags=["user"],
8787
summary="Creates list of users with given input array",
@@ -164,7 +164,7 @@ async def login_user(
164164
@router.get(
165165
"/user/logout",
166166
responses={
167-
200: {"description": "successful operation"},
167+
"default": {"description": "successful operation"},
168168
},
169169
tags=["user"],
170170
summary="Logs out current logged in user session",

0 commit comments

Comments
 (0)