Expand description
Centralized OpenAPI type → Rust type mapping.
TypeMapper is the single chokepoint for every (openapi_type, format) → Rust-type decision. Q2.0 introduced the chokepoint with
pass-through behavior; Q2 (quq) flips the defaults so common string
formats (date-time, uuid, uri, …) become typed Rust scalars
out of the box.
§Design
- Per-format strategy enums (e.g.
DateStrategy) drive the mapping. Defaults are opt-out: typed by default, set the strategy toStringto recover plainString. MappedTypecarries the Rust type plus an optional#[serde(with = "...")]codec hint. Codec hints flow throughSchemaType::Primitiveto the field-emission site ingenerator.rs, which wraps them in a#[serde(with = …)]attribute.UsedFeaturestracks which optional crates the mapper actually emitted references to. Q2.8 will read this after generation and write aREQUIRED_DEPS.toml.
§Conservative mode
Pass TypeMappingConfig::conservative() (CLI: --types-conservative)
to recover pre-Q2 behavior — every format renders as String. Useful
for bisecting regressions caused by typed-scalar adoption.
Structs§
- DepRequirement
- One crate the generated code needs in its
Cargo.toml. - Mapped
Type - Result of mapping an OpenAPI
(type, format)pair to a Rust type. - Type
Constraints Config - Type
Enums Config - Type
Mapper - Type
Mapping Config - Configuration for
TypeMapper. Mirrors the[generator.types]TOML section. Defaults flip on every common typed scalar; opt out per format by setting the strategy tostringin TOML. - Type
Shape Config - Used
Features - Tracks which optional crates the generator emitted code for.
Enums§
- Binary
Strategy - Strategy for
format: binary(raw octets). - Byte
Strategy - Strategy for
format: byte(base64-encoded binary on the wire). - Constraint
Mode - Q2.4 — what to emit for OpenAPI constraint keywords
(
minimum/maximum/minLength/maxLength/pattern/etc.). - Date
Strategy - Strategy for
format: date-time | date | time. - Duration
Strategy - Strategy for
format: duration(ISO 8601 durations). - Email
Strategy - Strategy for
format: email. - IpStrategy
- Strategy for
format: ipv4 | ipv6. - Type
Feature - Identifies an optional crate a mapping introduced.
- UriStrategy
- Strategy for
format: uri | url. - Uuid
Strategy - Strategy for
format: uuid(or normalized aliases).
Functions§
- collect_
dep_ requirements - Snapshot a
UsedFeaturesset as a sorted, de-duplicated list ofDepRequirements. Sorting by crate name keeps the emitted file deterministic so it can be checked in or diffed. - render_
required_ deps_ toml - Render
REQUIRED_DEPS.tomlcontent from a sorted set of requirements. ReturnsNonewhen the input is empty so the caller can skip writing the file (no clutter when no optional crates were used).