4

I have a problem with generating client API using openapi generator on Docker. After runing:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i ./petstore.yml -g typescript-angular -o api/petstore

I got an:

[error] The spec file is not found: ./petstore.yml
[error] Check the path of the OpenAPI spec and try again.

Also tried:

docker run --rm -v "${PWD}" openapitools/openapi-generator-cli generate -i ./petstore.yml -g typescript-angular -o api/petstore

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i petstore.yml -g typescript-angular -o api/petstore
Yura Demkiv
  • 346
  • 2
  • 8

1 Answers1

6

Fix:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/petstore.yml -g typescript-angular -o /local/api/petstore

My problem was in not understanding how -v "${PWD}:/local" works. This answer helped me.

When we run:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/petstore.yml -g typescript-angular -o /local/api/petstore

Docker runs container on openapitools/openapi-generator-cli image. Inside this container, we don't have access to local files. To fix this we need to use -v [localDir]:[containerDir]. Now you can use the contents of localDir inside the container by using containerDir folder.

I hope this makes sense.

Yura Demkiv
  • 346
  • 2
  • 8