openapi-processor/openapi-processor-spring

@NotNull annotation is parsed in models even if it's not required (in schema)

rombru opened this issue · 2 comments

Hi,

Here is an example

openapi-processor-mapping: v2

options:
  package-name: be.unamur.nuts.web.api
  javadoc: true
  bean-validation: true
openapi: 3.0.2
info:
  title: nuts
  version: '1.0'
  contact: {}
  description: 'Test bug'
servers:
  - url: 'http://localhost:8080'
tags:
  - name: user
    description: Everything about users
paths:
  '/users/{userId}':
    parameters:
      - schema:
          type: integer
        name: userId
        in: path
        required: true
        description: Id of an existing user.
    get:
      summary: Get User Info by User ID
      tags:
        - user
      responses:
        '200':
          description: User Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
              examples:
                Get User Alice Smith:
                  value:
                    id: 142
                    firstName: Alice
                    lastName: Smith
                    email: alice.smith@gmail.com
                    dateOfBirth: '1997-10-31'
                    emailVerified: true
                    signUpDate: '2019-08-24'
        '404':
          description: User Not Found
      operationId: get-users-userId
      description: Retrieve the information of the user with the matching user ID.

components:
  schemas:
    User:
      title: User
      type: object
      description: ''
      x-examples:
        Alice Smith:
          id: 142
          firstName: Alice
          lastName: Smith
      properties:
        id:
          type: integer
          description: Unique identifier for the given user.
        firstName:
          type: string
          description: The firstname of the user
        lastName:
          type: string
          description: The lastname of the user
      required:
        - lastName
  examples: {}

The result is the following Model:

public class User {
    @JsonProperty("id")
    @NotNull
    private Integer id;
    @JsonProperty("firstName")
    @NotNull
    private String firstName;
    @JsonProperty("lastName")
    @NotNull
    private String lastName;

    public User() {
    }
    ....
}

spring processor version: 1.0.0.M20
maven plugin version: 1.0.0.M2

The id and the firstName should not be @NotNull, only lastName is required

Yes, that was a bug in M20, fixed in openapi-processor/openapi-processor-core#44

It will work with oap-spring 2021.2.

Thanks ! Works like a charm 🥳