ids

package
v0.0.0-...-8d9931c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ids builds the RFC 6901 pointer that names a position — a jsontext.Pointer from construction on, read back through its methods, never split on '/' — and derives IR identifiers and namespaces from it.

The path is OpenAPI's and stays here — a JSON Pointer is not a GraphQL structural path or a protobuf fully-qualified name, and nothing above this package can compute one. The grammar wrapped around it belongs to the framework, which is the only thing this package reaches besides ir.

Index

Constants

View Source
const (
	// OpenAPISpace and AnonSpace both address source coordinates: a component
	// schema is named at its own pointer, an inline schema is anonymous at its
	// own pointer, and no pointer is both.
	OpenAPISpace compile.Space = "openapi"
	AnonSpace    compile.Space = "anon"
	// ComposedSpace holds the Models synthesized for distributed union variants
	// (§4.3) — nodes no schema in the source occupies. The branch pointer denotes
	// the branch schema, so a $ref naming it must keep resolving to the branch,
	// and the variant must not be reachable by any pointer a $ref can spell.
	// ForPointer yields only the openapi and anon spaces, so
	// resolveSchemaRef can never hand a composed ID to a reference; compile.Types
	// rejects the mistake of minting into a space that addresses coordinates.
	ComposedSpace compile.Space = "composed"
)

The namespaces this compiler addresses. The framework spells the grammar around them — the kind prefix and the separators (compile.TypeID and friends); what is chosen here is which namespace a node belongs in, and the pointer that is its path.

Variables

This section is empty.

Functions

func AnonType

func AnonType(pointer jsontext.Pointer) ir.TypeID

AnonType returns the stable ID of a hoisted inline type at pointer.

func Auth

func Auth(name string) ir.AuthID

Auth returns the stable ID of the named security scheme.

func ComponentEntry

func ComponentEntry(pointer jsontext.Pointer) (kind, name string, ok bool)

ComponentEntry returns the kind and name of the top-level component entry pointer addresses (/components/<kind>/<name>, no deeper path), both decoded, and ok=false for any other pointer or for an entry keyed "". componentEntryName drops the kind, and ComponentSchemaName narrows it to the schemas kind, which is the only one that earns a named TypeID.

func ComponentSchemaName

func ComponentSchemaName(pointer jsontext.Pointer) (string, bool)

ComponentSchemaName reports whether pointer addresses a top-level component schema (/components/schemas/<name> with no deeper path) and returns its name. Only this kind of component declares a named type in OpenAPI, which is why it alone gates NamedType.

It answers false for two unlike documents: one that declares no such entry, and one that declares it keyed "". Reporting the refusal as "not a component schema" is false for the second, since the pointer addresses exactly that — ComponentSchemaNamedEmpty separates them for a caller that has to say why.

func ComponentSchemaNamedEmpty

func ComponentSchemaNamedEmpty(pointer jsontext.Pointer) bool

ComponentSchemaNamedEmpty reports whether pointer addresses the top-level component schema keyed "" — the position /components/schemas/ addresses.

It exists because that schema is a component schema that ComponentSchemaName still refuses: an empty name earns no named TypeID, so the schema hoists anonymously (testdata/conformance/openapi/empty-names.yaml records that policy). A caller that reports the refusal needs the distinction to word it truthfully, since a reader who follows the pointer finds a component schema sitting exactly where a "not a component schema" message denies one is.

func ComposedType

func ComposedType(branchPointer jsontext.Pointer) ir.TypeID

ComposedType returns the stable ID of the Model synthesized for the distributed union variant at a branch pointer (§4.3).

func DeclarationHint

func DeclarationHint(pointer jsontext.Pointer, fallback string) string

DeclarationHint returns the name hint a node hoisted under pointer should carry: the component's own name when pointer addresses a top-level component entry, else fallback. A $ref'd component lowers once, at its declaration, so a use-site-derived hint (the referencing operation's ID, a response header's map key) would name the one shared node after whichever reference happened to lower first — arbitrary, and emitter-visible via Naming.Hint (issue #107).

func ForPointer

func ForPointer(pointer jsontext.Pointer) ir.TypeID

ForPointer returns the stable TypeID for a schema hoisted at pointer: the named-component ID for a top-level component schema, the anonymous (hoisted-inline) ID otherwise.

func NamedType

func NamedType(pointer jsontext.Pointer) ir.TypeID

NamedType returns the stable ID of a components-named schema at pointer.

func Op

func Op(pointer jsontext.Pointer) ir.OpID

Op returns the stable ID of the operation at pointer.

func Prop

func Prop(pointer jsontext.Pointer) ir.PropID

Prop returns the stable ID of the property at pointer.

func Ptr

func Ptr(tokens ...string) jsontext.Pointer

Ptr joins tokens into an RFC 6901 JSON pointer, escaping each one. IDs are derived from the pointers it builds (ir-design §3.1); the grammar wrapped around a pointer to make an ID belongs to the framework.

A position beneath another is base + Ptr(tokens...): joining two valid pointers yields a valid pointer, so extending one never takes it apart.

AppendToken rewrites a byte that is not UTF-8 to U+FFFD, which would give two keys differing only there one pointer. No token read from a document can carry one: a source that is not UTF-8 is refused before anything lowers.

func Scope

func Scope(segments ...string) string

Scope joins segments into an Unmodeled key scope: Ptr's escaping without the leading separator, since a scope is a relative path rather than a pointer (ir-design §12).

It exists for the scopes holding a segment the document chooses — a form part's name, a callback's — where an unescaped "/" makes one segment read as two. Two parts named "q" and "q/x-a" then wrote one key between them and the surviving entry followed declaration order, silently, which is what §4.3 forbids a minted node and §12 promises a scoped key.

func Service

func Service(sourceIndex int) ir.ServiceID

Service returns the stable ID of the service for the given source index.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL