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

OpenAPI spec not generated correctly when JSR303 Bean Validation annotations used #2262

Closed
gbengataylor opened this issue Apr 29, 2019 · 5 comments · Fixed by #2359
Closed
Labels
kind/bug Something isn't working
Milestone

Comments

@gbengataylor
Copy link

gbengataylor commented Apr 29, 2019

When a JSR303 annotation is used on the RequestBody of REST operation, the paths.{operation}.requestBody is not generated in the swagger documentation

This code was tested with OpenJDK Runtime Environment (build 1.8.0_161-b14) and Quarkus 0.14.0.

@Path("/fruits")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class FruitResource {

    private Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));

    public FruitResource() {
        fruits.add(new Fruit("Apple", "Winter fruit"));
        fruits.add(new Fruit("Pineapple", "Tropical fruit"));
    }

    @GET
    public Set<Fruit> list() {
        return fruits;
    }

    @POST
    public Set<Fruit> add(@Valid /* JSR Bean validation*/ Fruit fruit) { 
        fruits.add(fruit);
        return fruits;
    }

    @DELETE
    public Set<Fruit> delete(Fruit fruit) { // no JSR validations
        fruits.remove(fruit);
        return fruits;
    }
}

This is the generated OpenAPI spec

---
openapi: 3.0.1
info:
  title: Generated API
  version: "1.0"
paths:
  /fruits:
    get:
      responses:
        200:
          description: OK
          content:
            application/json: {}
    post: 
      responses: #request body not generated for post
        200:
          description: OK
          content:
            application/json: {}
    delete:
      requestBody: #request body generated for delete
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Fruit'
      responses:
        200:
          description: OK
          content:
            application/json: {}
components:
  schemas:
    Fruit:
      properties:
        description:
          type: string
        name:
          type: string
@Dufgui
Copy link
Contributor

Dufgui commented Apr 29, 2019

it's a bug in smallrye openapi.
smallrye/smallrye-open-api#90
I do a analysis and point the bug line

@gbengataylor
Copy link
Author

thanks @Dufgui !

@gbengataylor
Copy link
Author

it also doensn't generate if using @NotNull

@gsmet gsmet added kind/bug Something isn't working upstream labels Apr 29, 2019
@gsmet
Copy link
Member

gsmet commented Apr 29, 2019

yes, any annotation will make it fail.

@Dufgui
Copy link
Contributor

Dufgui commented Apr 29, 2019

If you Add a jsr303 annotations witb an @parameter. It will works. according to the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants