renderer

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseTemplateDir = "templates"
)

Functions

func ClearCache

func ClearCache()

ClearCache clears the template cache

func GetCacheSize

func GetCacheSize() int

GetCacheSize returns the current cache size

Types

type FieldInfo

type FieldInfo struct {
	Name       string
	FieldPath  string // Full path for nested fields (e.g., "user.address.street")
	Order      int
	Schema     *jsonschema.Schema
	IsRequired bool
	Validation ValidationInfo // Add validation information
}

FieldInfo represents metadata for a field extracted from JSONSchema

type FormConfig

type FormConfig struct {
	Class   string
	Action  string
	Method  string
	Enctype string
}

FormConfig holds cached form configuration

type GroupInfo

type GroupInfo struct {
	Title      GroupTitle
	Fields     []FieldInfo
	GroupClass string
}

GroupInfo represents metadata for a group extracted from JSONSchema

type GroupTitle

type GroupTitle struct {
	Text  string
	Class string
}

GroupTitle represents the title configuration for a group

type JSONSchemaRenderer

type JSONSchemaRenderer struct {
	Schema     *jsonschema.Schema
	HTMLLayout string
	// contains filtered or unexported fields
}

JSONSchemaRenderer is responsible for rendering HTML fields based on JSONSchema

func GetFromFile

func GetFromFile(schemaPath, template string, templateFiles ...string) (*JSONSchemaRenderer, error)

func NewJSONSchemaRenderer

func NewJSONSchemaRenderer(schema *jsonschema.Schema, htmlLayout string) *JSONSchemaRenderer

NewJSONSchemaRenderer creates a new instance of JSONSchemaRenderer

func (*JSONSchemaRenderer) RenderFields

func (r *JSONSchemaRenderer) RenderFields(data map[string]any) (string, error)

RenderFields generates HTML for fields based on the JSONSchema

type RequestSchemaTemplate

type RequestSchemaTemplate struct {
	Schema   *jsonschema.Schema  `json:"schema"`
	Renderer *JSONSchemaRenderer `json:"template"`
}

func GetFromBytes

func GetFromBytes(schemaContent []byte, template string, templateFiles ...string) (*RequestSchemaTemplate, error)

type ValidationInfo

type ValidationInfo struct {
	// Basic validations
	Required      bool
	MinLength     *float64
	MaxLength     *float64
	Minimum       *jsonschema.Rat
	Maximum       *jsonschema.Rat
	Pattern       string
	Format        string
	Enum          []interface{}
	MultipleOf    *jsonschema.Rat
	ExclusiveMin  *jsonschema.Rat
	ExclusiveMax  *jsonschema.Rat
	MinItems      *float64
	MaxItems      *float64
	UniqueItems   bool
	MinProperties *float64
	MaxProperties *float64
	Const         interface{}

	// Advanced JSON Schema 2020-12 validations
	AllOf                 []*jsonschema.Schema
	AnyOf                 []*jsonschema.Schema
	OneOf                 []*jsonschema.Schema
	Not                   *jsonschema.Schema
	If                    *jsonschema.Schema
	Then                  *jsonschema.Schema
	Else                  *jsonschema.Schema
	DependentSchemas      map[string]*jsonschema.Schema
	DependentRequired     map[string][]string
	PrefixItems           []*jsonschema.Schema
	Items                 *jsonschema.Schema
	Contains              *jsonschema.Schema
	MaxContains           *float64
	MinContains           *float64
	UnevaluatedItems      *jsonschema.Schema
	UnevaluatedProperties *jsonschema.Schema
	PropertyNames         *jsonschema.Schema
	AdditionalProperties  *jsonschema.Schema
	PatternProperties     *jsonschema.SchemaMap

	// Content validations
	ContentEncoding  *string
	ContentMediaType *string
	ContentSchema    *jsonschema.Schema

	// Metadata
	Title       *string
	Description *string
	Default     interface{}
	Examples    []interface{}
	Deprecated  *bool
	ReadOnly    *bool
	WriteOnly   *bool
}

ValidationInfo holds comprehensive validation information for a field

Jump to

Keyboard shortcuts

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