Skip to content

Latest commit

 

History

History
46 lines (29 loc) · 2.04 KB

File metadata and controls

46 lines (29 loc) · 2.04 KB

oapi-codegen CLI reference

This document contains the help content for the oapi-codegen command-line program.

oapi-codegen

Generate client and server boilerplate from OpenAPI 3 specifications

Usage: oapi-codegen [OPTIONS] --config-file <CONFIG_FILE> <SPEC_FILE>

Examples:

Write generated code. Select artifacts in the configuration file:

oapi-codegen --config-file oapi-codegen.yaml --output-file src/api.rs api.yaml

You can also set output with the output: configuration key:

oapi-codegen --config-file oapi-codegen.yaml api.yaml

You must provide a configuration file. The configuration file must enable at least one artifact. You must set output with --output-file or the output: configuration key:

oapi-codegen.yaml

output: src/api.rs generate: models: true std-http-server: true client: true

Arguments:
  • <SPEC_FILE> — Path to the OpenAPI 3 specification (YAML or JSON)
Options:
  • -c, --config-file <CONFIG_FILE> — Path to an oapi-codegen YAML configuration file (required)

  • -o, --output-file <OUTPUT_FILE> — Output file path (overrides configuration output:). Required unless the configuration sets output:

  • --check — Compare the generated code with the output file, and write nothing.

    The exit code is 0 when the output file holds the generated code. The exit code is 1 when the file differs, or when the file is absent. Use this in continuous integration to make stale output a failed build. This flag reports no dependencies, because it adds none.

  • --install-deps — After the write, run cargo add for each required crate.

    If set, this runs with no prompt. If stdin is interactive and the flag is not set, the CLI asks first. If stdin is not interactive and the flag is not set, the CLI prints only the list. cargo add targets the package whose Cargo.toml is nearest output. It merges with an existing declaration. A crate that already exists is updated in place.