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

Properties that are a reference are not expandable #599

Closed
niknetniko opened this issue Aug 7, 2018 · 2 comments
Closed

Properties that are a reference are not expandable #599

niknetniko opened this issue Aug 7, 2018 · 2 comments

Comments

@niknetniko
Copy link

When a property of a model is a reference to another model, the property is not expandable.


Example spec:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Example API
  description: Hello
paths:
  /examples/{id}:
    parameters:
      - in: path
        name: id
        schema:
          type: string
        description: The ID of the customer.
        required: true
    put:
      tags: [Examples]
      summary: Get an Example
      requestBody:
        content:
            application/json:
              schema:
                $ref: '#/components/schemas/Example'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Example'
            application/xml:
              schema:
                $ref: '#/components/schemas/Example'

components:
  schemas:
    Metadata:
      description: About the entity.
      readOnly: true
      properties:
        createdBy:
          type: string
          description: Who made it.
        createdAt:
          type: string
          description: When they made it.
          format: date-time
    Example:
      description: An example model.
      required: [test, meta]
      properties:
        test:
          type: string
          description: A test field.
        meta:
          $ref: '#/components/schemas/Metadata'
tags:
- name: Examples
  description: |
    A small example demonstrating the issue.

See the result here: https://rebilly.github.io/ReDoc/?url=https://gist.githubusercontent.com/niknetniko/ebdd032f6e4e132c0864b32181bfaef1/raw/61fe049675904795b9b45adaacffa7acbaa3800a/sample.yaml#tag/Examples

As you can, the meta field of the Example model is not expandable in the documentation.


I think I have found where the bug is:
https://github.com/Rebilly/ReDoc/blob/597688e7208159864c0d5964237df6fb3445e2b7/src/services/models/Schema.ts#L96
At this line, the schema's type is used or type detection happens. However, for references, the type of the schema is undefined. This is no problem; the type detections correctly determines that it is in fact an object. The problem lies later: multiple functions rely on the schema's type, which is undefined.
I believe this could be fixed by:

  1. Finding out why (if this is a problem, not sure) a property with referenced model has an undefined type
  2. Set the type of the schema to the one returned by detectType (I'm not sure if this breaks things)
@RomanHotsiy
Copy link
Member

Thanks for the detailed issue report and for digging into source code 🙌.
I will fix this.

For now, you can easily workaround the issue:

Finding out why (if this is a problem, not sure) a property with referenced model has an undefined type

Just add type: object to the referenced model:

Metadata:
  type: object # <--- here
  description: About the entity.
  readOnly: true
  # ...

@niknetniko
Copy link
Author

Thanks for the quick fix and the workaround 👍

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

2 participants