Unable to initialize SwaggerUIBundle in Angular 4 project
See original GitHub issueTrying to use swagger-ui-dist inside angular4 application. Initialization of SwaggerUIBundle produces an error (promise is overwritten error is thrown from zone.js).
Stacktrace:
swagger-ui-bundle.js:67 Unhandled promise rejection Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.
Most likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)
at Function.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.assertZonePatched (zone.js:44)
at new NgZone (core.es5.js:3775)
at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_._bootstrapModuleFactoryWithZone (core.es5.js:4492)
at core.es5.js:4537
at swagger-ui-bundle.js:67
at swagger-ui-bundle.js:67
at MutationObserver.f (swagger-ui-bundle.js:67)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.
Please check repository created to reproduce an issue: https://github.com/asakalou/swagger-angular4-issue
Please check swagger component at https://github.com/asakalou/swagger-angular4-issue/blob/master/src/app/swagger/swagger.component.ts
Q | A |
---|---|
Bug or feature request? | Bug |
Which Swagger/OpenAPI version? | |
Which Swagger-UI version? | swagger-ui-dist@3.1.5 |
How did you install Swagger-UI? | via npm |
Which broswer & version? | Chrome Version 60.0.3112.90 (Official Build) (64-bit) |
Which operating system? | macOS Sierra 10.12.6 |
Configuration (browser query string, constructor, config.yaml)
http://petstore.swagger.io/v2/swagger.json
Expected Behavior
No error, should render swagger ui.
Current Behavior
Error during initializing SwaggerUIBundle inside angular4 application.
Context
We are trying to render swagger ui inside our application to provide customers an interface for our API access.
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (4 by maintainers)
Top Results From Across the Web
Adding Swagger UI to Angular App - Stack Overflow
Configure the angular.json file and desired component for swagger-ui. ... OnInit } from '@angular/core'; declare const SwaggerUIBundle: any ...
Read more >Configuring and Using Swagger UI in ASP.NET Core Web API
By executing these steps, the Swagger is configured and ready for use in our project. Exploring the Swagger UI. First, we are going...
Read more >Configuration - Swagger Documentation
The swagger-config.yaml in the project root directory, if it exists, is baked into the application; configuration object passed as an argument to Swagger...
Read more >Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
Or for an easier approach using a visual editor to create the ... Additionally, Swagger UI (which is an actively managed project with...
Read more >MEAN Stack Tutorial: Create an Example Application | Linode
MEAN is an acronym for the combination of technology stacks–MongoDB, ... ng new my-angular-app --defaults # Initialize Angular project. cd ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @asakalou, I found a solution if you want to integrate swagger-ui on Angular 4. (Thanks to @shockey for your comment)
Firstly, go to polyfills.ts and add this before the import of zone.js :
Then, go to your swagger.component.ts and use the const exported like this :
Finally, add the CSS of Swagger UI in .angular-cli.json :
I would also recommend against using the
swagger-ui-dist
package in Angular. It causes you bundle sizes to be much larger than they need to be. I was able to use the normalswagger-ui
package in an Angular 5 project by doing a simpleconst SwaggerUI = require("swagger-ui");
in my swagger component. For more info, check out this issue