Skip to content

openapi-codegen: complete QUERY fallback and cross-language schema types - #66

Open
chrischeng-c4 wants to merge 1 commit into
mainfrom
issue/34
Open

chrischeng-c4 wants to merge 1 commit into
mainfrom
issue/34

Conversation

@chrischeng-c4

Copy link
Copy Markdown
Contributor

Closes #34

Summary of Changes

Implements the first slice of #34 for crates/openapi-codegen:

  • crates/openapi-codegen/src/domain/emit/rust/models_emit.rs:
    • Added is_string_enum to identify component schemas eligible for Rust enum generation (type: string, non-empty all-string enum, empty properties/unions).
    • Added emit_enum to emit #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Name { ... } with #[serde(rename = "<value>")] on each variant and PascalCase variant names via to_pascal, preserving declared order.
    • Implemented deterministic disambiguation using NameRegistry for colliding variant names (e.g. FooBar, FooBar_2) and non-identifier values ("" -> Anonymous, "123" -> _123, "self" -> Self_).
    • Preserved existing behavior for untyped, non-string, and inline enums, which continue mapping to String.
  • crates/openapi-codegen/src/domain/emit/rust/rsmap.rs:
    • Added unit test asserting that inline string enums, non-string enums, and nullable inline enums remain String / Option<String>.
  • crates/openapi-codegen/src/domain/emit/rust.rs:
    • Added integration unit test emits_string_enum_component_model verifying models.rs generation for string enum component schemas with struct $ref.

Local Validation Results

  1. Cancelled Broad Package Test:

    • Earlier unconstrained cargo test --locked -p openapi-codegen hung on background network TLS test domain::emit::py::tests::tls_alpn::generated_python_h2_runtime_negotiates_tls_alpn_h2 and was terminated via supported manage_task(Action=kill) per local testing policy (Task 0297a583-9bab-44e1-a787-5e6e80d8ff75/task-96). This broad package test is NOT RUN locally and left to cloud CI.
  2. Affected Isolated Unit Tests (PASSED):

    • cargo test --locked -p openapi-codegen --lib domain::emit::rust (19 passed, 0 failed):
      • declared_order: passed
      • rename_non_identifier_values: passed
      • collision_disambiguation: passed
      • nullable_enum_emits_same_enum: passed
      • struct_property_refs_enum: passed
      • non_string_enum_left_as_string: passed
      • serde_round_trip_rejects_undeclared_value: passed
      • inline_and_non_string_enums_stay_string: passed
      • emits_string_enum_component_model: passed
      • All 10 existing Rust emitter unit tests passed.
    • Unaffected TS and IR unit tests:
      • domain::emit::ts (27 passed)
      • domain::emit::py::models_emit (1 passed)
      • domain::emit::py::pymap (1 passed)
      • domain::ir (14 passed)
  3. Negative Control:

    • Reverting emit_schema to the type-alias branch caused exactly the 6 new enum test rows to fail while all other rows passed.
  4. Formatting:

    • cargo fmt --check -p openapi-codegen passed cleanly.

Cloud CI Requirements

  • Cloud MR Checks: Unfiltered package tests, server/network/h2c integration suites, and cross-language profile gates belong in cloud CI.
  • Status: PENDING / NOT RUN locally awaiting authorized cloud CI execution on the opened PR.

…emas

Emit #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Name
for top-level component schemas with type: string and a non-empty all-string enum.
Each variant gets #[serde(rename = "<value>")] preserving wire values, with
PascalCase variant names via to_pascal. Disambiguate colliding variants and
non-identifier values deterministically, and preserve String fallback for untyped,
non-string, and inline enums.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openapi-codegen: complete QUERY fallback and cross-language schema types

1 participant