feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
225 stars 63 forks source link

how to use prefix when swagger ui get json definition #186

Closed oussamaABID closed 4 years ago

oussamaABID commented 4 years ago

hi , My swagger is here : http://localhost:8080/swagger-ui/?url=/swagger-ui

but when i use my gateway to call micro service.. my url to get UI is different so she not working : http://localhost:8080/mymicroservice/swagger-ui/?url=/swagger-ui

Spring gateway :/

to get my swagger UI. i need add mymicroservice in path like this http://localhost:8080/mymicroservice/swagger-ui/?url=/mymicroservice/swagger-ui

After that i need add mymicroservice in path when i call each app service

localhost:8080/mymicroservice/myservice

how i can do that ?

Thanks

i try prefix option but is not working

({
  docsPath: '/swagger-ui',
  prefix:'/mymicroservice',
  uiIndex: (process.env.ENABLE_UI_SWAGGER=== 'true'),
  openApiVersion: 3,
Mairu commented 4 years ago

Hi, the prefix option is to be used for internal API prefixes.

In your case, you will have to use a custom function for the uiIndex option to handle your use case. See https://github.com/feathersjs-ecosystem/feathers-swagger/blob/master/lib/index.js#L39 for the default handling.

oussamaABID commented 4 years ago

hi mairu, tanks for replay. finaly i add just mymicroservice in docsPath option like this

swagger({
  docsPath: '/mymicroservice/swagger-ui',
  uiIndex: (process.env.ENABLE_UI_SWAGGER=== 'true'),
  openApiVersion: 3,

the probleme when i use swagger UI to try in out my service . i dont have mymicroservice in url. curl -X POST "http://localhost:3030/myService?param1=b&param2=b"

It s possible to custumise url to add mymicroservice in ui try in out ?

curl -X POST "http://localhost:3030/mymicroservice/myService?param1=b&param2=b" -H "accept: */*" -H "Content-Type: application/json"

image

Maybe getOperationArgs ?

thanks :)

Mairu commented 4 years ago

There is the servers option of the openApi Specification -> https://swagger.io/docs/specification/api-host-and-base-path/ . There you should be able to configure the server to your needs.

You would have to set this in the specs options of the initialization.

oussamaABID commented 4 years ago

thanks mairu you save my day 🚀 image