Skip to content

Incorrect type set for AnyType Schemas #1603

Closed

Description

@spacether

When parsing this v3.0.1 schema:

openapi: 3.0.1
info:
  title: ping test
  version: '1.0'
servers:
  - url: 'http://localhost:8000/'
paths:
  /ping:
    get:
      operationId: pingGet
      responses:
        '201':
          description: OK
components:
  schemas:
    AnyValue: {}
    AnyValueWithDesc:
      description: Can be any value - string, number, boolean, array or object.
    AnyValueNullable:
      nullable: true
      description: Can be any value, including `null`.
    AnyValueModel:
      description: test any value
      type: object
      properties:
        any_value:
          $ref: '#/components/schemas/AnyValue'
        any_value_with_desc:
          $ref: '#/components/schemas/AnyValueWithDesc'
        any_value_nullable:
          $ref: '#/components/schemas/AnyValueNullable'
    AnyValueModelInline:
      description: test any value inline
      type: object
      properties:
        any_value: {}
        any_value_with_desc:
          description: inline any value
        any_value_nullable:
          nullable: true
          description: inline any value nullable
        map_any_value:
          additionalProperties: {}
        map_any_value_with_desc:
          additionalProperties: 
            description: inline any value
        map_any_value_nullable:
          additionalProperties:
            nullable: true
            description: inline any value nullable
        array_any_value:
          items: {}
        array_any_value_with_desc:
          items: 
            description: inline any value
        array_any_value_nullable:
          items:
            nullable: true
            description: inline any value nullable

swagger-parser incorrectly defines the type of the schemas:

  • map_any_value as object when it should be null
  • map_any_value_with_desc as object when it should be null
  • map_any_value_nullable as object when it should be null
  • array_any_value as array when it should be null
  • array_any_value_with_desc as array when it should be null
  • array_any_value_nullable as array when it should be null

Using swagger-parser 2.0.26
For one of them here is the shown value of the schema

map_any_value -> {MapSchema@2888} "class MapSchema {
    class Schema {
        type: object
        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: 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
    "

Activity

  1. changed the title [-]Incorrect type set for AnyType Schema[/-] [+]Incorrect type set for AnyType Schemas[/+] on Sep 6, 2021
  2. self-assigned this
    on Jan 27, 2022
  3. added a commit that references this issue on Jan 27, 2022
  4. gracekarina commented on Feb 2, 2022

    @gracekarina
    Contributor

    This ticket will be solved when 3.1 branch is merged.

  5. spacether commented on Jun 28, 2022

    @spacether
    ContributorAuthor

    Using swagger-parser 2.0.31

    This issue is also happening for:

    openapi: 3.0.3
    info:
      title: openapi 3.0.3 sample spec
      description: sample spec for testing openapi functionality, built from json schema
        tests for draft6
      version: 0.0.1
    paths: {}
    components:
      schemas:
        PropertyRefsContainingComponentSchema:
          properties:
            foo:
              $ref: '#/components/schemas/PropertyRefsContainingComponentSchema'
          additionalProperties: false
    

    PropertyRefsContainingComponentSchema type should be unset but it is incorrectly set to object

  6. frantuma commented on Jul 7, 2022

    @frantuma
    Contributor

    This should be fixed in #1768, see this comment.
    Closing ticket, please reopen if you're experiencing further issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions