Skip to main content

Module type_mapping

Module type_mapping 

Source
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 to String to recover plain String.
  • MappedType carries the Rust type plus an optional #[serde(with = "...")] codec hint. Codec hints flow through SchemaType::Primitive to the field-emission site in generator.rs, which wraps them in a #[serde(with = …)] attribute.
  • UsedFeatures tracks which optional crates the mapper actually emitted references to. Q2.8 will read this after generation and write a REQUIRED_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.
MappedType
Result of mapping an OpenAPI (type, format) pair to a Rust type.
TypeConstraintsConfig
TypeEnumsConfig
TypeMapper
TypeMappingConfig
Configuration for TypeMapper. Mirrors the [generator.types] TOML section. Defaults flip on every common typed scalar; opt out per format by setting the strategy to string in TOML.
TypeShapeConfig
UsedFeatures
Tracks which optional crates the generator emitted code for.

Enums§

BinaryStrategy
Strategy for format: binary (raw octets).
ByteStrategy
Strategy for format: byte (base64-encoded binary on the wire).
ConstraintMode
Q2.4 — what to emit for OpenAPI constraint keywords (minimum/maximum/minLength/maxLength/pattern/etc.).
DateStrategy
Strategy for format: date-time | date | time.
DurationStrategy
Strategy for format: duration (ISO 8601 durations).
EmailStrategy
Strategy for format: email.
IpStrategy
Strategy for format: ipv4 | ipv6.
TypeFeature
Identifies an optional crate a mapping introduced.
UriStrategy
Strategy for format: uri | url.
UuidStrategy
Strategy for format: uuid (or normalized aliases).

Functions§

collect_dep_requirements
Snapshot a UsedFeatures set as a sorted, de-duplicated list of DepRequirements. Sorting by crate name keeps the emitted file deterministic so it can be checked in or diffed.
render_required_deps_toml
Render REQUIRED_DEPS.toml content from a sorted set of requirements. Returns None when the input is empty so the caller can skip writing the file (no clutter when no optional crates were used).