You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
directly remove/add "throws Exception" for all APIs are not good idea, since a part of APIs need it.
Describe the solution you'd like
I think we can use Open API "Specification Extensions", with additional flag "x-" to tell generator which API need throws, which don't need.
options:
Option 1. add x-operationId-exception: true/false ---- boolean value
api.yaml:
paths:
/api/v1/documents:
post:
operationId: "createDocument"
x-operationId-exception: true
option1.1 generate logical:
if (x-operationId-exception == true/undefined && unhandledException == true) {
generate "throws Exception"
} else if (x-operationId-exception == false && unhandledException == true) {
// e.g. we have 10 APIs, only a few APIs(e.g. 1,2) doesn't need throws
no throws generated
} else if (x-operationId-exception == true && unhandledException == false/undefined) {
// e.g. we have 10 APIs, only a few APIs(e.g. 1,2) do need throws
generate "throws Exception"
} else if (x-operationId-exception == false/undefined && unhandledException == false/undefined) {
no throws generated
}
option 1.2
for simple,
if(x-operationId-exception == true) {
generate "throws Exception"
} else {
no throws generated
}
Option 2. add x-operationId-exception: ---- string array
api.yaml:
paths:
/api/v1/documents:
post:
operationId: "createDocument"
x-operationId-exception: [MyException1, MyException2]
option 2.1 generate logical:
if (x-operationId-exception is defined) {
// no need to check unhandledException
generate "throws MyException1, MyException2"
} else if (x-operationId-exception is undefined) {
if (unhandledException == true) {
generate "throws Exception"
} else {
no throws generated
}
}
option 2.2
for simple,
if(x-operationId-exception is defined) {
generate "throws MyException1, MyException2"
} else {
no throws generated
}
Option 2 (for simple, option 2.2) may be better, how do you think?
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
it generate APIs as below, no "throws Exception" generated, but we really need "throws" in some cases:
I found two related PR/issue
[JAX-RS][Spec] Removes throws Exception. swagger-api/swagger-codegen#7437
Add
throws Exception
directive to Spring operation methods #2482directly remove/add "throws Exception" for all APIs are not good idea, since a part of APIs need it.
Describe the solution you'd like
I think we can use Open API "Specification Extensions", with additional flag "x-" to tell generator which API need throws, which don't need.

options:
Option 2 (for simple, option 2.2) may be better, how do you think?
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: