nori/codegen/naming
Identifier naming shared by every Gleam generator.
This existed as five separate copies, one per generator, which only
happened to agree. They do not have independent behaviour to have: a schema
name becomes a type in types.gleam and a cross-module call like
types.<name>_decoder() in client.gleam, so any drift between two copies
produces a call to a function that was never generated.
Values
pub fn doc_comment(description: String) -> String
A description as a Gleam doc comment, one /// per line.
⚠️ Prefixing only the first line leaves the rest as bare text, and the
generated module does not parse — a spec is free to use a YAML block scalar
for a description, and several do. Trailing blank lines are dropped so the
comment does not end with a stray ///.
pub fn to_pascal_case(name: String) -> String
Convert a snake_case or camelCase name to PascalCase.
gleam_routes emits the Route variants and gleam_middleware matches on them, so this has the same must-agree property as to_snake_case.
pub fn to_snake_case(name: String) -> String
Convert a PascalCase, camelCase, hyphenated, or dotted name to snake_case.
Names arrive straight from the spec, where “X-Request-Id”, “api.key” and “Order_Item” are all legal; every character that cannot appear in a Gleam identifier becomes an underscore.
Runs of underscores are left alone. Collapsing them would be prettier but buys nothing, and every caller has to agree character for character.
pub fn to_type_name(name: String) -> String
Turn a schema name into a Gleam type name.
Schema names are [a-zA-Z0-9._-]+ in OpenAPI, but a Gleam type name is
letters and digits only and must start with an uppercase letter. “Order_Item”
is a legal schema name that generates pub type Order_Item, which does not
parse.
Every reference to the type has to route through here too, or the definition and its uses end up with different names.