swagger-api / swagger-api/swagger-parser

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

Open
#1,974 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

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:

  • maxItems
  • maxLength
  • maxProperties
  • minItems
  • minLength
  • minProperties

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the OpenAPI 3.1.0 sample and inspect the parsed component schema for maxItems and maxLength when values are written as 2.0. Compare those results with integer-valued constraints and verify that all listed min/max Items, Length, and Properties fields are retained for JSON Schema 2020-12 compliance.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.