Documentation
¶
Overview ¶
Package extensions provides a framework for validating OpenAPI vendor extensions (x-* properties) against JSON Schema definitions. Extensions can be scoped to specific OpenAPI constructs (operations, schemas, etc.) and are loaded from .telescope/extensions/ or embedded as built-in vendor extension schemas.
Index ¶
- Variables
- func Analyzer(registry *Registry) treesitter.Analyzer
- func LoadBuiltins(registry *Registry) error
- func LoadDir(dir string, registry *Registry, logger *slog.Logger) error
- type CompiledExtension
- type ExtensionFile
- type ExtensionMeta
- type Registry
- func (r *Registry) Count() int
- func (r *Registry) Get(name string) (*CompiledExtension, bool)
- func (r *Registry) GetForScope(scope Scope) []*CompiledExtension
- func (r *Registry) IsRegistered(name string) bool
- func (r *Registry) IsRequired(name string) bool
- func (r *Registry) Register(meta ExtensionMeta) error
- func (r *Registry) RequiredForScope(scope Scope) []*CompiledExtension
- func (r *Registry) SetRequired(names []string)
- func (r *Registry) ValidAtScope(name string, scope Scope) bool
- type Scope
Constants ¶
This section is empty.
Variables ¶
var AllScopes = []Scope{ ScopeRoot, ScopeInfo, ScopePaths, ScopePathItem, ScopeOperation, ScopeParameter, ScopeSchema, ScopeResponse, ScopeRequestBody, ScopeComponents, ScopeHeader, ScopeMediaType, ScopeSecurityScheme, ScopeTag, ScopeServer, }
AllScopes lists every known scope except ScopeAny (which matches all).
Functions ¶
func Analyzer ¶
func Analyzer(registry *Registry) treesitter.Analyzer
Analyzer creates a treesitter.Analyzer that validates x-* extensions in OpenAPI documents against the registry.
func LoadBuiltins ¶
LoadBuiltins registers the embedded built-in vendor extension schemas.
Types ¶
type CompiledExtension ¶
type CompiledExtension struct {
Meta ExtensionMeta
SchemaData map[string]interface{}
}
CompiledExtension pairs an extension definition with its parsed JSON Schema.
type ExtensionFile ¶
type ExtensionFile struct {
Name string `json:"name"`
Scopes []Scope `json:"scope"`
Description string `json:"description"`
Schema json.RawMessage `json:"schema"`
}
ExtensionFile is the on-disk format for .telescope/extensions/*.json.
type ExtensionMeta ¶
type ExtensionMeta struct {
Name string `json:"name"`
Scopes []Scope `json:"scope"`
Description string `json:"description"`
Schema json.RawMessage `json:"schema"`
}
ExtensionMeta describes a single registered extension and its JSON Schema.
func BuiltinExtensions ¶
func BuiltinExtensions() []ExtensionMeta
BuiltinExtensions returns a copy of the embedded extension definitions.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all registered extension definitions and provides lookup by scope and extension name.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (*CompiledExtension, bool)
Get returns a single extension by name.
func (*Registry) GetForScope ¶
func (r *Registry) GetForScope(scope Scope) []*CompiledExtension
GetForScope returns all extensions registered for the given scope.
func (*Registry) IsRegistered ¶
IsRegistered returns whether an extension name is known to the registry.
func (*Registry) IsRequired ¶
IsRequired returns whether the named extension is required.
func (*Registry) Register ¶
func (r *Registry) Register(meta ExtensionMeta) error
Register adds an extension definition to the registry.
func (*Registry) RequiredForScope ¶
func (r *Registry) RequiredForScope(scope Scope) []*CompiledExtension
RequiredForScope returns extensions that are required for the given scope.
func (*Registry) SetRequired ¶
SetRequired marks extension names that must be present where scoped.
type Scope ¶
type Scope string
Scope identifies where in an OpenAPI document an extension is valid.
const ( ScopeRoot Scope = "root" ScopeInfo Scope = "info" ScopePaths Scope = "paths" ScopePathItem Scope = "pathItem" ScopeOperation Scope = "operation" ScopeParameter Scope = "parameter" ScopeSchema Scope = "schema" ScopeResponse Scope = "response" ScopeRequestBody Scope = "requestBody" ScopeComponents Scope = "components" ScopeHeader Scope = "header" ScopeMediaType Scope = "mediaType" ScopeSecurityScheme Scope = "securityScheme" ScopeTag Scope = "tag" ScopeServer Scope = "server" ScopeAny Scope = "any" )