OpenAPI generator

Submitted by Erik Wegner on

To learn about the topic, you may start reading my blog post.

This tip runs a docker container to generate the files from a specification yaml.

It can be summarized in this shell script:

sudo rm -rf generated
docker run --rm \
--volume="${PWD}/generated:/generated" \
--volume="${PWD}/openapi.yml:/openapi.yml:ro" \
openapitools/openapi-generator-cli:v6.4.0 generate \
--input-spec /openapi.yml \
--generator-name rust-server \
--package-name openapi \
--output /generated
  1. The target directory ./generated is removed.
  2. The container run directory mounts the target directory and the source file into the container.
  3. The container contains the command line version of the generator and writes the files into the target directory.

One thing to note on the rust templates: there are templates called rust and rust-server. The server templates build rust structures with stricter typings, which is good for a server. This emphasizes that any system should be strict about data it produces, but permissive about data it consumes.