swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Default value of array type is not converted correctly when converting from swagger 2 to openapi 3,

Open MasatoYagi opened this issue 2 years ago • 2 comments

Q&A

  • OS: [macOS]
  • Browser: [chrome]
  • Version: [108.0.5359.124 (Official Build) (arm64)]
  • Method of installation: [docker]
  • Swagger-Editor version: ["4.14.0"]
  • Swagger/OpenAPI version: [Swagger 2.0 -> OpenAPI 3.0]

Content & configuration

Example Swagger ver2.0 definition (Before conversion):

swagger: '2.0'
info:
  title: Future Vuls Public API
  description: Future Vuls Public API
  contact:
    name: FutureVuls
    url: >-
      https://xxxxxxxxxxxxxxxxxxx
  version: v1
host: host.xxxx.biz
schemes:
  - https
paths:
  /items:
    get:
      parameters:
        - name: status filter
          in: query
          description: Status filter
          required: false
          type: array
          items:
            type: string
            enum:
              - new
              - investigating
              - ongoing
              - defer
              - not_affected
              - risk_accepted
              - workaround
              - patch_applied
          collectionFormat: multi
          default: # array type
            - new
            - investigating
            - ongoing
      responses:
        '200':
          description: OK response.

Example OpenAPI ver3.0 definition (after conversion):

openapi: 3.0.1
info:
  title: Future Vuls Public API
  description: Future Vuls Public API
  contact:
    name: FutureVuls
    url: https://xxxxxxxxxxxxxxxxxxx
  version: v1
servers:
- url: https://host.xxxx.biz/
paths:
  /items:
    get:
      parameters:
      - name: status filter
        in: query
        description: Status filter
        style: form
        explode: true
        schema:
          type: array
          items:
            type: string
            enum:
            - new
            - investigating
            - ongoing
            - defer
            - not_affected
            - risk_accepted
            - workaround
            - patch_applied
           default: '["new","investigating","ongoing"]'  # Converted default value is not of type `array`
      responses:
        200:
          description: OK response.
          content: {}
components: {}

Describe the bug you're encountering

To reproduce...

Steps to reproduce the behavior:

  1. import file (Example Swagger ver2.0 definition)
  2. Go to 'toolbar'
  3. Click on 'Edit' > 'convert to OpenAPI 3'

Expected behavior

Now

           default: '["new","investigating","ongoing"]'  # Converted default value is not of type `array`

Correct output

            default:
              - new
              - investigating
              - ongoing

Additional context or thoughts

It would be more appreciated that an error is displayed if the type is array but the default value is of any other type.

MasatoYagi avatar Jan 14 '23 15:01 MasatoYagi

This issue looks related to our Java services. Seeking confirmation from the Java team.

Confirmed. Moving to https://github.com/swagger-api/swagger-parser repository.

char0n avatar Feb 15 '23 09:02 char0n

Thanks:)

MasatoYagi avatar Feb 15 '23 13:02 MasatoYagi