Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint error: Expected type Schema (object) but got boolean appears when linting API definition #1296

Closed
ZyzychO opened this issue Oct 12, 2023 · 5 comments · Fixed by #1310
Closed
Labels
c0 p2 Type: Bug Something isn't working

Comments

@ZyzychO
Copy link

ZyzychO commented Oct 12, 2023

Describe the bug

Upon linting a valid API Definition, the error message "Expected type Schema (object) but got boolean" appears

To Reproduce
Steps to reproduce the behavior:

  1. Given this redocly.yaml file:
    redocly.yaml.zip

  2. And this OpenAPI file
    openapi.yaml.zip

  3. Run this command: redocly lint openapi.yaml

  4. See error: Expected type Schema (object) but got boolean

Expected behavior

In accordance with JSON Schema documentation:
https://json-schema.org/understanding-json-schema/reference/object#extending, in order to extend closed schemas you can write your schema as in the example below:

components:
  schemas:
    MyObject:
      type: object
      additionalProperties: false
      allOf:
        - $ref: '#/components/schemas/MyObjectBase'
      properties:
        property1: true
        property2: true 
      required:
        - property2
    MyObjectBase:
      type: object
      properties:
        property1:
          type: string
        property2:
          type: string
      required:
        - property1
       

However, it seems Redocly CLI does not cover this use case since the error message occurs:

Screenshot 2023-10-12 at 19 40 55

Front logo Front conversations

@ZyzychO ZyzychO added Type: Bug Something isn't working c0 p2 labels Oct 12, 2023
@jeremyfiel
Copy link
Contributor

seems like your indentation is incorrect. the second allOf schema should be under an array - definition

components:
  schemas:
    MyObject:
      type: object
      additionalProperties: false
      allOf:
        - $ref: '#/components/schemas/MyObjectBase'
        - properties:
            property1: true
            property2: true 
          required:
            - property2
    MyObjectBase:
      type: object
      properties:
        property1:
          type: string
        property2:
          type: string
      required:
        - property1
       

@jeremyfiel
Copy link
Contributor

Does this solve your issue? Can this be closed?

@tatomyr
Copy link
Contributor

tatomyr commented Oct 24, 2023

@jeremyfiel I don't think it does. The issue is that the linter doesn't recognise a boolean value of properties. And I don't know if it's better to allow the booleans or use unevaluatedProperties (like in this example) instead of additionalProperties + boolean properties.

@lornajane
Copy link
Collaborator

Thanks everyone for the clear explanations. It's a valid bug IMO, although kind of an edge case for a specific way to extend a closed schema, I'm actually not sure I've seen this usage before in an OpenAPI context. For organisations who do control their own schemas, I think enabling additionalProperties on the base schema, or refactoring the structure would be a good workaround while we consider how to prioritise adding support for this case.

@jeremyfiel
Copy link
Contributor

It depends which version of OAS they are using to determine if this is a bug or not. In JSON Schema draft 7+, it is valid to have a Boolean schema or an object schema but that requires the use of OAS 3.1.x. if using OAS 3.0.x, Boolean schemas were not allowed and must be an empty schema property:{}, in which case this would not be a valid use case and the error is correctly reporting. I figured this usage was intended to be an allOf array of schemas and their indentation was incorrect. I suppose they can also write their schema in the way they've written it, although they need to adjust it with the empty schema.

jeremyfiel added a commit to jeremyfiel/redocly-cli that referenced this issue Oct 24, 2023
JSON Schema defines property keywords to be either boolean or object schema

>Each value of this object MUST be a valid JSON Schema

https://json-schema.org/draft/2020-12/json-schema-core#name-properties

fixes Redocly#1296
jeremyfiel added a commit to jeremyfiel/redocly-cli that referenced this issue Oct 24, 2023
`SchemaProperties`
JSON Schema defines property keywords to be either boolean or object schema

>Each value of this object MUST be a valid JSON Schema

https://json-schema.org/draft/2020-12/json-schema-core#name-properties

fixes Redocly#1296
tatomyr pushed a commit to jeremyfiel/redocly-cli that referenced this issue Oct 27, 2023
`SchemaProperties`
JSON Schema defines property keywords to be either boolean or object schema

>Each value of this object MUST be a valid JSON Schema

https://json-schema.org/draft/2020-12/json-schema-core#name-properties

fixes Redocly#1296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c0 p2 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants