Redocly / redocly-vs-code

Redocly VS Code extension
35 stars 6 forks source link

`exclusiveMinimum`/`exclusiveMaximum` OAS v3 is not validated correctly #36

Closed roalonso closed 1 year ago

roalonso commented 2 years ago

What happened?

When using exclusiveMinimum and exclusiveMaximum properties with OAS v3, the validator marks its usage as an error, saying its value should be a boolean. However, since OAS v3 this field now holds the actual (exclusive) minimum/maximum value, and is no longer a boolean.

What should have happened instead?

An integer or float should be accepted as the value for exclusiveMinimum/exclusiveMaximum. A boolean should no longer be accepted when using OAS v3.x.x.

Minimal reproducible OpenAPI snippet

openapi: 3.0.2
info: 
  title: title
  version: 1.0.0
  description: description
  license: 
    name: A license
    url: https://a.license.org
servers: 
  - url: https://a.server.org
paths: 
  /newPath:
    get: 
      operationId: newPathGet
      parameters:
        - in: query
          name: positiveValue
          required: true
          schema:
            type: number
            format: float
            exclusiveMinimum: 0.0
      summary: A test path.
      responses: 
        204:
          description: Successful
        422:
          description: Unprocessable

Screenshots

Screen Shot 2022-08-05 at 15 37 55

Additional context

Using OAS 3.0.2.

tatomyr commented 2 years ago

Hi @roalonso,

According to the spec of v.3.0.2 it uses JSON Schema Draft-00 and it doesn't define exlusiveMinimum/exclusiveMaximum at all unless I'm missing something. Could you specify how did you find it should be a number?

jeremyfiel commented 2 years ago

OpenAPI 3.1.x is fully aligned with JSON Schema draft 2020-12 and has changed the behavior of exclusiveMinimum and exclusiveMaximum keywords.

https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0

You are using 3.0.2 and it's base schema is aligned with JSON Schema draft 04 where these two keywords accepted a boolean value, not a number.

https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.0/schema.json#L349 https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.0/schema.json#L356

roalonso commented 1 year ago

I see, the extension is behaving as expected then.