swagger-api / swagger-parser

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

v3.1.0 min/max/Items/Length/Properties information omitted from schema #1974

Open spacether opened 10 months ago

spacether commented 10 months ago

v3.1.0 min/max/Items/Length/Properties information omitted from schema when numeric (float) values are used whose value equals an integer value. Applies to:

swagger-parser version: 2.1.1

For this spec:

openapi: 3.1.0
servers:
- url: https://someserver.com/v1
info:
  title: openapi 3.1.0 sample spec
  version: 0.0.1
  description: sample spec for testing openapi functionality, built from json schema
    tests for draft2020-12
tags: []
paths: {}
components:
  schemas:
    MaxitemsValidationWithADecimal:
      $schema: https://json-schema.org/draft/2020-12/schema
      maxItems: 2.0
    MaxlengthValidationWithADecimal:
      $schema: https://json-schema.org/draft/2020-12/schema
      maxLength: 2.0

The parsed component schema lacks maxItems/maxLength info, even though it was defined in the document. Here is the info:

class JsonSchema {
    class Schema {
        type: null
        format: null
        $ref: null
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
        patternProperties: null
        contains: null
        $id: null
        $anchor: null
        $schema: https://json-schema.org/draft/2020-12/schema
        const: null
        contentEncoding: null
        contentMediaType: null
        contentSchema: null
        propertyNames: null
        unevaluatedProperties: null
        maxContains: null
        minContains: null
        additionalItems: null
        unevaluatedItems: null
        _if: null
        _else: null
        then: null
        dependentRequired: null
        dependentSchemas: null
        $comment: null
        prefixItems: null
    }
}

This blocks compliance to json schema 2020-12, required by openapi v3.1.0 This came up when writing: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/pull/238

Related Issue: https://github.com/swagger-api/swagger-parser/issues/1979