scaffold

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateScaffold

func GenerateScaffold(outDir string, data Data) error

GenerateScaffold writes all scaffold files to outDir.

func GenerateToZip

func GenerateToZip(data Data) ([]byte, error)

GenerateToZip generates scaffold files and writes them to a zip archive in memory. Returns the zip bytes. Each file is stored as "ui/<path>" inside the zip.

Types

type APIOperation

type APIOperation struct {
	FuncName   string // e.g. "getUsers"
	Method     string // "GET"
	Path       string // "/api/v1/users"
	HasBody    bool
	PathParams []string
}

APIOperation is a parsed API operation for template use.

type Data

type Data struct {
	Title        string
	Version      string
	Theme        string
	HasAuth      bool
	LoginPath    string
	RegisterPath string
	Resources    []ResourceGroup
	Operations   []APIOperation
	// Auth-specific operation paths
	LoginOp    *APIOperation
	RegisterOp *APIOperation
}

Data is the top-level data passed to all templates.

func AnalyzeOnly

func AnalyzeOnly(specJSON []byte, opts Options) (*Data, error)

AnalyzeOnly parses an OpenAPI spec and returns analysis data. This is used by the UI to show a preview without generating files.

func AnalyzeSpec

func AnalyzeSpec(spec *Spec, opts Options) *Data

AnalyzeSpec extracts resources, operations, and auth info from the spec.

type FormField

type FormField struct {
	Name     string
	Label    string
	Type     string // "text", "email", "password", "number", "select"
	Required bool
	Options  []string // for select type
}

FormField describes a field in a generated form.

type Options

type Options struct {
	Title    string
	Theme    string // "light" or "dark"
	Auth     bool   // force auth on/off (auto-detected if not set)
	BasePath string // API base path prefix
}

Options configures scaffold generation.

type ResourceGroup

type ResourceGroup struct {
	Name       string // e.g. "Users"
	NameLower  string // e.g. "users"
	NamePlural string // e.g. "users"
	ListOp     *APIOperation
	DetailOp   *APIOperation
	CreateOp   *APIOperation
	UpdateOp   *APIOperation
	DeleteOp   *APIOperation
	FormFields []FormField
}

ResourceGroup groups related operations under a resource name.

type Spec

type Spec struct {
	Info       SpecInfo             `json:"info" yaml:"info"`
	Paths      map[string]*SpecPath `json:"paths" yaml:"paths"`
	Components *SpecComponents      `json:"components,omitempty" yaml:"components,omitempty"`
}

Spec mirrors the subset of OpenAPI 3.0 we need for scaffolding.

func ParseSpec

func ParseSpec(data []byte) (*Spec, error)

ParseSpec parses a JSON or YAML OpenAPI spec from bytes.

type SpecComponents

type SpecComponents struct {
	Schemas map[string]*SpecSchema `json:"schemas,omitempty" yaml:"schemas,omitempty"`
}

SpecComponents holds the components section of an OpenAPI spec.

type SpecInfo

type SpecInfo struct {
	Title       string `json:"title" yaml:"title"`
	Version     string `json:"version" yaml:"version"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

SpecInfo holds the info block of an OpenAPI spec.

type SpecOp

type SpecOp struct {
	OperationID string       `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Summary     string       `json:"summary,omitempty" yaml:"summary,omitempty"`
	Tags        []string     `json:"tags,omitempty" yaml:"tags,omitempty"`
	Parameters  []SpecParam  `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody *SpecReqBody `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
}

SpecOp describes a single operation in a path.

type SpecParam

type SpecParam struct {
	Name string `json:"name" yaml:"name"`
	In   string `json:"in" yaml:"in"`
}

SpecParam describes a parameter in an operation.

type SpecPath

type SpecPath struct {
	Get    *SpecOp `json:"get,omitempty" yaml:"get,omitempty"`
	Post   *SpecOp `json:"post,omitempty" yaml:"post,omitempty"`
	Put    *SpecOp `json:"put,omitempty" yaml:"put,omitempty"`
	Delete *SpecOp `json:"delete,omitempty" yaml:"delete,omitempty"`
	Patch  *SpecOp `json:"patch,omitempty" yaml:"patch,omitempty"`
}

SpecPath holds the operations for a single path.

type SpecReqBody

type SpecReqBody struct {
	Content map[string]*specMediaType `json:"content,omitempty" yaml:"content,omitempty"`
}

SpecReqBody describes the request body of an operation.

type SpecSchema

type SpecSchema struct {
	Ref        string                 `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Type       string                 `json:"type,omitempty" yaml:"type,omitempty"`
	Properties map[string]*SpecSchema `json:"properties,omitempty" yaml:"properties,omitempty"`
	Required   []string               `json:"required,omitempty" yaml:"required,omitempty"`
	Enum       []string               `json:"enum,omitempty" yaml:"enum,omitempty"`
	Format     string                 `json:"format,omitempty" yaml:"format,omitempty"`
}

SpecSchema describes a JSON schema.

Jump to

Keyboard shortcuts

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