extensions

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

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

func LoadBuiltins(registry *Registry) error

LoadBuiltins registers the embedded built-in vendor extension schemas.

func LoadDir

func LoadDir(dir string, registry *Registry, logger *slog.Logger) error

LoadDir reads all .json files from the given directory and registers them as extension definitions in the registry.

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 NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty extension registry.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered extensions.

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

func (r *Registry) IsRegistered(name string) bool

IsRegistered returns whether an extension name is known to the registry.

func (*Registry) IsRequired

func (r *Registry) IsRequired(name string) bool

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

func (r *Registry) SetRequired(names []string)

SetRequired marks extension names that must be present where scoped.

func (*Registry) ValidAtScope

func (r *Registry) ValidAtScope(name string, scope Scope) bool

ValidAtScope returns whether the named extension is valid at the given scope.

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"
)

Jump to

Keyboard shortcuts

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