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

nested relationship not displayed correctly #5972

Open
drummerwolli opened this issue Apr 22, 2020 · 3 comments
Open

nested relationship not displayed correctly #5972

drummerwolli opened this issue Apr 22, 2020 · 3 comments

Comments

@drummerwolli
Copy link

Q&A (please complete the following information)

  • OS: Ubuntu
  • Browser: Chrome
  • Version: 81
  • Method of installation: https://editor.swagger.io
  • Swagger-Editor version: 3.8.0
  • Swagger/OpenAPI version: OpenAPI 3.0.2

Content & configuration

Example Swagger/OpenAPI definition:

openapi: "3.0.2"
info:
  version: "0.2"
  title: "test API"
components:
  schemas:
    User:
      allOf:
        - $ref: '#/components/schemas/BasicMixInModel'
        - $ref: '#/components/schemas/UserFullObject'
      type: object
    UserFullObject:
      allOf:
        - $ref: '#/components/schemas/UserBaseObject'
      type: object
      required:
        - id
      properties:
        id:
          type: string
    UserBaseObject:
      type: object
      properties:
        full_user_name:
          type: string
        email:
          type: string
        team_name:
          type: string
    BasicMixInModel:
      type: object
      properties:
        updated_by:
          type: string
        updated_at:
          type: string
          format: date-time
    UserList:
      type: object
      properties:
        query:
          type: string
        items:
          type: array
          items:
            $ref: "#/components/schemas/User"
paths:
  /users:
    get:
      description: "get all users. default sorted by id"
      responses:
        200:
          description: "successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserList"

Swagger-Editor configuration options:

none

Describe the bug you're encountering

in the preview for the users GET request, not all fields are displayed.

To reproduce...

paste the above swagger file into the editor and see the rendered result.

Expected behavior

all fields should be displayed which are defined in the swagger file.

Screenshots

this is the output with missing fields:

image

also the schema is not displaying those fields:

image

interestingly enough, in the Schemas section of the editor, everything gets resolved properly:

image

Additional context or thoughts

I searched if some similar bug is/was happening already, the closest i found were swagger-api/swagger-editor#1892 and swagger-api/swagger-js#1394 but for the first one, i'm not sure if its the same issue. and changing the order also does not help here in this case.

the problem arises, when a list/array has items of objects, which are composed by other objects (referenced with allOf), which in turn also already were built out of other objects.

why do i need this? the shown swagger file is actually the condensed version of our system, which contains a user permission model. we need those different levels of inheritance to properly document also POST and PATCH requests.

@webron webron transferred this issue from swagger-api/swagger-editor Apr 22, 2020
@waterkip
Copy link
Contributor

waterkip commented Apr 26, 2020

I have the same issue (I use swagger-ui and not the editor), and I agree that the allOf is where the problem is. If you remove it, it shows the missing fields of your referenced property member. You directly reference the object in your response (you can fiddle with the attached file) it will also show the object correctly.

Glitching the matrix

SomeType:
  type: object
  allOf:
    - Foo
  properties:
    some_ref:
      $ref: "#/components/schemas/Bar"   

Works fine

SomeType:
  type: object
  properties:
    some_ref:
      $ref: "#/components/schemas/Bar"   

I've checked that my specs validate with

docker pull jamescooke/openapi-validator
docker run --rm -v $(pwd)/openapi:/data jamescooke/openapi-validator zd.yml

And that works, I've also used another viewer and that one shows show the correct data.

In the schema view of the object I also get an incorrect schema view. I've added my reproduction path as well.

bug.txt

@StenCalDabran
Copy link

It actually is solvable by changing some order: if you make sure, that the paths property comes before the components property, everything works fine. Although different behavior, this may very well be based on the same root problem as swagger-api/swagger-js#1394.

StenCalDabran pushed a commit to StenCalDabran/swagger that referenced this issue May 29, 2021
Ensure that the paths property comes before the components property,
as this may lead to several strange display bugs in swagger-ui.
See swagger-api/swagger-ui#5972 or
swagger-api/swagger-ui#3325 (comment)

Closes nestjs#1369
@jhmilan
Copy link

jhmilan commented Apr 7, 2022

It actually is solvable by changing some order: if you make sure, that the paths property comes before the components property, everything works fine. Although different behavior, this may very well be based on the same root problem as swagger-api/swagger-js#1394.

This is indeed a solution that fixes the issue. However, in some cases you can not change the spec because it is autogenerated (in my case https://docs.nestjs.com/openapi/introduction).

Any idea about what to do in those cases?

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