schema

package
v0.0.0-...-952df67 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name      string
	Generator string
	Args      map[string]interface{}
}

Field represents a data field to generate

type GeneratorParams

type GeneratorParams map[string]interface{}

GeneratorParams contains parameters for field generation

type PropertySchema

type PropertySchema struct {
	Type            string                    `json:"type"`
	Format          string                    `json:"format,omitempty"`
	Description     string                    `json:"description,omitempty"`
	Generator       string                    `json:"x-generator,omitempty"`
	GeneratorParams GeneratorParams           `json:"x-generator-params,omitempty"`
	Properties      map[string]PropertySchema `json:"properties,omitempty"`
	Items           *PropertySchema           `json:"items,omitempty"`
	GeneratorCount  int                       `json:"x-generator-count,omitempty"`
}

PropertySchema defines a single property in the schema

type Registry

type Registry struct {
	Schemas map[string]*Schema
}

Registry holds all loaded schemas

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new schema registry

func (*Registry) GenerateData

func (r *Registry) GenerateData(resourceName string, count int) ([]map[string]interface{}, error)

GenerateData generates fake data for a resource

func (*Registry) GetAllResourceNames

func (r *Registry) GetAllResourceNames() []string

GetAllResourceNames returns all registered resource names

func (*Registry) GetRouteAliases

func (r *Registry) GetRouteAliases(resourceName string) []string

GetRouteAliases returns additional paths for a resource

func (*Registry) GetRouteMethods

func (r *Registry) GetRouteMethods(resourceName string) []string

GetRouteMethods returns allowed methods for a resource (defaults to ["GET"])

func (*Registry) GetRoutePath

func (r *Registry) GetRoutePath(resourceName string) string

GetRoutePath returns the custom path or default path for a resource

func (*Registry) GetSchema

func (r *Registry) GetSchema(resourceName string) (*Schema, bool)

GetSchema retrieves a schema by resource name

func (*Registry) LoadEmbeddedSchemas

func (r *Registry) LoadEmbeddedSchemas() error

LoadEmbeddedSchemas loads all schemas from embedded files

func (*Registry) LoadSchema

func (r *Registry) LoadSchema(path string) error

LoadSchema loads a single schema file

func (*Registry) LoadSchemas

func (r *Registry) LoadSchemas(schemasDir string) error

LoadSchemas loads all schemas from the shared/schemas directory

func (*Registry) SchemaToFields

func (r *Registry) SchemaToFields(schema *Schema) []Field

SchemaToFields converts a schema into generator field definitions

func (*Registry) SupportsMethod

func (r *Registry) SupportsMethod(resourceName string, method string) bool

SupportsMethod checks if a resource supports a specific HTTP method

type ResourceMetadata

type ResourceMetadata struct {
	Name        string       `json:"name"`
	Singular    string       `json:"singular"`
	Description string       `json:"description"`
	Routes      *RouteConfig `json:"routes,omitempty"` // Custom route configuration
}

ResourceMetadata contains information about the resource

type RouteConfig

type RouteConfig struct {
	Path    string   `json:"path,omitempty"`    // Custom path (e.g., "/v1/users")
	Methods []string `json:"methods,omitempty"` // Allowed methods ["GET", "POST", etc.]
	Aliases []string `json:"aliases,omitempty"` // Additional paths for this resource
}

RouteConfig defines custom route configuration

type Schema

type Schema struct {
	SchemaURI   string                    `json:"$schema"`
	Type        string                    `json:"type"`
	Title       string                    `json:"title"`
	Description string                    `json:"description,omitempty"`
	Resource    ResourceMetadata          `json:"x-resource"`
	Properties  map[string]PropertySchema `json:"properties"`
	Required    []string                  `json:"required,omitempty"`
}

Schema represents a JSON Schema with our custom extensions

Jump to

Keyboard shortcuts

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