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

Component schema not rendering in SwaggerUI when specified using $ref #8671

Open
eganma-umich opened this issue May 15, 2023 · 1 comment
Open

Comments

@eganma-umich
Copy link

Q&A (please complete the following information)

  • OS: macOS Version 13.3.1 (a) (22E772610a)
  • Browser: 42Crunch OpenAPI Editor, SwaggerUI preview
  • Version: 4.17.0
  • Method of installation: VS Code .dmg > Vs Code Extensions
  • Swagger-UI version: "swagger-ui-react": "^4.15.5"
  • Swagger/OpenAPI version: 3.0.2

Content & configuration

Example Swagger/OpenAPI definition:

{
    "openapi":"3.0.2",
    "info": {
      "title":"API Title",
      "version":"1.0"
    },
    "servers": [
      {"url":"https://api.server.test/v1"}
    ],
    "components": {
        "schemas": {
            "collectionTemplate": {
                "type": "object",
                "properties": {
                    "type": {
                        "enum": ["collection"]
                    },
                    "items": {
                        "type": "array",
                        "items": {
                            "type": "object"
                        }
                    }
                }
            },
            "timestampTemplate": {
                "type": "object",
                "properties": {
                    "timestamp": {
                        "enum": ["timestamp"]
                    }
                }
            },
            "item1": {
                "allOf": [
                    {
                        "$ref": "#/components/schemas/timestampTemplate"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "item1Prop": {
                                "type": "string"
                            }
                        }
                    }
                ]
            },
            "item2": {
                "type": "object",
                "properties": {
                    "item2Prop": {
                        "enum": ["item2Prop"]
                    },
                    "item1Copy": {
                        "$ref": "#/components/schemas/item1"
                    }
                }
            },
            "item2CollectionNotRendered": {
                "allOf": [
                    {
                        "$ref": "#/components/schemas/collectionTemplate"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "items": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/components/schemas/item2"
                                }
                            }
                        }
                    }
                ]
            },
            "item2CollectionRendered": {
                "allOf": [
                    {
                        "$ref": "#/components/schemas/collectionTemplate"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "items": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "item2Prop": {
                                            "enum": ["item2Prop"]
                                        },
                                        "item1Copy": {
                                            "$ref": "#/components/schemas/item1"
                                        }
                                    }
                                }
                            }
                        }
                    }
                ]
            }
        }
    },
    "paths": {
        "/notrendered": {
            "get": {
                "description": "",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/item2CollectionNotRendered"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/rendered": {
            "get": {
                "description": "",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/item2CollectionRendered"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Swagger-UI configuration options:

// n/a

Describe the bug you're encountering

One component schema (item2 in example) includes another (item1 in example) as a sub-object in its definition. The item2 schema resolves correctly in the "Schemas" section of the preview, but the reference to item1 defaults to "string" rather than displaying the sub-object in the route response example textbox when added as a $ref. Adding the item2 schema directly rather than referencing it produces the expected result.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io
  2. Copy the example definition into the editor
  3. Compare example text for responses of /notrendered and /rendered
  4. Compare schemas for item2Collection* > items > item1Copy of item2CollectionNotRendered and item2CollectionRendered in the Schemas section.

Expected behavior

The response example text for item2CollectionNotRendered and item2CollectionRenderd to match.

Screenshots

238069996-eb55920c-4660-4416-a422-ba952fd94527

238070027-7d5df88c-caf4-499a-aa69-24ad5a73af30

238070045-ec5a8ed6-df0d-4253-ac2c-abfb21daea5f

Additional context or thoughts

Directed here by extension project: 42Crunch/vscode-openapi#222

@Eger37
Copy link

Eger37 commented Aug 28, 2024

HI, I think that this issue may be similar with #7696

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

No branches or pull requests

2 participants