codegen

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldID        = "id"
	FieldCreatedAt = "created_at"
	FieldUpdatedAt = "updated_at"
)
View Source
const (
	DefaultPageSize = 20
	MaxPageSize     = 1000
	MinPageSize     = 1
)

Variables

This section is empty.

Functions

func FindProjectRoot

func FindProjectRoot() (string, error)

func GenerateAPI

func GenerateAPI(authCfg *AuthConfig)

func GenerateAPIWithSkip

func GenerateAPIWithSkip(authCfg *AuthConfig, resourcesToSkip map[string]bool)

func GenerateOpenAPI

func GenerateOpenAPI(tables map[string]TableSchema)

func GenerateStructs

func GenerateStructs(tables map[string]TableSchema)

func GetConfigPath

func GetConfigPath(cfg *config.Config) (string, error)

func GetDTOsPath

func GetDTOsPath(cfg *config.Config) (string, error)

func GetModelsPath

func GetModelsPath(cfg *config.Config) (string, error)

func GetOpenAPIPath

func GetOpenAPIPath(cfg *config.Config) (string, error)

func GetResourcesPath

func GetResourcesPath(cfg *config.Config) (string, error)

func GetRoutesPath

func GetRoutesPath(cfg *config.Config) (string, error)

func GoTypeToOpenAPIType

func GoTypeToOpenAPIType(goType string) (string, string)

func LoadConfig

func LoadConfig() (*config.Config, error)

func LoadResourceDTOs

func LoadResourceDTOs() map[string]ResourceDTOs

func LoadSchema

func LoadSchema(db database.Database) map[string]TableSchema

func Pluralize

func Pluralize(word string) string

func ScaffoldAll

func ScaffoldAll(db database.Database)

func SingularizeExported

func SingularizeExported(word string) string

Types

type AuthConfig

type AuthConfig struct {
	Enabled     bool                // Whether auth is enabled globally
	RequireAuth map[string][]string // resource -> HTTP methods requiring auth
}

AuthConfig defines which endpoints require authentication This is now derived from the unified config.Config

func DefaultAuthConfig

func DefaultAuthConfig() *AuthConfig

DefaultAuthConfig returns a configuration that requires auth for all CRUD operations This is kept for backwards compatibility with tests

func GetAuthConfigFromConfig

func GetAuthConfigFromConfig(cfg *config.Config) *AuthConfig

GetAuthConfigFromConfig creates an AuthConfig from the unified config

func NoAuthConfig

func NoAuthConfig() *AuthConfig

NoAuthConfig returns a configuration with no authentication requirements This is kept for backwards compatibility with tests

func (*AuthConfig) RequiresAuth

func (c *AuthConfig) RequiresAuth(resource, method string) bool

RequiresAuth checks if a specific resource and HTTP method requires authentication

func (*AuthConfig) SetResourceAuth

func (c *AuthConfig) SetResourceAuth(resource string, methods []string)

SetResourceAuth sets the authentication requirements for a resource

type Column

type Column struct {
	Name       string
	Type       string
	IsNullable bool
}

type DTOSchema

type DTOSchema struct {
	Name   string
	Fields []StructField
}

type Relation

type Relation struct {
	ChildTable   string
	ChildColumn  string
	ParentTable  string
	ParentColumn string
}

type ResourceDTOs

type ResourceDTOs struct {
	Name       string
	PluralName string
	DTOs       map[string]DTOSchema
}

func (*ResourceDTOs) GetMainDTO

func (r *ResourceDTOs) GetMainDTO() *DTOSchema

type StructField

type StructField struct {
	Name      string
	Type      string
	JSONTag   string
	DBTag     string
	DTOTag    string
	IsPointer bool
}

type TableSchema

type TableSchema struct {
	TableName string
	Columns   []Column
	Relations []Relation
}

Jump to

Keyboard shortcuts

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