swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Consider re-factoring swagger-ui into a component

Open thegecko opened this issue 11 years ago • 8 comments

IMO, swagger-ui should be a drop-in component which should behave as a module and have external dependencies, but is currently structured as an application.

This causes issues with baked-in dependencies and the need to distribute the project with copies of third party libraries.

Structuring the project as a module following AMD/CommonJS paradigms and utilising a registry such as bower for third-party dependencies could make the project far easier to manage, update and integrate into other applications.

thegecko avatar Dec 13 '14 11:12 thegecko

thanks, we'll take this into account

fehguy avatar Dec 29 '14 18:12 fehguy

I would like to second thegecko's request, trying to integrate AMD functionality has been a hair puller.

swbullis avatar Jan 28 '15 19:01 swbullis

@swbullis have you been able to implement swagger-ui via AMD/require? If not, I would also like to request this feature.

alycda avatar Feb 10 '15 20:02 alycda

The only way we can truly package an app like this is web components. I played with the idea of wrapping this app in a web component in this branch. Unfortunately because SwaggerUI relies of global objects and <body> element in too many places, it's not an easy task. There is also routing that needs to get refactored to allow multiple SwaggerUI instances live in the same page.

mohsen1 avatar Mar 10 '15 18:03 mohsen1

@alycda no I finally opted to just use an iframe.

swbullis avatar Mar 11 '15 20:03 swbullis

I'll echo this desire too. Swagger can't be embedded on a site that uses RequireJS (or any AMD loader), because shred.bundle.js overwrites window.require and window.define. iframes are a fine solution, but do have some drawbacks if you want to hide the fact that an iframe is being used (main difficulties are keeping the size of the iframe consistent with the size of the content, so no inner scrolling is necessary, and allowing for links inside the iframe to navigate the parent, instead of navigating inside the iframe).

As far as I know, shred.bundle.js is the only barrier. If only shred would look for an existing AMD loader instead of jamming its own into the page, I like to think everything would suddenly play nicely together. :)

mwcz avatar Mar 18 '15 21:03 mwcz

shred is a dependency of swagger-js. Plan is to remove that dependency. Once it's gone we will make swagger-ui.js a UMD compatible (requirejs and commonjs compatible) file.

mohsen1 avatar Mar 18 '15 21:03 mohsen1

Awesome, great to hear!

mwcz avatar Mar 19 '15 01:03 mwcz