swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
781 stars 527 forks source link

minProperties and maxProperties null values while reading from swagger 2.0 #1962

Open gcornacchia opened 1 year ago

gcornacchia commented 1 year ago

Consider the following swagger 2.0 file (simplified version of petstore)

swagger: '2.0'
info:
  description: 'This is a sample server Petstore server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, you can use the api key `special-key` to test the authorization filters.'
  version: 1.0.6
  title: Swagger Petstore
  termsOfService: http://swagger.io/terms/
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
host: petstore.swagger.io
basePath: /v2
paths:
  /pet/{petId}:
    get:
      summary: Find pet by ID
      description: Returns a single pet
      operationId: getPetById
      produces:
        - application/json
        - application/xml
      parameters:
        - name: petId
          in: path
          description: ID of pet to return
          required: true
          type: integer
          format: int64
      responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/Pet'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
definitions:
  Pet:
    type: object
    required:
      - name
      - photoUrls
    additionalProperties: true
    minProperties: 1
    maxProperties: 4
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string
        example: doggie
      photoUrls:
        type: array
        xml:
          wrapped: true
        items:
          type: string
          xml:
            name: photoUrl
      status:
        type: string
        description: pet status in the store
        enum:
          - available
          - pending
          - sold

If I try to parse as follow

        ParseOptions parseOptions = new ParseOptions();
        parseOptions.setResolve(true); // implicit
        SwaggerParseResult result = new OpenAPIParser().readLocation(f.getAbsolutePath(),null,parseOptions);
        OpenAPI swagger = result.getOpenAPI();

I found that the minProperties and maxProperties field of Pet object are null.