openapi-mock icon indicating copy to clipboard operation
openapi-mock copied to clipboard

Can the docker container load the OpenAPI YAML specification from a local file

Open dragonjuggler opened this issue 5 years ago • 4 comments

Hi.

It looks like the docker version of this requires specifying a URL to load the YAML specification. I know that the container will not have access to a local file on the host, but has any method been looked into that would allow that? For example, having a configuration service or admin service for the docker container which would allow "setting" the specification via a browser?

The docker version is more desirable, since nothing really needs to be installed, but serving up a YAML spec from a web service is not desirable (during development, the file will only be local).

Thanks.

-Mark

dragonjuggler avatar Sep 18 '20 14:09 dragonjuggler

Hello, @dragonjuggler !

You can use valid file path instead of web URL. To share your local config file with the running container you have to use docker volume. See example of docker-compose config below.

version: '3.0'

services:
  openapi_mock:
    container_name: openapi_mock
    image: muonsoft/openapi-mock
    environment:
      OPENAPI_MOCK_SPECIFICATION_URL: '/app/petstore.yaml'
    volumes:
      - ./examples/petstore.yaml:/app/petstore.yaml
    ports:
      - "8080:8080"

strider2038 avatar Sep 18 '20 14:09 strider2038

I can give this a try. How can you supply other options to the container? For example, for the standalone executable, I had to set cors_enabled to true to get things to work in my environment. And how can you get debug/trace information from the container when something doesn't work?

I ran into a couple of different issues running the command line version. Would you like me to create a separate issue for those?

dragonjuggler avatar Sep 18 '20 17:09 dragonjuggler

Never mind about the configuration - I figured it out. All the configuration environment variables need to be supplied in the docker-compose file. This plus your earlier response would be useful to have in the documentation.

dragonjuggler avatar Sep 18 '20 17:09 dragonjuggler

Ok. I ran into a few wrinkles:

  1. In the servers definition, using a URL of "http://localhost:9090" caused an error. It required a trailing / character in the URL.
  2. Attempting to use https resulted in an SSL error from curl: curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
  3. Attempting to use server variables did not work.

For #3, I tried the following definition: servers:

  • url: http://localhost:8080/{basePath} description: Local mock variables: basePath: default: v1 Swagger editor turns URLs into: /v1/XXX

But trying to access that URL results in an HTTP 404 Not found.

dragonjuggler avatar Sep 18 '20 19:09 dragonjuggler