Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring] Bug @ApiResponse ignores different responses #3371

Closed
frasch1712 opened this issue Jul 14, 2016 · 11 comments
Closed

[Spring] Bug @ApiResponse ignores different responses #3371

frasch1712 opened this issue Jul 14, 2016 · 11 comments

Comments

@frasch1712
Copy link

frasch1712 commented Jul 14, 2016

Description

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),
        }
)
Swagger-codegen version

master branch

Swagger declaration file content or url

Declaration in yaml (extract):

paths:
   ...
   get:
   ...
      responses:
        200:
          description: Successful response
          schema:
            $ref: "#/definitions/Product"
        400:
          description: Bad Request
          schema:
            $ref: "#/definitions/Error"

Command line used for generation

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 frasch1712 changed the title [JAVA] Bug @ApiResponse ignores different responses [Spring] Bug @ApiResponse ignores different responses Jul 17, 2016
@wing328
Copy link
Contributor

wing328 commented Jul 22, 2016

@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

@frasch1712
Copy link
Author

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.

@ok11
Copy link

ok11 commented Sep 22, 2016

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.

@wing328
Copy link
Contributor

wing328 commented Sep 23, 2016

@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.

@fdasoghe
Copy link

fdasoghe commented Jan 2, 2017

I have this same issue. Is there any progress on it? Or maybe a workaround?

@ebautistabar
Copy link

Hi, first of all congrats on this amazing project! Now on to the issue, just a couple of comments:

  • are there plans to merge [Java][Spring] fix incorrect @ApiResponse's response type. #4801 for the next release?
  • 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

@wing328
Copy link
Contributor

wing328 commented May 18, 2017

@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.

@ebautistabar
Copy link

@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.

@gcernier-amadeus
Copy link
Contributor

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)?

@wing328
Copy link
Contributor

wing328 commented Aug 8, 2017

@gcernier-amadeus I'll try to merge it later today after resolving the merge conflicts.

@wing328
Copy link
Contributor

wing328 commented Aug 8, 2017

Closed via #4801. Thanks for the fix by @gcernier-amadeus

Please pull the latest master to give it a try.

@wing328 wing328 closed this as completed Aug 8, 2017
@wing328 wing328 modified the milestones: v2.3.0, Future Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants