dart

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package dart provides Dart-specific code generation utilities.

Index

Constants

This section is empty.

Variables

View Source
var Primitives = map[string]bool{
	"int": true, "double": true, "num": true, "bool": true,
	"String": true, "Object": true, "DateTime": true, "Duration": true,
	"List": true, "Map": true, "Set": true, "Iterable": true,
	"Future": true, "Stream": true, "dynamic": true,
}

Primitives is the set of Dart primitive type names.

View Source
var ReservedWords = map[string]bool{

	"assert": true, "break": true, "case": true, "catch": true,
	"class": true, "const": true, "continue": true, "default": true,
	"do": true, "else": true, "enum": true, "extends": true,
	"false": true, "final": true, "finally": true, "for": true,
	"if": true, "in": true, "is": true, "new": true,
	"null": true, "rethrow": true, "return": true, "super": true,
	"switch": true, "this": true, "throw": true, "true": true,
	"try": true, "var": true, "void": true, "while": true,
	"with": true,

	"abstract": true, "as": true, "covariant": true, "deferred": true,
	"dynamic": true, "export": true, "extension": true, "external": true,
	"factory": true, "function": true, "get": true, "implements": true,
	"import": true, "interface": true, "late": true, "library": true,
	"mixin": true, "operator": true, "part": true, "required": true,
	"set": true, "static": true, "typedef": true,

	"async": true, "await": true, "yield": true, "sync": true,

	"int": true, "double": true, "num": true, "bool": true,
	"string": true, "list": true, "map": true, "object": true,
	"future": true, "stream": true, "iterable": true,

	"queryParameters": true, "headerParams": true, "formParams": true,
	"requestOptions": true, "varLocalPath": true,
}

ReservedWords is the set of Dart reserved words and built-in identifiers that must not be used as bare variable, parameter, or field names.

View Source
var TypeMapping = map[string]string{
	"Set":       "Set",
	"set":       "Set",
	"Array":     "List",
	"array":     "List",
	"List":      "List",
	"boolean":   "bool",
	"decimal":   "String",
	"string":    "String",
	"int":       "int",
	"int32":     "int",
	"int64":     "int",
	"long":      "int",
	"short":     "int",
	"char":      "String",
	"float":     "double",
	"double":    "double",
	"number":    "num",
	"integer":   "int",
	"object":    "Object?",
	"Object":    "Object?",
	"Map":       "Map<String, Object?>",
	"map":       "Map<String, Object?>",
	"date":      "DateTime",
	"DateTime":  "DateTime",
	"date-time": "DateTime",
	"binary":    "List<int>",
	"File":      "List<int>",
	"file":      "List<int>",
	"ByteArray": "String",
	"UUID":      "String",
	"URI":       "String",
	"Error":     "Object",
	"AnyType":   "Object?",
}

TypeMapping maps OpenAPI types/formats to Dart types.

The OpenAPI parser in this codebase emits TypeScript-shaped DataType strings (Array<X>, { [key: string]: X; }, any). The Dart generator translates those strings to Dart equivalents in a post-processing pass; see fetch.go.

Functions

func Camelize

func Camelize(s string, lowercaseFirst bool) string

Camelize converts a string to camelCase or PascalCase.

Words are split on non-alphanumeric characters and on lowercase->uppercase boundaries. When lowercaseFirst is true the first word's first character is lowercased; remaining words are capitalized.

func SanitizeName

func SanitizeName(name string) string

SanitizeName replaces non-word characters with underscores.

func Underscore

func Underscore(s string) string

Underscore converts a string to snake_case.

Types

type BaseGenerator

type BaseGenerator struct {
	// Configuration
	Config     *config.GeneratorConfig
	DartConfig *config.DartFetchConfig

	// 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
}

BaseGenerator is the base generator for Dart languages. It mirrors AbstractDartCodegen in the Java implementation.

func NewBaseGenerator

func NewBaseGenerator() *BaseGenerator

NewBaseGenerator creates a new Dart base generator.

func (*BaseGenerator) EscapeReservedWord

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

EscapeReservedWord escapes a reserved word by suffixing it with an underscore, matching common Dart practice and avoiding the leading-underscore privacy rule.

func (*BaseGenerator) FromModel

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

FromModel converts an OpenAPI schema to a CodegenModel (placeholder).

func (*BaseGenerator) FromOperation

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

FromOperation converts an OpenAPI operation to a CodegenOperation (placeholder).

func (*BaseGenerator) FromParameter

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

FromParameter converts an OpenAPI parameter to a CodegenParameter (placeholder).

func (*BaseGenerator) FromProperty

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

FromProperty converts an OpenAPI property to a CodegenProperty (placeholder).

func (*BaseGenerator) FromResponse

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

FromResponse converts an OpenAPI response to a CodegenResponse (placeholder).

func (*BaseGenerator) FromSecurityScheme

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

FromSecurityScheme converts a security scheme to CodegenSecurity (placeholder).

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 Dart 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 Dart 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 Dart primitive.

func (*BaseGenerator) IsReservedWord

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

IsReservedWord checks if a word is reserved (case-insensitive lookup).

func (*BaseGenerator) PostProcessModels

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

PostProcessModels post-processes models (default: identity).

func (*BaseGenerator) PostProcessOperations

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

PostProcessOperations post-processes operations (default: identity).

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 in Dart snake_case convention.

func (*BaseGenerator) ToApiName

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

ToApiName converts a tag to a Dart API class name (PascalCase + ApiNameSuffix).

func (*BaseGenerator) ToModelFilename

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

ToModelFilename returns the model file name in Dart snake_case convention.

func (*BaseGenerator) ToModelName

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

ToModelName converts a schema name to a Dart model class name (PascalCase).

func (*BaseGenerator) ToParamName

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

ToParamName converts a parameter name to a Dart identifier.

func (*BaseGenerator) ToVarName

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

ToVarName converts a property name to a Dart variable name.

Dart convention is camelCase for fields, parameters, and local variables. Reserved words are escaped via EscapeReservedWord. Names starting with a digit are prefixed with "n".

type FetchGenerator

type FetchGenerator struct {
	*BaseGenerator

	PubName         string
	PubVersion      string
	PubDescription  string
	PubAuthor       string
	PubHomepage     string
	PubRepository   string
	SdkConstraint   string
	UseDartIoSender bool
}

FetchGenerator implements the dart-fetch generator.

It produces a Dart client with no third-party runtime dependencies. HTTP requests are dispatched through a pluggable HttpSender; a dart:io HttpClient adapter is included by default.

func NewFetchGenerator

func NewFetchGenerator() *FetchGenerator

NewFetchGenerator creates a new Dart Fetch generator.

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) PostProcessModels

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

PostProcessModels translates TypeScript-shaped DataType strings emitted by the parser into Dart equivalents and computes per-property serialization metadata used by the model template.

func (*FetchGenerator) PostProcessOperations

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

PostProcessOperations translates TypeScript-shaped types on operations and their parameters, and escapes operation IDs that conflict with Dart keywords or with the *Raw method-naming convention used by the apis template.

func (*FetchGenerator) ProcessOpts

func (g *FetchGenerator) ProcessOpts() error

ProcessOpts processes options and initializes the generator.

Jump to

Keyboard shortcuts

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