Documentation
¶
Overview ¶
Package idents holds the Go-identifier conversion helpers used by both the semantic analyser and the codegen pass. Keeping it here - instead of inside codegen - lets semantic detect "user_id and userId map to the same Go field name" collisions during analysis without pulling in the rest of codegen.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileName ¶ added in v1.5.1
FileName renders a DSL identifier as a generated file/directory name in the requested case: "snake" → `create_user`, "camel" → `createUser`, anything else (including "kebab" and "") → `create-user`. It uses the same SplitFieldName word-splitting as KebabCase, so the default stays byte-for- byte identical to KebabCase; only the join changes. Callers pass the value of `output.fileCase`.
func FileNameWords ¶ added in v1.5.1
FileNameWords joins pre-split words into a file/directory name under the given case. It backs FileName and lets callers append a literal suffix word (e.g. "middleware") so the separator between it and the name follows the same case: kebab `auth-middleware`, snake `auth_middleware`, camel `authMiddleware`.
func GoFieldName ¶
GoFieldName converts a DSL field name (which is allowed to be lowercase, snake_case, or camelCase) into an exported Go identifier applying the common-initialism rule.
Hot path (called per field across codegen + collision detection): Builder keeps the per-part append allocation-free.
func KebabCase ¶ added in v1.2.0
KebabCase lowercases each word SplitFieldName yields and joins them with `-`. It is the one word-splitting rule for kebab output (route segments, generated file names) so the analyser's pathless-method route and the route codegen registers cannot disagree: `ListV2Items` → `list-v2items`, `GetUser` → `get-user`. A digit→letter boundary is NOT a word break, so `V2Items` stays one word - unlike a hand-rolled camel walker that splits before any uppercase whose next rune is lowercase.
func LastSegment ¶ added in v1.4.0
LastSegment returns the trailing slash-delimited segment of a DSL import path - the piece that becomes the package's referencing identifier (`import "auth/types"` → alias `types`). Returns p unchanged when it has no slash, and "" for an empty or slash-terminated path.
func SplitFieldName ¶
SplitFieldName breaks a name into word components on `_`, `-`, and camelCase boundaries. Consecutive uppercase letters are kept together as a single acronym word (so `DBError` → `["DB", "Error"]` and `HTTPRequest` → `["HTTP", "Request"]`); a new word starts whenever an uppercase letter follows a lowercase letter, OR when an uppercase letter sits between two other uppercase letters and is followed by a lowercase letter (the "acronym ends here" boundary).
Exported so callers outside this package (codegen path / error helpers) can derive their own kebab / snake forms without duplicating the boundary logic.
Types ¶
type Collision ¶
type Collision struct {
// DSLNames are the DSL spellings, in source order, that all
// converted to the same canonical Go identifier.
DSLNames []string
// CanonicalGoName is the Go identifier the first DSL name maps
// to - the "winner" that keeps its bare spelling.
CanonicalGoName string
// ResolvedGoNames pairs each DSLName index with the Go
// identifier emitted in the generated struct: index 0 is the
// canonical name; indices ≥ 1 carry the `_N` disambiguator.
ResolvedGoNames []string
}
Collision records one DSL → Go-identifier mapping inside a group of names that produced the same Go identifier under GoFieldName. The first occurrence keeps the bare Go name; subsequent ones are suffixed `_2`, `_3`, ... so the resulting struct compiles. Both the original and the resolved Go names are returned so callers (semantic warnings + codegen) stay consistent on what spelling each DSL name maps to in the emitted struct.
func DedupGoFieldNames ¶
DedupGoFieldNames takes the DSL field names of a single struct in source order and returns:
- resolved: the Go identifiers to emit in the struct, with `_N` suffixes appended to any duplicate beyond the first occurrence.
- collisions: one Collision per group whose size is > 1, in source-order of the first occurrence. Empty when the struct is collision-free, which is the overwhelming common case.
The dedup keeps the first DSL spelling at its bare Go name so a project that adds a colliding alias later doesn't retroactively rename the original field - generated code stays stable for already-published struct shapes.