stoplightio / elements

Build beautiful, interactive API Docs with embeddable React or Web Components, powered by OpenAPI and Markdown.

Home Page:https://stoplight.io/open-source/elements/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example body missing reference schema attributes

janavMGX opened this issue · comments

Context

We have revamped our API documentation and would like to use Stoplight as the new method of displaying the YAMLs.

Current Behavior

The example body in the Try it panel doesn't seem to correspond to the number of attributes. [https://www.mediagenix.tv/api-j7d2XD7sFqcdWGeS/docs/Latest_version/Content/Content%20API/Stoplight%20API%20Explorer.htm#/paths/series/post](Seen in Series > POST series)

When I view the YAML in Swagger UI, the example body is a lot longer. [https://www.mediagenix.tv/api-j7d2XD7sFqcdWGeS/docs/Latest_version/Content/Content%20API/Swagger%20UI%20API%20Explorer.htm](Seen in Series > POST series)

The schema used in this call:

    Series:
      allOf:
        - $ref: '#/components/schemas/Content'
        - type: object
          properties:
            contentId:
              type: string
            seasonIds:
              type: array
              items:
                type: string
                description: The contentId's of the seasons that are part of this series.
            contentType:
              type: string
              description: Maps to the drop-down PSIProductType
            productTitles:
              type: array
              items:
                $ref: '#/components/schemas/ProductTitle'
            contentCollectionIntentions:
              description: Maps to the drop-down PSIContentCollectionIntention
              type: array
              items:
                type: string           

The result example body:

{
  "contentId": "string",
  "seasonIds": [
    "string"
  ],
  "contentType": "string",
  "productTitles": [
    {
      "id": "string",
      "title": "string",
      "type": "string",
      "broadcastingTitle": false,
      "alternativeTitle": false
    }
  ],
  "contentCollectionIntentions": [
    "string"
  ]
}

Stoplight only seems to show the attributes directly defined on the schema and not the reference schema.

Expected Behavior

Stoplight should also show the full example body including the referenced schema.

This ticket has been labeled jira. A tracking ticket in Stoplight's Jira (STOP-347) has been created.

@janavMGX Could it be that your $ref'ed schema (#/components/schemas/Content) in your above schema is having additionalProperties: false? If you remove that does it work for you?

@weyert No, it only has properties defined like this:
Content:
properties:
title:
type: string
duration:
etc...

What I did try now is to move the $ref below the properties like this, and then it does show all of them. I'm not sure why that could be. Thanks!

Series:
      allOf:
        - type: object
          properties:
            contentId:
              type: string
            seasonIds:
              type: array
              items:
                type: string
                description: The contentId's of the seasons that are part of this series.
            contentType:
              type: string
              description: Maps to the drop-down PSIProductType
            productTitles:
              type: array
              items:
                $ref: '#/components/schemas/ProductTitle'
            contentCollectionIntentions:
              description: Maps to the drop-down PSIContentCollectionIntention
              type: array
              items:
                type: string
        - $ref: '#/components/schemas/Content'   

Yeah, I have the same issue for when I removed the additionProperties: false in the referenced schema it started showing.

I haven't figured out what the cause is but if I deep down in @stoplight/json-schema-tree it uses a fork of json-schema-merge-allof (https://github.com/mokkabonna/json-schema-merge-allof) which has an setting ignoreAdditionalProperties then it shows up.

So there is something going wrong when merging allOf entries.

commented

Yeah, I have the same issue for when I removed the additionProperties: false in the referenced schema it started showing.

I haven't figured out what the cause is but if I deep down in @stoplight/json-schema-tree it uses a fork of json-schema-merge-allof (https://github.com/mokkabonna/json-schema-merge-allof) which has an setting ignoreAdditionalProperties then it shows up.

So there is something going wrong when merging allOf entries.

Any update?

@nawbc Not on my end. I have been busy working on work stuff. Might pick the sup at a later time. The code is not easy to understand for me so struggling a bit.

Last month I tried to replace it with https://www.npmjs.com/package/@fastify/merge-json-schemas but not much luck so far.

Same discussion: #2593