typescript

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package typescript provides TypeScript-specific code generation utilities.

Index

Constants

This section is empty.

Variables

View Source
var Primitives = map[string]bool{
	"string": true, "String": true, "boolean": true, "Boolean": true,
	"Double": true, "Integer": true, "Long": true, "Float": true,
	"Object": true, "Array": true, "ReadonlyArray": true, "Date": true,
	"number": true, "any": true, "File": true, "Error": true,
	"Map": true, "Set": true,
}

Primitives is the set of TypeScript primitive types

View Source
var ReservedWords = map[string]bool{

	"varLocalPath": true, "queryParameters": true, "headerParams": true,
	"formParams": true, "useFormData": true, "varLocalDeferred": true,
	"requestOptions": true,

	"abstract": true, "await": true, "boolean": true, "break": true,
	"byte": true, "case": true, "catch": true, "char": true,
	"class": true, "const": true, "continue": true, "debugger": true,
	"default": true, "delete": true, "do": true, "double": true,
	"else": true, "enum": true, "export": true, "extends": true,
	"false": true, "final": true, "finally": true, "float": true,
	"for": true, "function": true, "goto": true, "if": true,
	"implements": true, "import": true, "in": true, "instanceof": true,
	"int": true, "interface": true, "let": true, "long": true,
	"native": true, "new": true, "null": true, "package": true,
	"private": true, "protected": true, "public": true, "return": true,
	"short": true, "static": true, "super": true, "switch": true,
	"synchronized": true, "this": true, "throw": true, "transient": true,
	"true": true, "try": true, "typeof": true, "var": true,
	"void": true, "volatile": true, "while": true, "with": true,
	"yield": true,

	"blob": true, "file": true, "date": true, "error": true,
	"map": true, "set": true, "array": true, "object": true,
}

ReservedWords is the set of TypeScript reserved words

View Source
var TypeMapping = map[string]string{
	"Set":       "Set",
	"set":       "Set",
	"Array":     "Array",
	"array":     "Array",
	"boolean":   "boolean",
	"decimal":   "string",
	"string":    "string",
	"int":       "number",
	"float":     "number",
	"number":    "number",
	"long":      "number",
	"short":     "number",
	"char":      "string",
	"double":    "number",
	"object":    "any",
	"integer":   "number",
	"Map":       "any",
	"map":       "any",
	"date":      "string",
	"DateTime":  "string",
	"date-time": "string",
	"binary":    "any",
	"File":      "any",
	"file":      "any",
	"ByteArray": "string",
	"UUID":      "string",
	"URI":       "string",
	"Error":     "Error",
	"AnyType":   "any",
}

TypeMapping maps OpenAPI types to TypeScript types

Functions

func Camelize

func Camelize(s string, lowercaseFirst bool) string

Camelize converts a string to camelCase or PascalCase

func Dashize

func Dashize(s string) string

Dashize converts a string to kebab-case

func SanitizeName

func SanitizeName(name string) string

SanitizeName sanitizes a name for use as an identifier

func Underscore

func Underscore(s string) string

Underscore converts a string to snake_case

Types

type BaseGenerator

type BaseGenerator struct {
	// Configuration
	Config   *config.GeneratorConfig
	TSConfig *config.TypeScriptFetchConfig

	// Type mappings
	TypeMapping                map[string]string
	ImportMapping              map[string]string
	ReservedWords              map[string]bool
	LanguageSpecificPrimitives map[string]bool
	InstantiationTypes         map[string]string

	// Name mappings
	NameMapping          map[string]string
	ParameterNameMapping map[string]string
	ModelNameMapping     map[string]string
	EnumNameMapping      map[string]string

	// Package configuration
	ModelPackage string
	ApiPackage   string
	SourceDir    string

	// Naming configuration
	ModelNamePrefix string
	ModelNameSuffix string
	ApiNameSuffix   string

	// Template files
	ApiTemplateFiles   map[string]string
	ModelTemplateFiles map[string]string
	SupportingFiles    []generator.SupportingFile

	// Additional properties for templates
	AdditionalProperties map[string]any

	// Behavior flags
	ModelPropertyNaming     config.ModelPropertyNamingType
	NullSafeAdditionalProps bool
	AllowUnicodeIdentifiers bool
}

BaseGenerator is the base generator for TypeScript languages. It mirrors AbstractTypeScriptClientCodegen in Java.

func NewBaseGenerator

func NewBaseGenerator() *BaseGenerator

NewBaseGenerator creates a new TypeScript base generator

func (*BaseGenerator) EscapeReservedWord

func (g *BaseGenerator) EscapeReservedWord(name string) string

EscapeReservedWord escapes a reserved word

func (*BaseGenerator) FromModel

func (g *BaseGenerator) FromModel(name string, schema any) *codegen.CodegenModel

FromModel converts an OpenAPI schema to a CodegenModel

func (*BaseGenerator) FromOperation

func (g *BaseGenerator) FromOperation(path, httpMethod string, operation any) *codegen.CodegenOperation

FromOperation converts an OpenAPI operation to a CodegenOperation

func (*BaseGenerator) FromParameter

func (g *BaseGenerator) FromParameter(parameter any) *codegen.CodegenParameter

FromParameter converts an OpenAPI parameter to a CodegenParameter

func (*BaseGenerator) FromProperty

func (g *BaseGenerator) FromProperty(name string, schema any, required bool) *codegen.CodegenProperty

FromProperty converts an OpenAPI property to a CodegenProperty

func (*BaseGenerator) FromResponse

func (g *BaseGenerator) FromResponse(code string, response any) *codegen.CodegenResponse

FromResponse converts an OpenAPI response to a CodegenResponse

func (*BaseGenerator) FromSecurityScheme

func (g *BaseGenerator) FromSecurityScheme(name string, scheme any) *codegen.CodegenSecurity

FromSecurityScheme converts security scheme to CodegenSecurity

func (*BaseGenerator) GetAdditionalProperties

func (g *BaseGenerator) GetAdditionalProperties() map[string]any

GetAdditionalProperties returns additional properties for templates

func (*BaseGenerator) GetApiTemplateFiles

func (g *BaseGenerator) GetApiTemplateFiles() map[string]string

GetApiTemplateFiles returns API template files

func (*BaseGenerator) GetConfig

func (g *BaseGenerator) GetConfig() *config.GeneratorConfig

GetConfig returns the generator config

func (*BaseGenerator) GetImportMapping

func (g *BaseGenerator) GetImportMapping() map[string]string

GetImportMapping returns the import mapping

func (*BaseGenerator) GetLanguageSpecificPrimitives

func (g *BaseGenerator) GetLanguageSpecificPrimitives() map[string]bool

GetLanguageSpecificPrimitives returns primitive types

func (*BaseGenerator) GetModelTemplateFiles

func (g *BaseGenerator) GetModelTemplateFiles() map[string]string

GetModelTemplateFiles returns model template files

func (*BaseGenerator) GetReservedWords

func (g *BaseGenerator) GetReservedWords() map[string]bool

GetReservedWords returns the reserved words

func (*BaseGenerator) GetSchemaType

func (g *BaseGenerator) GetSchemaType(schemaType, format string) string

GetSchemaType returns the TypeScript type for an OpenAPI schema type

func (*BaseGenerator) GetSupportingFiles

func (g *BaseGenerator) GetSupportingFiles() []generator.SupportingFile

GetSupportingFiles returns supporting files

func (*BaseGenerator) GetTypeDeclaration

func (g *BaseGenerator) GetTypeDeclaration(schemaType, format string) string

GetTypeDeclaration returns the type declaration for a schema

func (*BaseGenerator) GetTypeMapping

func (g *BaseGenerator) GetTypeMapping() map[string]string

GetTypeMapping returns the type mapping

func (*BaseGenerator) IsPrimitive

func (g *BaseGenerator) IsPrimitive(typeName string) bool

IsPrimitive checks if a type is a language primitive

func (*BaseGenerator) IsReservedWord

func (g *BaseGenerator) IsReservedWord(word string) bool

IsReservedWord checks if a word is reserved

func (*BaseGenerator) PostProcessModels

func (g *BaseGenerator) PostProcessModels(models []*codegen.CodegenModel) []*codegen.CodegenModel

PostProcessModels post-processes models

func (*BaseGenerator) PostProcessOperations

func (g *BaseGenerator) PostProcessOperations(operations []*codegen.CodegenOperation) []*codegen.CodegenOperation

PostProcessOperations post-processes operations

func (*BaseGenerator) SanitizeOperationId

func (g *BaseGenerator) SanitizeOperationId(operationId string) string

SanitizeOperationId sanitizes an operation ID

func (*BaseGenerator) SetConfig

func (g *BaseGenerator) SetConfig(cfg *config.GeneratorConfig)

SetConfig sets the generator config

func (*BaseGenerator) ToApiFilename

func (g *BaseGenerator) ToApiFilename(name string) string

ToApiFilename returns the API file name

func (*BaseGenerator) ToApiName

func (g *BaseGenerator) ToApiName(name string) string

ToApiName converts a tag to an API class name

func (*BaseGenerator) ToModelFilename

func (g *BaseGenerator) ToModelFilename(name string) string

ToModelFilename returns the model file name

func (*BaseGenerator) ToModelName

func (g *BaseGenerator) ToModelName(name string) string

ToModelName converts a schema name to a TypeScript model name

func (*BaseGenerator) ToParamName

func (g *BaseGenerator) ToParamName(name string) string

ToParamName converts a parameter name

func (*BaseGenerator) ToVarName

func (g *BaseGenerator) ToVarName(name string) string

ToVarName converts a property name to a variable name

type FetchGenerator

type FetchGenerator struct {
	*BaseGenerator

	// Fetch-specific configuration
	WithPackageJson           bool
	ImportFileExtension       string
	UseSingleRequestParameter bool
	PrefixParameterInterfaces bool
	WithoutRuntimeChecks      bool
	StringEnums               bool
	FileNaming                string
	WithInterfaces            bool
	ValidationAttributes      bool
}

FetchGenerator implements the typescript-fetch generator. It mirrors TypeScriptFetchClientCodegen in Java.

func NewFetchGenerator

func NewFetchGenerator() *FetchGenerator

NewFetchGenerator creates a new TypeScript Fetch generator

func (*FetchGenerator) EscapeReservedWord

func (g *FetchGenerator) EscapeReservedWord(name string) string

EscapeReservedWord escapes reserved words

func (*FetchGenerator) GetHelp

func (g *FetchGenerator) GetHelp() string

GetHelp returns the help text

func (*FetchGenerator) GetName

func (g *FetchGenerator) GetName() string

GetName returns the generator name

func (*FetchGenerator) GetTag

GetTag returns the generator type

func (*FetchGenerator) GetTypeDeclaration

func (g *FetchGenerator) GetTypeDeclaration(schemaType, format string) string

GetTypeDeclaration returns the type declaration for file/binary types

func (*FetchGenerator) PostProcessModels

func (g *FetchGenerator) PostProcessModels(models []*codegen.CodegenModel) []*codegen.CodegenModel

PostProcessModels post-processes models for TypeScript-Fetch

func (*FetchGenerator) PostProcessOperations

func (g *FetchGenerator) PostProcessOperations(operations []*codegen.CodegenOperation) []*codegen.CodegenOperation

PostProcessOperations post-processes operations for TypeScript-Fetch

func (*FetchGenerator) ProcessOpts

func (g *FetchGenerator) ProcessOpts() error

ProcessOpts processes CLI options and initializes the generator

func (*FetchGenerator) ToApiFilename

func (g *FetchGenerator) ToApiFilename(name string) string

ToApiFilename returns the API file name with file naming convention applied

func (*FetchGenerator) ToModelFilename

func (g *FetchGenerator) ToModelFilename(name string) string

ToModelFilename returns the model file name with file naming convention applied

Jump to

Keyboard shortcuts

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