Swagger Spring Boot Code generation ignores different schema references in responses.
Actually the following is generated:
@ApiResponses(
value =
{
@ApiResponse(code = 200, message = "Successful response", response = Product.class),
@ApiResponse(code = 400, message = "Bad Request", response = Product.class),
}
)
I would expect the following "response = Error.class for code = 400" (see below for the yaml definition):
@ApiResponses(
value =
{
@ApiResponse(code = 200, message = "Successful response", response = Product.class),
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
}
)
master branch
Declaration in yaml (extract):
paths:
...
get:
...
responses:
200:
description: Successful response
schema:
$ref: "#/definitions/Product"
400:
description: Bad Request
schema:
$ref: "#/definitions/Error"
java -Dmodels -Dapis -jar swagger-codegen-cli.jar generate -i swagger.yaml -l spring
additional config:
{
"modelPackage": "...",
"apiPackage": "...",
"interfaceOnly": true,
"hideGenerationTimestamp": true,
"dateLibrary":"java8",
"java8": true,
"library": "spring-boot"
}
@frasch1712 I don't think the custom error model is supported at the moment. May I know if you've cycle to contribute the enhancement?
cc @cbornet
I investigated a bit in it and think it is only a small change in the mustache template. So I will try to contribute the enhancement.
And just for the record -- the problem is that the template uses returnTypeproperty, which gets resolved in the higher (operation) context, and thus gives really an operation return type, Product in the example above; instead the template should use baseType, which is a property of the response.
So, a bug in the api.mustache . I have fixed locally, will wait until the pull request by @frasch1712 gets accepted into the upstream.
@ok11 I don't see any PR from @frasch1712 : https://github.com/swagger-api/swagger-codegen/pulls/frasch1712
For the time being, I would suggest you to file one for review. Thanks.
I have this same issue. Is there any progress on it? Or maybe a workaround?
Hi, first of all congrats on this amazing project! Now on to the issue, just a couple of comments:
@ApiResponse objects, both containing code 200; I think this point was not raised in the issue so far but it would be nice if it were fixed too@ebautistabar
are there plans to merge #4801 for the next release?
Yes, we want to merge it. Did you have a chance to test the first? Does it work for you?
when setting a 200 response and a default response in the yaml file, the generator creates just 2 @ApiResponse objects, both containing code 200; I think this point was not raised in the issue so far but it would be nice if it were fixed too
I would recommend opening a new issue for tracking so as to more easily draw attention from the community.
@wing328 I have tested the PR and it seems to solve the issue described by @frasch1712.
I will open a new issue to describe the other problem.
Would it be possible to merge #4801 so that I will have a possibility to provide another fix of another issue I spotted around the same feature, before v2.3.0 milestone (so that this version will contain the 2 fixes)?
@gcernier-amadeus I'll try to merge it later today after resolving the merge conflicts.
Closed via #4801. Thanks for the fix by @gcernier-amadeus
Please pull the latest master to give it a try.