microsoft / OpenAPI.NET.OData

Generates OpenAPI document from OData CSDL
MIT License
207 stars 62 forks source link

nullable on double conversions #581

Closed baywet closed 1 month ago

baywet commented 1 month ago

Right now we're converting OData Edm.Double to

oneOf:
  - type: number
    format: double
  - type: string
  - $ref: '#/components/schemas/ReferenceNumeric'
nullable: true

Reference numeric being

ReferenceNumeric:
  enum:
    - '-INF'
    - INF
    - NaN

While this is not technically invalid, it doesn't mean anything as per

A true value adds "null" to the allowed type specified by the type keyword, only if type is explicitly defined within the same Schema Object. Other Schema Object constraints retain their defined behavior, and therefore may disallow the use of null as a value. A false value leaves the specified or default type unmodified. The default value is false.

source

I believe we should instead emit

oneOf:
  - type: number
    format: double
    nullable: true
  - type: string
     nullable: true
  - $ref: '#/components/schemas/ReferenceNumeric'

Reference numeric being

ReferenceNumeric:
  type: string
  nullable: true
  enum:
    - '-INF'
    - INF
    - NaN
andrueastman commented 1 month ago

Out of curiosity, does this cause an effect for downstream tooling like Kiota at the moment?

baywet commented 1 month ago

Kiota no because oai.net is much more tolerant than the specification prescribes for those sorts of things. But redocly complains. Also other tooling fails. This is impacting a major partner of ours.