oaspec/openapi/dedup
Values
pub fn dedup(
spec: spec.OpenApiSpec(stage),
) -> spec.OpenApiSpec(stage)
Deduplicate names within schemas to avoid collisions in generated code. This is a pre-processing pass that runs after hoisting and before validation.
Scope is intentionally limited: operationId / function-name uniqueness is
enforced by oaspec/codegen/validate.gleam with a hard error, not by a
silent rename, because renaming mutates the generated public API surface
without telling the user (see issue #237). Property name and enum variant
deduplication is done at codegen time via dedup_property_names/1 and
dedup_enum_variants/1 to preserve JSON wire names.
pub fn dedup_enum_variants(
enum_values: List(String),
) -> List(String)
Given a list of original enum values (JSON wire values), return a list of deduped PascalCase Gleam variant suffixes. The returned list is parallel to the input.
pub fn dedup_param_field_names(
params: List(spec.Parameter(stage)),
) -> List(String)
Given the parameters of a single operation, return a parallel list of
deduped snake_case Gleam field names. Parameters whose wire names map to
the same snake_case field (e.g. id in path AND id in query) get the
same _2/_3 suffix treatment used for property names. The reserved
label body is taken first so a parameter literally named body is
renamed instead of clashing with the request type’s body field.
The function is order-sensitive: the first occurrence keeps its base snake_case form, later occurrences get the suffix. Pass the parameters in the same order the spec lists them so type emission, server dispatch, and client builder agree on the final field name.
pub fn dedup_property_names(
prop_names: List(String),
) -> List(String)
Given a list of original property names (JSON wire names), return a list of deduped snake_case Gleam field names. The returned list is parallel to the input: result[i] is the Gleam name for input[i].