feat: generate rust models from openapi 3 component schemas - #1
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an initial, model-only OpenAPI 3 → Rust codegen pipeline to the oapi-codegen crate, including a CLI, schema lowering + emission, and a comprehensive fixture/golden-based coverage harness to keep OpenAPI feature handling explicit as openapiv3 evolves.
Changes:
- Implemented the load → lower → emit pipeline for component schemas (structs, enums/unions, aliases, refs, formats, additionalProperties, nullable, x-rust-type).
- Added a coverage-matrix test (
tests/coverage.rs) with fixtures + goldens and a compile-check integration test for generated outputs. - Updated repo docs/tooling (README usage/config docs, Makefile target, dependency additions, Copilot formatting guidance).
Reviewed changes
Copilot reviewed 55 out of 56 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents CLI usage, config format, and schema → Rust mapping table. |
| Makefile | Adds an update-golden target to refresh checked-in generated outputs. |
| crates/oapi-codegen/tests/golden/allof_merge.rs | New golden output for allOf merge behavior. |
| crates/oapi-codegen/tests/golden/anyof_untagged.rs | New golden output for anyOf untagged unions. |
| crates/oapi-codegen/tests/golden/array_types.rs | New golden output for arrays (scalars, refs, nested arrays). |
| crates/oapi-codegen/tests/golden/ext_x_rust_type.rs | New golden output for x-rust-type overrides. |
| crates/oapi-codegen/tests/golden/freeform_any.rs | New golden output for free-form schemas ({}) as serde_json::Value. |
| crates/oapi-codegen/tests/golden/integer_formats.rs | New golden output for integer format mapping. |
| crates/oapi-codegen/tests/golden/map_alias.rs | New golden output for map aliases via additionalProperties. |
| crates/oapi-codegen/tests/golden/metadata_docs.rs | New golden output for description → rustdoc mapping. |
| crates/oapi-codegen/tests/golden/nullable.rs | New golden output for nullable → Option<T> mapping. |
| crates/oapi-codegen/tests/golden/number_formats.rs | New golden output for number format mapping. |
| crates/oapi-codegen/tests/golden/object_additional_properties.rs | New golden output for additionalProperties alongside fields (flatten). |
| crates/oapi-codegen/tests/golden/object_nested_inline.rs | New golden output for inline nested objects being hoisted. |
| crates/oapi-codegen/tests/golden/object_optional_required.rs | New golden output for required vs optional fields + serde skipping. |
| crates/oapi-codegen/tests/golden/oneof_discriminator.rs | New golden output for discriminator mapping → untagged union. |
| crates/oapi-codegen/tests/golden/oneof_untagged.rs | New golden output for oneOf untagged unions. |
| crates/oapi-codegen/tests/golden/primitive_scalars.rs | New golden output for primitive scalar mappings. |
| crates/oapi-codegen/tests/golden/ref_local.rs | New golden output for local $ref and aliasing. |
| crates/oapi-codegen/tests/golden/string_enum.rs | New golden output for string enums with serde renames. |
| crates/oapi-codegen/tests/golden/string_formats.rs | New golden output for string format mapping (date, date-time, uuid, bytes, etc.). |
| crates/oapi-codegen/tests/generated_compiles.rs | Compile-checks supported goldens against real deps + adds basic serde round-trip tests. |
| crates/oapi-codegen/tests/fixtures/allof_merge.yaml | Fixture exercising allOf merge behavior. |
| crates/oapi-codegen/tests/fixtures/anyof_untagged.yaml | Fixture exercising anyOf behavior. |
| crates/oapi-codegen/tests/fixtures/array_types.yaml | Fixture exercising array typing and nesting. |
| crates/oapi-codegen/tests/fixtures/ext_x_rust_type.yaml | Fixture exercising x-rust-type. |
| crates/oapi-codegen/tests/fixtures/freeform_any.yaml | Fixture exercising {} schemas and free-form fields. |
| crates/oapi-codegen/tests/fixtures/integer_formats.yaml | Fixture exercising integer format mapping. |
| crates/oapi-codegen/tests/fixtures/map_alias.yaml | Fixture exercising map aliases via additionalProperties. |
| crates/oapi-codegen/tests/fixtures/metadata_docs.yaml | Fixture exercising schema/property description doc emission. |
| crates/oapi-codegen/tests/fixtures/nullable.yaml | Fixture exercising nullable. |
| crates/oapi-codegen/tests/fixtures/number_formats.yaml | Fixture exercising number format mapping. |
| crates/oapi-codegen/tests/fixtures/object_additional_properties.yaml | Fixture exercising typed additionalProperties with fields present. |
| crates/oapi-codegen/tests/fixtures/object_nested_inline.yaml | Fixture exercising hoisting of inline nested objects. |
| crates/oapi-codegen/tests/fixtures/object_optional_required.yaml | Fixture exercising required vs optional properties. |
| crates/oapi-codegen/tests/fixtures/oneof_discriminator.yaml | Fixture exercising discriminator mapping handling. |
| crates/oapi-codegen/tests/fixtures/oneof_untagged.yaml | Fixture exercising plain oneOf handling. |
| crates/oapi-codegen/tests/fixtures/primitive_scalars.yaml | Fixture exercising primitive scalar typing. |
| crates/oapi-codegen/tests/fixtures/ref_local.yaml | Fixture exercising local refs and aliases. |
| crates/oapi-codegen/tests/fixtures/string_enum.yaml | Fixture exercising string enums. |
| crates/oapi-codegen/tests/fixtures/string_formats.yaml | Fixture exercising string formats. |
| crates/oapi-codegen/tests/fixtures/unsupported_not.yaml | Fixture ensuring unsupported not is rejected. |
| crates/oapi-codegen/tests/coverage.rs | Coverage matrix + golden regeneration logic + anchor to force exhaustive handling of openapiv3 enum variants. |
| crates/oapi-codegen/src/schema.rs | Schema lowering from openapiv3 into the IR, including unions, allOf merge, and inline type hoisting. |
| crates/oapi-codegen/src/naming.rs | Identifier casing + keyword escaping + serde rename decisions. |
| crates/oapi-codegen/src/main.rs | CLI implementation for generating models to stdout or a file, optionally via config. |
| crates/oapi-codegen/src/loader.rs | Spec loading and $ref resolution helpers. |
| crates/oapi-codegen/src/lib.rs | Public API for generating models (string/file), exporting Config/Error/Result. |
| crates/oapi-codegen/src/ir.rs | IR types representing generated Rust items and type expressions. |
| crates/oapi-codegen/src/error.rs | Error types and Display/source wiring for load/generate/emit errors. |
| crates/oapi-codegen/src/emit.rs | IR → TokenStream → syn parse → prettyplease output emission with stable blank-line separation. |
| crates/oapi-codegen/src/config.rs | Deserializable config compatible with oapi-codegen YAML conventions. |
| crates/oapi-codegen/Cargo.toml | Adds dependencies required by the generator + dev-deps used by compile-check tests. |
| Cargo.lock | Locks the newly introduced crate dependencies. |
| .github/copilot-instructions.md | Codifies blank-line separation between Rust item definitions. |
dotkas
force-pushed
the
dotkas/initial-implementation
branch
from
June 24, 2026 20:36
ef08f8e to
483ff94
Compare
Contributor
|
🎉 This PR is included in version 1.0.0-dev.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Contributor
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.