2

How to run swagger on my UI ? Tried like this:

import  * as SwaggerUI from 'swagger-ui';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})

export class HomeComponent implements OnInit {
  constructor(private el: ElementRef) {

    const swaggerUi = new SwaggerUI({
      url: 'http://petstore.swagger.io/v2/swagger.json',
      domNode: this.el.nativeElement.querySelector('.swagger-container'),
      deepLinking: true,
      presets: [
        SwaggerUI.presets.apis

      ],
    });

  //  var swaggerUi = SwaggerUI({
  //  url: 'http://petstore.swagger.io/v2/swagger.json',
  //   dom_id: 'swagger-ui-container'
  //});
  
    swaggerUi.load();
  }

error : swaggerUi.load is not a function I don't know really how to show my yaml/json in angular Help please

aaaaaaaaax10
  • 599
  • 2
  • 9
  • 21

1 Answers1

0

I tried using 'swagger-ui', 'swagger-ui-dist' and 'swagger-client' in Angular 5/6 but could not able to render the swagger UI. Though I was able to innitialize the swagger object using 'swagger-client'.

Then I tried swangular-component

Though it was throwing an error which i solved by adding below code to tsconfig.json:

    "baseUrl": "",
    "paths": {
      "@angular/*": [
        "../node_modules/@angular/*"
      ]
    },  

into compilerOptions object.