openapi

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var (
	// ErrNotImplemented is returned when a feature is not yet implemented.
	ErrNotImplemented = errors.New("not implemented yet")
)
View Source
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

func FormatComment(description string) string

FormatComment converts a description string to a Pulse comment. Handles multi-line comments and ensures proper formatting.

func GetOperationID

func GetOperationID(method, path string) string

GetOperationID generates a consistent operation ID from method and path.

func IsPrimitiveType

func IsPrimitiveType(typeName string) bool

IsPrimitiveType returns true if the given type name is a primitive Pulse type.

func IsReservedOpenAPIWord

func IsReservedOpenAPIWord(word string) bool

IsReservedOpenAPIWord checks if a word is reserved in OpenAPI specifications.

func PathToMethodName

func PathToMethodName(path string) string

PathToMethodName converts a path to a valid method name.

func SanitizeComment

func SanitizeComment(comment string) string

SanitizeComment removes characters that might break comment formatting.

func ToValidIdentifier

func ToValidIdentifier(s string) string

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 Info

type Info struct {
	Title       string
	Description string
	Version     string
}

Info contains metadata about the API.

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.

func NewParser

func NewParser() *Parser

NewParser creates a new OpenAPI parser.

func (*Parser) ParseFile

func (p *Parser) ParseFile(filename string) (*ParsedSpec, error)

ParseFile loads and validates an OpenAPI 3.0/3.1 YAML or JSON file. It resolves $ref references (local and external) and extracts components/schemas into a normalized type map.

type PathItem

type PathItem struct {
	Path       string
	Operations map[string]*Operation
}

PathItem represents a path in the OpenAPI spec.

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

func MakeArrayType(elementType PulseType) PulseType

MakeArrayType creates an array type with the given element type.

func MakeCustomType

func MakeCustomType(typeName string) PulseType

MakeCustomType creates a custom/user-defined type.

func MakeMapType

func MakeMapType(valueType PulseType) PulseType

MakeMapType creates a map type with the given value type.

func MakeOptional

func MakeOptional(t PulseType) PulseType

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.

func (PulseType) String

func (t PulseType) String() string

String returns the Pulse type as a string.

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

type SecurityScheme struct {
	Type   string
	Scheme string
}

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.

func (Warning) String

func (w Warning) String() string

String returns a formatted representation of the warning.

type Warnings

type Warnings struct {
	// contains filtered or unexported fields
}

Warnings collects warnings during translation.

func NewWarnings

func NewWarnings() *Warnings

NewWarnings creates a new Warnings collection.

func (*Warnings) AddError

func (w *Warnings) AddError(location, message string)

AddError adds an error to the collection (non-fatal).

func (*Warnings) AddWarning

func (w *Warnings) AddWarning(location, message string)

AddWarning adds a warning to the collection.

func (*Warnings) All

func (w *Warnings) All() []Warning

All returns all warnings.

func (*Warnings) Count

func (w *Warnings) Count() int

Count returns the number of warnings.

func (*Warnings) HasErrors

func (w *Warnings) HasErrors() bool

HasErrors returns true if there are any error-level warnings.

Jump to

Keyboard shortcuts

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