swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.47k stars 8.96k forks source link

Access extension data from OpenAPI/Swagger schema #7859

Open topliceanurazvan opened 2 years ago

topliceanurazvan commented 2 years ago

How can we help?

Currently, after reading the documentation, for showing extensions found in the schema, you can do that with the showExtensions property, but only for Operations/Parameters/Response/Schema objects. The problem is that there are some schemas that have extensions at the top-level or path level ( eg. shown in the screenshot below ) and they are not shown by default.

image

I've tried to access the data of the extension through SwaggerUI plugins, but only managed to do so at the operation level with wrapComponents -> operation. Are there any examples or could you provide some help on how I can access the extension data through plugins if the extension is at top-level or path level?

topliceanurazvan commented 2 years ago

Apparently I found something that works for me. When you define a plugin, the first argument contains the specSelectors from where you can access specJson() which gives you the json format of the spec given to SwaggerUI. You can use it in any wrapComponent or component as preffered.

I think the issue can be closed!