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

HTML rendering broken / unusable when allOf and oneOf even if spec is considered 0 warning #2562

Open
LasneF opened this issue Jun 19, 2024 · 6 comments

Comments

@LasneF
Copy link

LasneF commented Jun 19, 2024

Describe the bug

given a specification with no error , no warning using redocly lint , the documentation generated via redocly build-docs "crashes" at rendering , and make it unusable

To Reproduce
given the Open API description attached

run redocly build-docs .\component-descriptor.yml

Open the HTML File produce ,

select for kind the value CAT , the HTML rendering is ok
select for kind the value DOG ; the HTML rendering is broken and does not allow anymore to choose a value

Expected behavior

Either the API specification is considered as invalid are not renderable , and the build doc should shoot an error ,can be at the build doc or at the linter level

Either it is considered as correct and the rendering should be OK

Logs
NA

OpenAPI description
cf attached file (notice that yml or json does not matter)

Redocly Version(s)
redocly --version
1.16.0

Node.js Version(s)
node --version
v18.16.0

Additional context

component-descriptor.json

@LasneF LasneF changed the title HTML rendering broken whe allOf and oneOf HTML rendering broken / unusable when allOf and oneOf even if spec is considered 0 warning Jun 19, 2024
@LasneF
Copy link
Author

LasneF commented Jun 19, 2024

notice that according to https://github.com/hyperjump-io/json-schema.hyperjump.io and
https://github.com/gregsdennis/json-everything the schema describe is "valid" , and is working as expected.

@tatomyr
Copy link
Contributor

tatomyr commented Jun 19, 2024

If you remove the oneOf inside Dog, it starts working. On one hand, it's redundant, and removing it even makes the documentation a bit more readable. On the other hand, the schema is valid, so I'd expect Redoc to render it correctly.

@Redocly/keyboard-warriors, could you check if it's a bug on Redoc's end?

@LasneF
Copy link
Author

LasneF commented Jun 20, 2024

@tatomyr you are right , the sample has been over simplified , as the real use case was to have
AllOf ( something + oneOf ( A or B) + oneOf(C+D) )

@AlexVarchuk AlexVarchuk transferred this issue from Redocly/redocly-cli Jul 22, 2024
@AlexVarchuk
Copy link
Collaborator

It is Redoc issue. We'll look into it later.

@NigelThorne
Copy link

NigelThorne commented Aug 7, 2024

I think I've hit this issue too.
I have two files (firstChoice.json and secondChoice.json) of the structure

{"oneOf": [{ ...},{...}]}

and a schema file (both.json) that references them both

{ "allOf": [{"$ref": "firstChoice.json"}, {"$ref": "secondChoice.json"}]

Using the CLI to generate the docs, using both.json as an endpoints schema, the documentation only shows the second choice fields.

so switching the order causes the other choice to be visible.

{ "allOf": [{"$ref": "secondChoice.json"}, {"$ref": "firstChoice.json"}]

However... If I inline the refs, I can get it to show both fields.

{ "allOf": [{"oneOf": [{ ...},{...}]}, {"oneOf": [{ ...},{...}]}]

If one of the refs is not an 'oneOf' that also seem to work fine for me.

{ "allOf": [{"$ref": "firstChoice.json"}, {"$ref": "notAChoice.json"}]

@jeremyfiel
Copy link

jeremyfiel commented Aug 16, 2024

@NigelThorne

If I understand your issue, this should be a valid reproduction of it...

openapi: 3.0.3
info:
  title: '2562'
  version: '0.0.1'
servers:
  - url: https://redocly.com
paths:
  '/thing':
    get:
      summary: test allOf with nested oneOf by $ref
      responses:
        '200':
          description: OK
          content:
            'application/json':
              schema:
                allOf:
                  - $ref: '#/components/schemas/one-of-1'
                  - $ref: '#/components/schemas/one-of-2'
              examples:
                one-of-1:
                  value: 
                    that: 'test'
                one-of-2:
                  value:
                    thing: 'test'
                all-of:
                  value:  
                    thing: 'test'
                    that: "doesn't work"
components:
  schemas:
    one-of-1:
      title: one-of-1
      type: object
      oneOf:
        - properties:
            this:
              type: string
        - properties:
            that:
              type: string
    one-of-2:
      title: one-of-2
      type: object
      oneOf:
        - properties:
            thing:
              type: string
        - properties:
            another_thing:
              type: string
# redocly.yaml
extends:
  - recommended
rules:
  no-invalid-media-type-examples: warn

In this case, the schema defined is illogical because you can never have a valid instance against this schema.

The allOf looks at both individual schemas, and within each of them is a oneOf definition, which means the data instance can ONLY be one of those oneOf schemas, thus allOf fails because not ALL OF the schemas pass validation.

take these examples to explain further:

individual property from one-of-1 fails

{
  "that": "test"
}

individual property from one-of-2 fails

{
  "thing": "test"
}

trying one property from each subschema still fails

{
  "thing": "test",
  "that": "doesn't work"
}

I don't think Redocly look the schemas with any schema logic considered, so they should still render this illogical schema but, this is not a valid schema if you were to use it for validation and you should be able to see redocly linting does the job correctly and reports the errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants