Swagger-ui: Supporting multiple files in docker container

Created on 2 Oct 2018  路  7Comments  路  Source: swagger-api/swagger-ui

I am having trouble supporting multiple files inside the swaggerapi/swagger-ui docker container.

Here is my docker compose:

  swaggerui:
    image: swaggerapi/swagger-ui
    ports:
      - "7000:8080"
    environment:
      - SWAGGER_JSON=/swagger/swagger.yml
    volumes:
      - ./Swagger:/swagger

I would expect this to serve swagger.yml out of the /swagger directory that is mounted.

docker exec -it -name- ls swagger
I can see all my files here, swagger.yml, user.swagger.yml, etc

But this is not the root of the nginx web server running in the container:

    location / {
      alias            /usr/share/nginx/html/;

Looks like swagger.yml is copied over to /user/share/nginx/html/. This means that my files I want to reference in my swagger.yml are not available to be served by nginx.

This doesn't seem like it should be the default behavior, how can I support loading in the other files found in my mounted volume? Perferably without having to modify my swagger.yml to have a strange path I would only use in docker (we are using it only for local). It should also use the volume as a source so I can make changes locally.

docker enhancement

Most helpful comment

Here's what I ended up doing, combining the knowledge from above:

~
docker run -p 80:8080
-e URLS_PRIMARY_NAME=FIRST
-e URLS="[
{ url: 'docs/first.yml', name: 'FIRST' }
, { url: 'docs/second.yml', name: 'SECOND' }
]"
-v pwd:/usr/share/nginx/html/docs/
swaggerapi/swagger-ui
~

All 7 comments

Here is a workaround that will copy my volume contents to the nginx directory

docker exec -it *name* cp -a swagger/. /usr/share/nginx/html

Hoping there is a way to do this through configuration instead.

hmm, now running into issues with $ref, I want to split my API into separate files and it looks like people are using https://github.com/javanile/yamlinc to do it, this is another problem for my use case.

My use case is I want a local docker container to be used for development where it will pick up any changes in my swagger files and serve them in swaggerui. This is hard to do if I have to automate the build process, to do this I am looking at building my own custom image.

To solve the dependency problem nginx could be updated to serve all .yml and .json files from a mount

I managed to do it by mounting volume inside nginx web server root directory
docker run -p 8085:8080 -v /swagger-files:/usr/share/nginx/html/myfiles swaggerapi/swagger-ui

Then explore swagger files from that directory ./myfiles/petstore.json

Here's what I ended up doing, combining the knowledge from above:

~
docker run -p 80:8080
-e URLS_PRIMARY_NAME=FIRST
-e URLS="[
{ url: 'docs/first.yml', name: 'FIRST' }
, { url: 'docs/second.yml', name: 'SECOND' }
]"
-v pwd:/usr/share/nginx/html/docs/
swaggerapi/swagger-ui
~

This works for me.

My docker-compose:

     swagger-ui:
         image: swaggerapi/swagger-ui
         ports:
             - 8083:8080
         volumes:
             - ./docs:/usr/share/nginx/html/docs
             - ./docs:/docs
         environment:
             SWAGGER_JSON: /docs/openapi.yaml

My openapi.yaml is compliance with v3.0.0, https://swagger.io/docs/specification/using-ref/

paths:
  /user:
    $ref: '/docs/openapi-user.yaml'
  /user/{id}:
    $ref: '/docs/openapi-user-by-id.yaml'

My openapi-user.yaml:

post:
    tags:
      - user
    summary: Create a user

Voila!

This issue can be closed I think, it is fixed with #5565

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartinMuzatko picture MartinMuzatko  路  4Comments

easyest picture easyest  路  3Comments

Deraen picture Deraen  路  4Comments

LaysDragon picture LaysDragon  路  3Comments

prabhat1790 picture prabhat1790  路  3Comments