quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.63k stars 2.64k forks source link

Use of @Valid causes request body to be ignored from generated OpenAPI/Swagger YAML #2339

Closed chrisjleu closed 5 years ago

chrisjleu commented 5 years ago

It appears as though the presence of javax.validation.Valid confuses the generation of the OpenAPI specification:

    @POST
    @Path("create1")
    public JsonObject createUser1(@Valid CreateUserCommand command) {
        return new JsonObject().put("response", "OK");
    }

    @POST
    @Path("create2")
    public JsonObject createUser2(CreateUserCommand command) {
        return new JsonObject().put("response", "OK");
    }

    @POST
    @Path("create3/{data}")
    public JsonObject createUser3(@PathParam("data") String data) {
        return new JsonObject().put("response", data);
    }

Generates the following YAML:

---
openapi: 3.0.1
info:
  title: Generated API
  version: "1.0"
paths:
  /api/create1:
    post:
      responses:
        200:
          description: OK
          content:
            application/json: {}
  /api/create2:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserCommand'
      responses:
        200:
          description: OK
          content:
            application/json: {}
  /api/create3/{data}:
    post:
      parameters:
      - name: data
        in: path
        required: true
        schema:
          type: string
      responses:
        200:
          description: OK
          content:
            application/json: {}
components:
  schemas:
    CreateUserCommand:
      properties:
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string

One would expect the requestBody to be present in /create1, just like in /create2. /create3 works fine too (just for information).

geoand commented 5 years ago

This seems to be a duplicate of #2262 and I have a PR in smallrye that should fix both

geoand commented 5 years ago

Once 1.1.3 lands in Central I will open a PR to add it

geoand commented 5 years ago

I'll close this as a duplicate of #2262. A PR has been opened for that issue.