Documentation
¶
Index ¶
- Variables
- func FormatComment(description string) string
- func GetOperationID(method, path string) string
- func IsPrimitiveType(typeName string) bool
- func IsReservedOpenAPIWord(word string) bool
- func PathToMethodName(path string) string
- func SanitizeComment(comment string) string
- func ToValidIdentifier(s string) string
- type FromPulseGenerator
- func (g *FromPulseGenerator) Generate(pulseFile string) (*GeneratedSpec, error)
- func (g *FromPulseGenerator) GenerateToFile(pulseFile, outputFile string) error
- func (g *FromPulseGenerator) GenerateToFileWithWarnings(pulseFile, outputFile string, strict bool) ([]Warning, error)
- func (g *FromPulseGenerator) SetStrict(strict bool)
- type GeneratedSpec
- type Info
- type OpenAPIType
- type Operation
- type Parameter
- type ParsedSpec
- type Parser
- type PathItem
- type PulseType
- type Response
- type SchemaInfo
- type SecurityScheme
- type ToPulseGenerator
- func (g *ToPulseGenerator) Generate(openapiFile string) (*parser.IDL, error)
- func (g *ToPulseGenerator) GeneratePulseContent(idl *parser.IDL, sourceFile string) string
- func (g *ToPulseGenerator) GenerateToFile(openapiFile, outputFile string) error
- func (g *ToPulseGenerator) GenerateToFileWithWarnings(openapiFile, outputFile string) ([]Warning, error)
- func (g *ToPulseGenerator) SetStrict(strict bool)
- type TranslationContext
- type Warning
- type Warnings
Constants ¶
This section is empty.
Variables ¶
var ( TypeString = PulseType{Name: "string", IsPrimitive: true} TypeInt = PulseType{Name: "int", IsPrimitive: true} TypeFloat = PulseType{Name: "float", IsPrimitive: true} TypeBool = PulseType{Name: "bool", IsPrimitive: true} TypeVoid = PulseType{Name: "void", IsPrimitive: true} )
Primitive types mapping from OpenAPI to Pulse.
var ( // ErrNotImplemented is returned when a feature is not yet implemented. ErrNotImplemented = errors.New("not implemented yet") )
var OpenAPIReservedWords = map[string]bool{ "$ref": true, "schema": true, "example": true, "examples": true, "encoding": true, "style": true, "explode": true, "allowReserved": true, "content": true, "headers": true, "links": true, }
OpenAPIReservedWords contains words that are reserved in OpenAPI specifications.
Functions ¶
func FormatComment ¶
FormatComment converts a description string to a Pulse comment. Handles multi-line comments and ensures proper formatting.
func GetOperationID ¶
GetOperationID generates a consistent operation ID from method and path.
func IsPrimitiveType ¶
IsPrimitiveType returns true if the given type name is a primitive Pulse type.
func IsReservedOpenAPIWord ¶
IsReservedOpenAPIWord checks if a word is reserved in OpenAPI specifications.
func PathToMethodName ¶
PathToMethodName converts a path to a valid method name.
func SanitizeComment ¶
SanitizeComment removes characters that might break comment formatting.
func ToValidIdentifier ¶
ToValidIdentifier converts a string to a valid Pulse identifier. Converts to lowercase and replaces non-alphanumeric characters with underscores.
Types ¶
type FromPulseGenerator ¶
type FromPulseGenerator struct {
// OpenAPIVersion specifies the target OpenAPI version (3.0 or 3.1)
OpenAPIVersion string
// Strict mode treats warnings as errors
Strict bool
// contains filtered or unexported fields
}
FromPulseGenerator generates OpenAPI specs from Pulse IDL.
func NewFromPulseGenerator ¶
func NewFromPulseGenerator(version string) *FromPulseGenerator
NewFromPulseGenerator creates a new Pulse → OpenAPI generator.
func (*FromPulseGenerator) Generate ¶
func (g *FromPulseGenerator) Generate(pulseFile string) (*GeneratedSpec, error)
Generate reads a Pulse IDL file and generates an OpenAPI specification.
func (*FromPulseGenerator) GenerateToFile ¶
func (g *FromPulseGenerator) GenerateToFile(pulseFile, outputFile string) error
GenerateToFile reads a Pulse IDL file and writes OpenAPI spec to a file.
func (*FromPulseGenerator) GenerateToFileWithWarnings ¶
func (g *FromPulseGenerator) GenerateToFileWithWarnings(pulseFile, outputFile string, strict bool) ([]Warning, error)
GenerateToFileWithWarnings reads a Pulse IDL file, writes OpenAPI spec to a file, and returns warnings.
func (*FromPulseGenerator) SetStrict ¶
func (g *FromPulseGenerator) SetStrict(strict bool)
SetStrict sets the strict mode flag.
type GeneratedSpec ¶
type GeneratedSpec struct {
// Version is the OpenAPI version (3.0 or 3.1)
Version string
// T is the OpenAPI document
T *openapi3.T
}
GeneratedSpec represents a generated OpenAPI specification.
func (*GeneratedSpec) ToJSON ¶
func (s *GeneratedSpec) ToJSON() ([]byte, error)
ToJSON serializes the spec to JSON format.
func (*GeneratedSpec) ToYAML ¶
func (s *GeneratedSpec) ToYAML() ([]byte, error)
ToYAML serializes the spec to YAML format (preferred).
type OpenAPIType ¶
type OpenAPIType struct {
// Type is the OpenAPI type (e.g., "string", "integer", "number", "boolean", "array", "object")
Type string
// Format is the OpenAPI format (e.g., "int32", "int64", "float", "double")
Format string
// Nullable indicates if the type is nullable (OpenAPI 3.1)
Nullable bool
}
OpenAPIType represents the OpenAPI type format.
type Operation ¶
type Operation struct {
ID string
Method string
Path string
Tag string
Summary string
Description string
Tags []string
Parameters []*Parameter
RequestBody *SchemaInfo
Responses map[string]*Response
}
Operation represents an operation in the OpenAPI spec.
type Parameter ¶
type Parameter struct {
Name string
In string // "path", "query", "header", "cookie"
Description string
Required bool
Schema *SchemaInfo
}
Parameter represents a parameter in an operation.
type ParsedSpec ¶
type ParsedSpec struct {
// Version is the OpenAPI version (e.g., "3.0.0", "3.1.0")
Version string
// Info contains metadata about the API
Info Info
// Paths maps path strings to path items
Paths map[string]*PathItem
// Schemas contains all components/schemas
Schemas map[string]*SchemaInfo
// Security contains security schemes
Security map[string]*SecurityScheme
// contains filtered or unexported fields
}
ParsedSpec represents a parsed OpenAPI specification.
func (*ParsedSpec) GetWarnings ¶
func (s *ParsedSpec) GetWarnings() []Warning
GetWarnings returns all warnings encountered during parsing.
func (*ParsedSpec) HasErrors ¶
func (s *ParsedSpec) HasErrors() bool
HasErrors returns true if there were any errors during parsing.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents an OpenAPI spec parser.
type PulseType ¶
type PulseType struct {
// Name is the type name (e.g., "string", "int", "User")
Name string
// IsOptional indicates if the type is optional ([optional])
IsOptional bool
// IsArray indicates if the type is an array
IsArray bool
// ArrayElementType is the element type for arrays
ArrayElementType *PulseType
// IsMap indicates if the type is a map
IsMap bool
// MapValueType is the value type for maps
MapValueType *PulseType
// IsPrimitive indicates if this is a primitive type
IsPrimitive bool
// IsCustom indicates if this is a custom/user-defined type
IsCustom bool
}
PulseType represents a Pulse type.
func MakeArrayType ¶
MakeArrayType creates an array type with the given element type.
func MakeCustomType ¶
MakeCustomType creates a custom/user-defined type.
func MakeMapType ¶
MakeMapType creates a map type with the given value type.
func MakeOptional ¶
MakeOptional creates an optional version of the given type.
func MapOpenAPITypeToPulse ¶
func MapOpenAPITypeToPulse(openapiType *OpenAPIType) PulseType
MapOpenAPITypeToPulse maps an OpenAPI type to a Pulse type. This implements the type mapping from Phase 2, Task 2.
type Response ¶
type Response struct {
Code string
Description string
Schema *SchemaInfo
}
Response represents a response from an operation.
type SchemaInfo ¶
type SchemaInfo struct {
// Name is the schema name (from components/schemas or generated)
Name string
// Description is the schema description
Description string
// Type is the Pulse type
Type PulseType
// Required fields (for object schemas)
Required map[string]bool
// Properties map for object schemas
Properties map[string]*SchemaInfo
// IsArray indicates if this is an array type
IsArray bool
// Items type for array schemas
Items *SchemaInfo
// IsMap indicates if this is a map type
IsMap bool
// AdditionalProperties type for map schemas
AdditionalProperties *SchemaInfo
// Enum values for enum schemas
Enum []string
// AllOf schemas for composition
AllOf []*SchemaInfo
// RefName is the name of the referenced schema (for $ref)
RefName string
// IsCircular indicates if this schema has circular references
IsCircular bool
// IsEnum indicates if this is an enum type
IsEnum bool
// IsObject indicates if this is an object/struct type
IsObject bool
}
SchemaInfo represents a parsed schema from the OpenAPI spec.
type SecurityScheme ¶
SecurityScheme represents a security scheme.
type ToPulseGenerator ¶
type ToPulseGenerator struct {
// Parser is used to load OpenAPI specs
Parser *Parser
// Strict mode treats warnings as errors
Strict bool
// contains filtered or unexported fields
}
ToPulseGenerator generates Pulse IDL from parsed OpenAPI specifications.
func NewToPulseGenerator ¶
func NewToPulseGenerator() *ToPulseGenerator
NewToPulseGenerator creates a new OpenAPI → Pulse generator.
func (*ToPulseGenerator) Generate ¶
func (g *ToPulseGenerator) Generate(openapiFile string) (*parser.IDL, error)
Generate reads an OpenAPI spec file and generates Pulse IDL.
func (*ToPulseGenerator) GeneratePulseContent ¶
func (g *ToPulseGenerator) GeneratePulseContent(idl *parser.IDL, sourceFile string) string
GeneratePulseContent generates the Pulse IDL file content from an IDL structure.
func (*ToPulseGenerator) GenerateToFile ¶
func (g *ToPulseGenerator) GenerateToFile(openapiFile, outputFile string) error
GenerateToFile reads an OpenAPI spec file and writes Pulse IDL to a file.
func (*ToPulseGenerator) GenerateToFileWithWarnings ¶
func (g *ToPulseGenerator) GenerateToFileWithWarnings(openapiFile, outputFile string) ([]Warning, error)
GenerateToFileWithWarnings reads an OpenAPI spec file, writes Pulse IDL to a file, and returns warnings.
func (*ToPulseGenerator) SetStrict ¶
func (g *ToPulseGenerator) SetStrict(strict bool)
SetStrict sets the strict mode flag.
type TranslationContext ¶
type TranslationContext struct {
// Warnings collects warnings during translation
Warnings *Warnings
// Strict mode treats warnings as errors
Strict bool
// Schemas is the map of parsed schemas from OpenAPI spec
Schemas map[string]*SchemaInfo
// CircularRefTracker tracks circular references
CircularRefTracker map[string]bool
}
TranslationContext holds state during the translation process.
func NewTranslationContext ¶
func NewTranslationContext(strict bool) *TranslationContext
NewTranslationContext creates a new translation context.
type Warning ¶
type Warning struct {
// Level is either "warning" or "error"
Level string
// Message is the warning message
Message string
// Location is the source location (e.g., file path, schema name)
Location string
}
Warning represents a warning or error encountered during translation.