thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
79 stars 14 forks source link

Illegal OpenAPI after format due to automatic conversion of string attribute to number #47

Closed simon-spinner closed 2 years ago

simon-spinner commented 2 years ago

If the title attribute of a schema contains only a string that looks like a number, e.g.: "500.1", starting with 1.9.1 openapi-format will turn it into a number in the formatted output (yaml format). The resulting specification is illegal, as the title attribute must always be a string and not a number.

thim81 commented 2 years ago

@simon-spinner

Thanks for reporting the issue.

I havent been able to test it myself, but could you already share if this happens everywhere or only certain OAS elements (like schema or components)?

Since 1.9.1, we provided support for large numbers that were converted unwanted. It feels that this is a side-effect of that change.

thim81 commented 2 years ago

@simon-spinner

I just updated an existing test, where the input/output are the same

components:
  schemas:
    Pet:
      type: object
      properties:
        properties:
          type: string
          example: 123e4567-e89b-12d3-a456-426614174000
        id:
          type: integer
          format: int64
          example: 10
        title:
          type: string
          example: 500.1
        name:
          type: string
          example: 123456789012345678901234567890

I tried with the exact same numeric value "500.1". This is a comparison of the input (original value) & output (after openapi-format conversion) 2022-03-17 at 09 34 25

Can you provide me with an example where the conversion is incorrect?

(I'm using openapi-format 1.9.2)

simon-spinner commented 2 years ago

Slightly adapted your example:

openapi: 3.0.2
info:
  title: Repro
  version: '1.0'
paths: {}
components:
  schemas:
    Pet:
      title: '500.1'
      type: object
      properties:
        properties:
          type: string
          example: 123e4567-e89b-12d3-a456-426614174000
        id:
          type: integer
          format: int64
          example: 10
        title:
          type: string
          example: 500.1
        name:
          type: string
          example: 1.2345678901234568e+29

After formatting it is:

openapi: 3.0.2
info:
  title: Repro
  version: '1.0'
paths: {}
components:
  schemas:
    Pet:
      title: 500.1
      type: object
      properties:
        properties:
          type: string
          example: 123e4567-e89b-12d3-a456-426614174000
        id:
          type: integer
          format: int64
          example: 10
        title:
          type: string
          example: 500.1
        name:
          type: string
          example: 1.2345678901234568e+29

which is not valid according to OpenAPI json schema.

image

thim81 commented 2 years ago

aha, now I see ! Indeed that is not desired behaviour.

I'll work on a bug fix

thim81 commented 2 years ago

@simon-spinner I just merged a bugfix for this bug. It will be part of the upcoming release.

thim81 commented 2 years ago

Closing the issue, since we just release 1.10.0 of openapi-format. If the issue would not be solved, feel free to reopen this item.