Skip to content
Open
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 @@ -76,7 +76,7 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v
operationId = "{{{operationId}}}",
description = """{{{unescapedNotes}}}""",
responses = [{{#responses}}
ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = [Content({{#isArray}}array = ArraySchema({{/isArray}}schema = Schema(implementation = {{{baseType}}}::class)){{#isArray}}){{/isArray}}]{{/baseType}}){{^-last}},{{/-last}}{{/responses}} ]{{#hasAuthMethods}},
ApiResponse(responseCode = "{{#isDefault}}default{{/isDefault}}{{^isDefault}}{{{code}}}{{/isDefault}}", description = "{{{message}}}"{{#baseType}}, content = [Content({{#isArray}}array = ArraySchema({{/isArray}}schema = Schema(implementation = {{{baseType}}}::class)){{#isArray}}){{/isArray}}]{{/baseType}}){{^-last}},{{/-last}}{{/responses}} ]{{#hasAuthMethods}},
security = [ {{#authMethods}}SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} ]{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} ]{{/hasAuthMethods}}
){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
@ApiOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface {{classname}} {
operationId = "{{{operationId}}}",
description = """{{{unescapedNotes}}}""",
responses = [{{#responses}}
ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = [Content({{#isArray}}array = ArraySchema({{/isArray}}schema = Schema(implementation = {{{baseType}}}::class)){{#isArray}}){{/isArray}}]{{/baseType}}){{^-last}},{{/-last}}{{/responses}}
ApiResponse(responseCode = "{{#isDefault}}default{{/isDefault}}{{^isDefault}}{{{code}}}{{/isDefault}}", description = "{{{message}}}"{{#baseType}}, content = [Content({{#isArray}}array = ArraySchema({{/isArray}}schema = Schema(implementation = {{{baseType}}}::class)){{#isArray}}){{/isArray}}]{{/baseType}}){{^-last}},{{/-last}}{{/responses}}
]{{#hasAuthMethods}},
security = [ {{#authMethods}}SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} ]{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} ]{{/hasAuthMethods}}
){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,41 @@ public void nonReactiveWithResponseEntity() throws Exception {
);
}

/**
* Regression test for https://github.com/OpenAPITools/openapi-generator/issues/17445.
* OpenAPI 'default' responses must emit responseCode = "default" in @ApiResponse (swagger2),
* not "0" (internal pre-processed value) or "200" (incorrect mapping from parent codegen).
* Also verifies that useResponseEntity=false does not crash when the first response is 'default'.
*/
@Test
public void defaultResponseCodeRenderedAsDefault() throws Exception {
Path root = generateApiSources(Map.of(
KotlinSpringServerCodegen.REACTIVE, false,
KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "swagger2",
KotlinSpringServerCodegen.INTERFACE_ONLY, true,
KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, false
), Map.of(
CodegenConstants.MODELS, "false",
CodegenConstants.MODEL_TESTS, "false",
CodegenConstants.MODEL_DOCS, "false",
CodegenConstants.APIS, "true",
CodegenConstants.SUPPORTING_FILES, "false"
));
Path userApi = root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt");
// operations whose only OpenAPI response is 'default:' must use responseCode = "default"
assertFileContains(userApi,
"ApiResponse(responseCode = \"default\", description = \"successful operation\")"
);
// explicit HTTP 200 responses must still use the concrete status code
assertFileContains(userApi,
"ApiResponse(responseCode = \"200\", description = \"successful operation\", content"
);
// the raw internal representation ("0") must never appear in generated output
assertFileNotContains(userApi,
"responseCode = \"0\""
);
}

@Test
public void reactiveWithoutFlow() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserApiController() {
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand All @@ -58,7 +58,7 @@ class UserApiController() {
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand All @@ -78,7 +78,7 @@ class UserApiController() {
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand Down Expand Up @@ -160,7 +160,7 @@ class UserApiController() {
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface UserApi {
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand All @@ -68,7 +68,7 @@ interface UserApi {
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand All @@ -90,7 +90,7 @@ interface UserApi {
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand Down Expand Up @@ -180,7 +180,7 @@ interface UserApi {
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface UserApi {
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand All @@ -67,7 +67,7 @@ interface UserApi {
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand All @@ -89,7 +89,7 @@ interface UserApi {
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand Down Expand Up @@ -179,7 +179,7 @@ interface UserApi {
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.POST],
Expand All @@ -56,7 +56,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.POST],
Expand All @@ -74,7 +74,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.POST],
Expand Down Expand Up @@ -153,7 +153,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.GET],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand All @@ -59,7 +59,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand All @@ -79,7 +79,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand Down Expand Up @@ -161,7 +161,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand All @@ -59,7 +59,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand All @@ -79,7 +79,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand Down Expand Up @@ -161,7 +161,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ],
ApiResponse(responseCode = "default", description = "successful operation") ],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface UserApi {
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
]
)
@RequestMapping(
Expand All @@ -64,7 +64,7 @@ interface UserApi {
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
]
)
@RequestMapping(
Expand All @@ -85,7 +85,7 @@ interface UserApi {
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
]
)
@RequestMapping(
Expand Down Expand Up @@ -173,7 +173,7 @@ interface UserApi {
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
ApiResponse(responseCode = "default", description = "successful operation")
]
)
@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.POST],
Expand All @@ -56,7 +56,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.POST],
Expand All @@ -74,7 +74,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.POST],
Expand Down Expand Up @@ -153,7 +153,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation") ]
ApiResponse(responseCode = "default", description = "successful operation") ]
)
@RequestMapping(
method = [RequestMethod.GET],
Expand Down
Loading