supereagle / experiences

Summary of practical experience in work.
2 stars 0 forks source link

Aggregate Swagger documentations from multiple microservices into a Swagger UI #6

Closed supereagle closed 7 years ago

supereagle commented 7 years ago

In a platform constructed by microservices, services communicate through REST APIs. If use Swagger to describe the REST APIs for each service, there will be too many Swagger documentations. It is better to manage and display them in one Swagger UI.

Reference

Question: Best way to aggregate multiple Swagger endpoints in a single HTML page Load multiple resources to swagger-ui - work by @ponelat

supereagle commented 7 years ago

Error

Swagger UI can display swagger.json but has an "ERROR" indicator

http://online.swagger.io/validator/debug?url=http://xxx.xxx.com/swagger.json {"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://xxx.xxx.com/swagger.json"}]}

Parameter: validatorUrl

By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). Setting it to null will disable validation. This parameter is relevant for Swagger 2.0 specs only.

Solution

Set validatorUrl: null to disable online validator.

supereagle commented 7 years ago

Error

Can't read from server. It may not have the appropriate access-control-origin settings.

Solution

Enable CORS support by add Access-Control-Allow-Origin: * in the response header.

Reference

CORS Support Enable CORS Server