Documentation
¶
Index ¶
- Constants
- Variables
- func BuildGuide(ctx *ApiDefContext) (map[string]any, error)
- func BuildRelations(guideEntity any, pathsDesc []map[string]any) map[string]any
- func Camelify(s string) string
- func Canonize(s string) string
- func CleanComponentName(name string) string
- func ClearCustomPlurals()
- func DebugPath(pathStr string, methodName string, args ...any)
- func Depluralize(word string) string
- func EnsureMinEntityName(name string, existing map[string]any) string
- func Find(obj any, qkey string) []map[string]any
- func FindPathsWithPrefix(ctx *ApiDefContext, pathStr string, strict bool, param bool) int
- func FormatJSONIC(val any) string
- func FormatJsonSrc(jsonsrc string) string
- func GetElem(val any, idx int, alts ...any) any
- func GetModelPath(model any, path string, required bool) (any, error)
- func InferFieldType(name string, specType string) string
- func InferTypeFromValue(value any) string
- func IsEmpty(val any) bool
- func Items(val any) [][2]any
- func Kebabify(s string) string
- func KeysOf(val any) []string
- func LoadFile(path string) (string, error)
- func MakeBuild(opts ApiDefOptions) func(model, build map[string]any) (*ApiDefResult, error)
- func MakeEntityBuilder(ctx *ApiDefContext) (func() error, error)
- func MakeFlowBuilder(ctx *ApiDefContext) (func() error, error)
- func Merge(val any, maxdepths ...int) any
- func NewApiDef(opts ApiDefOptions) *apiDefInstance
- func Nom(v map[string]any, format string) string
- func NormalizeFieldName(s string) string
- func Parse(kind string, source string, meta map[string]string) (map[string]any, error)
- func RelativizePath(path string) string
- func ResolveElements(ctx *ApiDefContext, kind string, subkind string, ...) ([]any, error)
- func SanitizeSlug(s string) string
- func SetCustomPlurals(plurals any)
- func Size(val any) int
- func SlugToPascalCase(s string) string
- func Snakify(s string) string
- func ToJSON(val any) string
- func ToJSONOrdered(val any) string
- func Transliterate(s string) string
- func Validator(torig any) string
- func WarnOnError(where string, warn Warner, fn func() any, fallback any) any
- func WriteFileWarn(warn Warner, path string, text string)
- type ApiDefContext
- type ApiDefOptions
- type ApiDefResult
- type CmpDesc
- type EntityDesc
- type EntityPathDesc
- type Guide
- type GuideEntity
- type GuideMetrics
- type GuideMetricsCount
- type GuidePath
- type GuidePathAction
- type GuidePathOp
- type GuidePathRename
- type GuideRenameParam
- type Logger
- type MethodDef
- type MethodDesc
- type MethodEntityDesc
- type MethodName
- type Metrics
- type MetricsCount
- type ModelArg
- type ModelEntity
- type ModelEntityFlow
- type ModelEntityFlowStep
- type ModelEntityRelations
- type ModelField
- type ModelFieldOp
- type ModelOp
- type ModelOpMap
- type ModelPoint
- type OpDesc
- type OpName
- type ParameterDef
- type PathDef
- type PathDesc
- type PathMatchResult
- type SchemaDef
- type ServerDef
- type ServerVariableDef
- type Transform
- type TransformResult
- func ArgsTransform(ctx *ApiDefContext) (*TransformResult, error)
- func CleanTransform(ctx *ApiDefContext) (*TransformResult, error)
- func EntityTransform(ctx *ApiDefContext) (*TransformResult, error)
- func FieldTransform(ctx *ApiDefContext) (*TransformResult, error)
- func FlowTransform(ctx *ApiDefContext) (*TransformResult, error)
- func FlowstepTransform(ctx *ApiDefContext) (*TransformResult, error)
- func OperationTransform(ctx *ApiDefContext) (*TransformResult, error)
- func SelectTransform(ctx *ApiDefContext) (*TransformResult, error)
- func TopTransform(ctx *ApiDefContext) (*TransformResult, error)
- type TypeName
- type Warner
- type WhyOptions
Constants ¶
const IS_ENTCMP_METHOD_RATE = 0.21
Schema components that occur less than this rate (over total method count) qualify as unique entities, not shared schemas.
const IS_ENTCMP_PATH_RATE = 0.41
const KIT = "kit"
KIT is the central namespace constant for model structures.
const Version = "0.1.2"
Variables ¶
var METHOD_CONSIDER_ORDER = map[string]int{
"GET": 100,
"QUERY": 150,
"POST": 200,
"PUT": 300,
"PATCH": 400,
"DELETE": 500,
"HEAD": 600,
"OPTIONS": 700,
}
var METHOD_IDOP = map[string]string{
"GET": "load",
"QUERY": "load",
"POST": "create",
"PUT": "update",
"DELETE": "remove",
"PATCH": "patch",
"HEAD": "head",
"OPTIONS": "OPTIONS",
}
Functions ¶
func BuildGuide ¶
func BuildGuide(ctx *ApiDefContext) (map[string]any, error)
BuildGuide constructs the guide that maps an OpenAPI spec to SDK entities.
func BuildRelations ¶
BuildRelations determines entity relationships from path structure.
func Camelify ¶
Camelify converts a string to PascalCase using jostraca-compatible partify. Mirrors TS jostraca/util/basic.ts:camelify so single-char segments merge into the next segment (e.g. "poetry_o_racle" → "PoetryOracle", not "PoetryORacle").
func CleanComponentName ¶
CleanComponentName cleans a component name by removing common suffixes/prefixes.
func ClearCustomPlurals ¶ added in v0.1.2
func ClearCustomPlurals()
ClearCustomPlurals drops the per-model overrides so a subsequent Generate in the same process starts clean.
func Depluralize ¶
Depluralize converts a plural word to its singular form. Mirrors src/utility.ts:depluralize, including per-model custom plural overrides installed via SetCustomPlurals.
func EnsureMinEntityName ¶
EnsureMinEntityName ensures an entity name meets minimum length requirements.
func FindPathsWithPrefix ¶
func FindPathsWithPrefix(ctx *ApiDefContext, pathStr string, strict bool, param bool) int
FindPathsWithPrefix counts paths that start with a given prefix.
func FormatJSONIC ¶
FormatJSONIC formats a value as JSONIC text. FormatJSONIC formats a value in JSONIC format (like JSON but with unquoted bare keys, no commas, and keys ending in $ excluded). Matches the TS formatJSONIC output exactly.
func FormatJsonSrc ¶
FormatJsonSrc converts JSON source to JSONIC-style format.
func GetModelPath ¶
GetModelPath retrieves a value from a nested model by dot-separated path.
func InferFieldType ¶
InferFieldType infers field type from its name and spec type.
func InferTypeFromValue ¶
InferTypeFromValue infers a type string from a Go value.
func MakeBuild ¶
func MakeBuild(opts ApiDefOptions) func(model, build map[string]any) (*ApiDefResult, error)
MakeBuild creates a build function from options.
func MakeEntityBuilder ¶
func MakeEntityBuilder(ctx *ApiDefContext) (func() error, error)
MakeEntityBuilder creates a builder that generates entity definition files.
func MakeFlowBuilder ¶
func MakeFlowBuilder(ctx *ApiDefContext) (func() error, error)
MakeFlowBuilder creates a builder that generates flow definition files.
func NewApiDef ¶
func NewApiDef(opts ApiDefOptions) *apiDefInstance
ApiDef creates a new API definition generator with the given options.
func NormalizeFieldName ¶
NormalizeFieldName normalizes a field name.
func RelativizePath ¶
RelativizePath makes a path relative to the current working directory.
func ResolveElements ¶
func ResolveElements( ctx *ApiDefContext, kind string, subkind string, standard map[string]func(*ApiDefContext) (any, error), ) ([]any, error)
ResolveElements resolves and executes guide elements in order.
func SanitizeSlug ¶
SanitizeSlug sanitizes a raw slug into a clean kebab-case string.
func SetCustomPlurals ¶ added in v0.1.2
func SetCustomPlurals(plurals any)
SetCustomPlurals installs per-model plural overrides. Keys are lowercased; non-string or empty values are skipped so a partially-typed model entry can't poison the map. Mirrors src/utility.ts:setCustomPlurals.
func SlugToPascalCase ¶
SlugToPascalCase converts a raw slug to PascalCase.
func ToJSONOrdered ¶
ToJSONOrdered serialises like ToJSON but at every map level emits non-`$`-suffixed keys alphabetically first, then `$`-suffixed keys alphabetically. Mirrors the output ordering produced by JSON.stringify over a TS map cleaned by transform/clean (alphabetical, with `key$` appended afterwards by jostraca's `each`).
func Transliterate ¶
Transliterate removes diacritics from a string.
func Validator ¶
Validator normalizes a type string to its canonical form. Mirrors src/utility.ts:validator — undefined input (or anything non-string) returns the canonical `$ANY` macro; a string that doesn't map to a canonical type is returned as the literal "Any".
func WarnOnError ¶
WarnOnError calls fn and returns its result, warning on error.
func WriteFileWarn ¶
WriteFileWarn writes a file and warns on error.
Types ¶
type ApiDefContext ¶
type ApiDefContext struct {
Log Logger `json:"-"`
Spec map[string]any `json:"spec,omitempty"`
Opts ApiDefOptions `json:"opts"`
DefPath string `json:"defpath"`
Model map[string]any `json:"model,omitempty"`
ApiModel map[string]any `json:"apimodel,omitempty"`
Guide map[string]any `json:"guide,omitempty"`
Def map[string]any `json:"def,omitempty"`
Note map[string]any `json:"note,omitempty"`
Warn Warner `json:"-"`
Metrics *Metrics `json:"metrics,omitempty"`
Work map[string]any `json:"work,omitempty"`
}
ApiDefContext holds the processing context during API definition generation.
type ApiDefOptions ¶
type ApiDefOptions struct {
Def string `json:"def,omitempty"`
Fs any `json:"fs,omitempty"`
Debug any `json:"debug,omitempty"`
Folder string `json:"folder,omitempty"`
Meta map[string]any `json:"meta,omitempty"`
OutPrefix string `json:"outprefix,omitempty"`
Strategy string `json:"strategy,omitempty"`
Why *WhyOptions `json:"why,omitempty"`
}
ApiDefOptions holds configuration options for ApiDef.
type ApiDefResult ¶
type ApiDefResult struct {
OK bool `json:"ok"`
Start int64 `json:"start"`
End int64 `json:"end"`
Steps []string `json:"steps"`
Err error `json:"err,omitempty"`
Ctrl map[string]any `json:"ctrl,omitempty"`
Guide map[string]any `json:"guide,omitempty"`
ApiModel map[string]any `json:"apimodel,omitempty"`
Ctx *ApiDefContext `json:"ctx,omitempty"`
}
ApiDefResult holds the result of an API definition generation.
type CmpDesc ¶
type CmpDesc struct {
NameDesc any `json:"namedesc,omitempty"`
PathRate float64 `json:"path_rate"`
MethodRate float64 `json:"method_rate"`
}
CmpDesc holds component analysis information.
type EntityDesc ¶
type EntityDesc struct {
Name string `json:"name"`
OrigName string `json:"origname"`
Plural string `json:"plural"`
Path map[string]*EntityPathDesc `json:"path"`
Alias map[string]string `json:"alias"`
Cmp CmpDesc `json:"cmp"`
}
EntityDesc holds entity analysis information.
type EntityPathDesc ¶
type EntityPathDesc struct {
Op map[string]any `json:"op"`
PM *PathMatchResult `json:"pm,omitempty"`
Rename map[string]any `json:"rename,omitempty"`
WhyRename map[string]any `json:"why_rename,omitempty"`
Action map[string]any `json:"action,omitempty"`
WhyAction map[string]any `json:"why_action,omitempty"`
WhyEnt []string `json:"why_ent,omitempty"`
WhyPath []string `json:"why_path,omitempty"`
}
EntityPathDesc holds entity path analysis information.
type Guide ¶
type Guide struct {
Control map[string]any `json:"control"`
Entity map[string]*GuideEntity `json:"entity"`
Metrics GuideMetrics `json:"metrics"`
}
Guide represents the guide structure mapping API spec to SDK entities.
type GuideEntity ¶
type GuideEntity struct {
Name string `json:"name"`
Orig string `json:"orig,omitempty"`
Path map[string]*GuidePath `json:"path"`
}
GuideEntity represents an entity in the guide.
type GuideMetrics ¶
type GuideMetrics struct {
Count GuideMetricsCount `json:"count"`
Found map[string]any `json:"found"`
}
GuideMetrics holds guide-level metrics.
type GuideMetricsCount ¶
type GuideMetricsCount struct {
Path int `json:"path"`
Method int `json:"method"`
Entity int `json:"entity"`
Tag int `json:"tag"`
Cmp int `json:"cmp"`
}
GuideMetricsCount holds guide metric counters.
type GuidePath ¶
type GuidePath struct {
WhyPath []string `json:"why_path,omitempty"`
Action map[string]*GuidePathAction `json:"action,omitempty"`
Rename *GuidePathRename `json:"rename,omitempty"`
Op map[string]*GuidePathOp `json:"op,omitempty"`
}
GuidePath represents a path in the guide.
type GuidePathAction ¶
type GuidePathAction struct {
WhyAction []string `json:"why_action,omitempty"`
}
GuidePathAction represents an action on a guide path.
type GuidePathOp ¶
type GuidePathOp struct {
Method string `json:"method"`
WhyOp []string `json:"why_op,omitempty"`
Transform map[string]any `json:"transform,omitempty"`
}
GuidePathOp represents an operation on a guide path.
type GuidePathRename ¶
type GuidePathRename struct {
Param map[string]*GuideRenameParam `json:"param,omitempty"`
}
GuidePathRename holds parameter rename mappings.
type GuideRenameParam ¶
type GuideRenameParam struct {
Target string `json:"target"`
WhyRename []string `json:"why_rename,omitempty"`
}
GuideRenameParam represents a parameter rename.
type MethodDef ¶
type MethodDef struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationId string `json:"operationId,omitempty"`
Parameters []ParameterDef `json:"parameters,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Servers []ServerDef `json:"servers,omitempty"`
}
MethodDef represents an OpenAPI method definition.
type MethodDesc ¶
type MethodDesc struct {
Path string `json:"path"`
Method string `json:"method"`
Summary string `json:"summary"`
OperationId string `json:"operationId,omitempty"`
Tags []string `json:"tags"`
Parameters []any `json:"parameters"`
Responses map[string]any `json:"responses"`
RequestBody map[string]any `json:"requestBody,omitempty"`
MethodEntity *MethodEntityDesc `json:"MethodEntity,omitempty"`
}
MethodDesc is the detailed method analysis from heuristic processing.
type MethodEntityDesc ¶
type MethodEntityDesc struct {
Ref string `json:"ref"`
Cmp string `json:"cmp,omitempty"`
OrigCmp string `json:"origcmp,omitempty"`
OrigCmpRef string `json:"origcmpref,omitempty"`
WhyCmp []string `json:"why_cmp,omitempty"`
CmpOccur int `json:"cmpoccur"`
PathRate float64 `json:"path_rate"`
MethodRate float64 `json:"method_rate"`
EntName string `json:"entname"`
WhyOp []string `json:"why_op,omitempty"`
Rename map[string]any `json:"rename,omitempty"`
WhyRename map[string]any `json:"why_rename,omitempty"`
RenameOrig []string `json:"rename_orig,omitempty"`
OpName string `json:"opname"`
WhyOpName []string `json:"why_opname,omitempty"`
PM *PathMatchResult `json:"pm,omitempty"`
}
MethodEntityDesc describes method-entity relationships during analysis.
type Metrics ¶
type Metrics struct {
Count MetricsCount `json:"count"`
Found map[string]any `json:"found"`
}
Metrics holds counters and found items during processing.
type MetricsCount ¶
type MetricsCount struct {
Path int `json:"path"`
Method int `json:"method"`
OrigCmpRefs map[string]int `json:"origcmprefs"`
Cmp int `json:"cmp"`
Tag int `json:"tag"`
Entity int `json:"entity"`
}
MetricsCount holds metric counters.
type ModelArg ¶
type ModelArg struct {
Name string `json:"name"`
Orig string `json:"orig"`
Type any `json:"type"`
Kind string `json:"kind"`
Reqd bool `json:"reqd"`
}
ModelArg represents an operation argument/parameter.
type ModelEntity ¶
type ModelEntity struct {
Name string `json:"name"`
Op ModelOpMap `json:"op"`
Fields []*ModelField `json:"fields"`
ID map[string]string `json:"id"`
Relations ModelEntityRelations `json:"relations"`
}
ModelEntity represents an entity definition with operations and fields.
type ModelEntityFlow ¶
type ModelEntityFlow struct {
Name string `json:"name"`
Entity string `json:"entity"`
Kind string `json:"kind"`
Step []*ModelEntityFlowStep `json:"step"`
}
ModelEntityFlow represents a flow definition.
type ModelEntityFlowStep ¶
type ModelEntityFlowStep struct {
Op OpName `json:"op"`
Input map[string]any `json:"input,omitempty"`
Match map[string]any `json:"match,omitempty"`
Data map[string]any `json:"data,omitempty"`
Spec []map[string]any `json:"spec,omitempty"`
Valid []map[string]any `json:"valid,omitempty"`
}
ModelEntityFlowStep represents a single flow step.
type ModelEntityRelations ¶
type ModelEntityRelations struct {
Ancestors [][]string `json:"ancestors"`
}
ModelEntityRelations holds entity relationship information.
type ModelField ¶
type ModelField struct {
Name string `json:"name"`
Type any `json:"type"`
Req bool `json:"req"`
Op map[OpName]*ModelFieldOp `json:"op,omitempty"`
}
ModelField represents an entity field definition.
type ModelFieldOp ¶
ModelFieldOp holds field-specific operation configuration.
type ModelOp ¶
type ModelOp struct {
Name OpName `json:"name"`
Points []*ModelPoint `json:"points"`
}
ModelOp represents an operation definition.
type ModelOpMap ¶
ModelOpMap maps operation names to their definitions.
type ModelPoint ¶ added in v0.1.2
type ModelPoint struct {
Orig string `json:"orig"`
Method MethodName `json:"method"`
Parts []string `json:"parts"`
Rename map[string]any `json:"rename,omitempty"`
Args map[string]any `json:"args,omitempty"`
Transform map[string]any `json:"transform,omitempty"`
Select map[string]any `json:"select,omitempty"`
}
ModelPoint represents a point implementation of an operation.
type OpDesc ¶
type OpDesc struct {
Paths []*PathDesc `json:"paths"`
}
OpDesc aggregates paths for an operation.
type ParameterDef ¶
type ParameterDef struct {
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Schema *SchemaDef `json:"schema,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Example any `json:"example,omitempty"`
}
ParameterDef represents an OpenAPI parameter object.
type PathDef ¶
type PathDef struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Get *MethodDef `json:"get,omitempty"`
Put *MethodDef `json:"put,omitempty"`
Post *MethodDef `json:"post,omitempty"`
Delete *MethodDef `json:"delete,omitempty"`
Options *MethodDef `json:"options,omitempty"`
Head *MethodDef `json:"head,omitempty"`
Patch *MethodDef `json:"patch,omitempty"`
Trace *MethodDef `json:"trace,omitempty"`
Servers []ServerDef `json:"servers,omitempty"`
Parameters []ParameterDef `json:"parameters,omitempty"`
Tags any `json:"tags,omitempty"`
}
PathDef represents an OpenAPI/Swagger path object.
type PathDesc ¶
type PathDesc struct {
Orig string `json:"orig"`
Method MethodName `json:"method"`
Parts []string `json:"parts"`
Rename map[string]any `json:"rename,omitempty"`
Op map[string]any `json:"op,omitempty"`
Def map[string]any `json:"def,omitempty"`
}
PathDesc describes a path during transform processing.
type PathMatchResult ¶
type PathMatchResult struct {
Matches []string `json:"matches"`
Index int `json:"index"`
Expr string `json:"expr"`
Path string `json:"path"`
}
PathMatchResult holds the result of a path pattern match.
func PathMatch ¶
func PathMatch(path any, expr string) *PathMatchResult
PathMatch performs regex-style matching on URL paths. t - text part, p - param part, / - separator / at start - must match from start; / at end - must match to end
type SchemaDef ¶
type SchemaDef struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Enum []any `json:"enum,omitempty"`
Items *SchemaDef `json:"items,omitempty"`
Properties map[string]*SchemaDef `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties any `json:"additionalProperties,omitempty"`
AllOf []*SchemaDef `json:"allOf,omitempty"`
OneOf []*SchemaDef `json:"oneOf,omitempty"`
AnyOf []*SchemaDef `json:"anyOf,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Default any `json:"default,omitempty"`
ExampleValue any `json:"example,omitempty"`
}
SchemaDef represents an OpenAPI schema object.
type ServerDef ¶
type ServerDef struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
Variables map[string]ServerVariableDef `json:"variables,omitempty"`
}
ServerDef represents an OpenAPI server object.
type ServerVariableDef ¶
type ServerVariableDef struct {
Enum []string `json:"enum,omitempty"`
Default string `json:"default"`
Description string `json:"description,omitempty"`
}
ServerVariableDef represents an OpenAPI server variable.
type Transform ¶
type Transform func(ctx *ApiDefContext) (*TransformResult, error)
Transform is a function that transforms the context.
type TransformResult ¶
type TransformResult struct {
OK bool `json:"ok"`
Msg string `json:"msg"`
Err error `json:"err,omitempty"`
}
TransformResult holds the result of a transform step.
func ArgsTransform ¶
func ArgsTransform(ctx *ApiDefContext) (*TransformResult, error)
ArgsTransform extracts and resolves operation arguments from the API spec.
func CleanTransform ¶
func CleanTransform(ctx *ApiDefContext) (*TransformResult, error)
CleanTransform removes empty nodes and internal properties from the model.
func EntityTransform ¶
func EntityTransform(ctx *ApiDefContext) (*TransformResult, error)
EntityTransform creates entity definitions from the guide.
func FieldTransform ¶
func FieldTransform(ctx *ApiDefContext) (*TransformResult, error)
FieldTransform extracts and infers entity fields from operations.
func FlowTransform ¶
func FlowTransform(ctx *ApiDefContext) (*TransformResult, error)
FlowTransform creates basic flow definitions for entities.
func FlowstepTransform ¶
func FlowstepTransform(ctx *ApiDefContext) (*TransformResult, error)
FlowstepTransform creates individual flow steps within entity flows. Mirrors src/transform/flowstep.ts: createStep, listStep, updateStep, loadStep, removeStep, plus a final post-remove listStep when remove exists.
func OperationTransform ¶
func OperationTransform(ctx *ApiDefContext) (*TransformResult, error)
OperationTransform maps HTTP operations to entity operations.
func SelectTransform ¶
func SelectTransform(ctx *ApiDefContext) (*TransformResult, error)
SelectTransform selects response fields from OpenAPI definitions.
func TopTransform ¶
func TopTransform(ctx *ApiDefContext) (*TransformResult, error)
TopTransform sets API info and servers from the definition.
type Warner ¶
Warner is a function that records warnings during processing.
func MakeWarner ¶
MakeWarner creates a new Warner instance.
type WhyOptions ¶
type WhyOptions struct {
Show bool `json:"show,omitempty"`
}
WhyOptions controls diagnostic output.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package model embeds the shared aontu model schemas (apidef.aontu, guide.aontu) so the Go module ships them to downstream Go clients that unify apidef output.
|
Package model embeds the shared aontu model schemas (apidef.aontu, guide.aontu) so the Go module ships them to downstream Go clients that unify apidef output. |