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

Parameter with @Valid are not take account in schema #90

Closed
Dufgui opened this issue Apr 29, 2019 · 2 comments
Closed

Parameter with @Valid are not take account in schema #90

Dufgui opened this issue Apr 29, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@Dufgui
Copy link

Dufgui 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

I see it, it come from
OpenApiAnnotationScanner.processJaxRsMethod in the following block:

        // If the request body is null, figure it out from the parameters.  Only if the
        // method declares that it @Consumes data
        if (operation.getRequestBody() == null && currentConsumes != null) {
            Type requestBodyType = JandexUtil.getRequestBodyParameterClassType(method);
            if (requestBodyType != null) {
                Schema schema = typeToSchema(requestBodyType);
                if (schema != null) {
                    RequestBody requestBody = new RequestBodyImpl();
                    ModelUtil.setRequestBodySchema(requestBody, schema, currentConsumes);
                    operation.setRequestBody(requestBody);
                }
            }
        }

because JandexUtil.getRequestBodyParameterClassType return only parameter without annotation, but don't check if this is a not an @Parameter

@gsmet
Copy link
Contributor

gsmet commented Apr 29, 2019

but don't check if this is a not an @parameter

To be more precise, it's supposed to exclude the parameters marked with a JAX-RS annotation but as soon as there is an annotation, it's considered excluded.

Only the parameters with proper JAX-RS annotations should be excluded.

@MikeEdgar
Copy link
Member

Fixed by #98

gasper-vrhovsek pushed a commit to gasper-vrhovsek/smallrye-open-api that referenced this issue May 17, 2021
…urio-apicurio-data-models-1.1.4

Bump apicurio-data-models from 1.1.2 to 1.1.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants