openapi

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractEndpointsCmd

func ExtractEndpointsCmd() *cobra.Command

ExtractEndpointsCmd returns the cobra command for extracting HTTP endpoints

func OpenAPISpecCmd

func OpenAPISpecCmd() *cobra.Command

OpenAPISpecCmd returns the cobra command for generating OpenAPI specifications

Types

type BusinessLayerInfo

type BusinessLayerInfo struct {
	PackagePath string                         // Full import path
	TypeName    string                         // Type name (e.g., "DealBusinessLayer")
	Methods     map[string]BusinessLayerMethod // Method name -> method info
}

BusinessLayerInfo holds information about a business layer type

type BusinessLayerMethod

type BusinessLayerMethod struct {
	Name        string
	ReturnTypes []string // List of return type names (e.g., ["deals_models.DealDetails", "error"])
}

BusinessLayerMethod represents a method signature from a business layer

type BusinessLayerRegistry

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

BusinessLayerRegistry stores all discovered business layers and their methods

func NewBusinessLayerRegistry

func NewBusinessLayerRegistry(verbose bool) *BusinessLayerRegistry

NewBusinessLayerRegistry creates a new business layer registry

func (*BusinessLayerRegistry) GetMethodReturnType

func (r *BusinessLayerRegistry) GetMethodReturnType(packageName, typeName, methodName string) string

GetMethodReturnType looks up the return type for a business layer method Returns the first non-error return type, or empty string if not found

func (*BusinessLayerRegistry) LookupMethodByFieldType

func (r *BusinessLayerRegistry) LookupMethodByFieldType(fieldType, methodName string) string

LookupMethodByFieldType looks up a method return type given a field type expression fieldType could be like "*deals_business_layer.DealBusinessLayer"

func (*BusinessLayerRegistry) ScanBusinessLayers

func (r *BusinessLayerRegistry) ScanBusinessLayers(domainDir string, businessLayerSuffix string) error

ScanBusinessLayers scans the domain directory for business layer files and extracts method signatures. domainDir is the absolute path to the domain directory. businessLayerSuffix is the suffix used to identify business layer directories (e.g., "_business_layer").

type ComponentsSpec

type ComponentsSpec struct {
	Schemas         map[string]SchemaSpec         `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Responses       map[string]ResponseRef        `json:"responses,omitempty" yaml:"responses,omitempty"`
	Parameters      map[string]ParameterRef       `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBodies   map[string]RequestBodyRef     `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	SecuritySchemes map[string]SecuritySchemeSpec `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
}

ComponentsSpec represents reusable components

type ContactSpec

type ContactSpec struct {
	Name  string `json:"name,omitempty" yaml:"name,omitempty"`
	URL   string `json:"url,omitempty" yaml:"url,omitempty"`
	Email string `json:"email,omitempty" yaml:"email,omitempty"`
}

ContactSpec represents contact information

type EndpointInfo

type EndpointInfo struct {
	Path       string   `json:"path"`
	Method     string   `json:"method"`
	Handler    string   `json:"handler"`
	MSName     string   `json:"msName"`
	Middleware []string `json:"middleware,omitempty"`
}

EndpointInfo represents the structure of an extracted HTTP endpoint

type EndpointSpec

type EndpointSpec struct {
	Path            string
	Method          string
	Handler         string
	MSName          string
	Middleware      []string
	Summary         string
	Description     string
	Tags            []string
	Parameters      []ParameterSpec
	RequestBody     *RequestBodySpec
	Responses       map[string]ResponseSpec
	Security        []SecurityRequirement
	ControllerFile  string
	HandlerFunction *ast.FuncDecl
}

EndpointSpec represents a full endpoint specification with request/response details

type ExampleSpec

type ExampleSpec struct {
	Summary     string      `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string      `json:"description,omitempty" yaml:"description,omitempty"`
	Value       interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

ExampleSpec represents an example

type InfoSpec

type InfoSpec struct {
	Title          string       `json:"title" yaml:"title"`
	Description    string       `json:"description,omitempty" yaml:"description,omitempty"`
	Version        string       `json:"version" yaml:"version"`
	TermsOfService string       `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
	Contact        *ContactSpec `json:"contact,omitempty" yaml:"contact,omitempty"`
	License        *LicenseSpec `json:"license,omitempty" yaml:"license,omitempty"`
}

InfoSpec represents API information

type LicenseSpec

type LicenseSpec struct {
	Name string `json:"name" yaml:"name"`
	URL  string `json:"url,omitempty" yaml:"url,omitempty"`
}

LicenseSpec represents license information

type MediaTypeSpec

type MediaTypeSpec struct {
	Schema   *SchemaSpec            `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example  interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Examples map[string]ExampleSpec `json:"examples,omitempty" yaml:"examples,omitempty"`
}

MediaTypeSpec represents a media type

type OAuthFlow

type OAuthFlow struct {
	AuthorizationURL string            `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
	TokenURL         string            `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
	RefreshURL       string            `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes" yaml:"scopes"`
}

OAuthFlow represents an OAuth flow

type OAuthFlows

type OAuthFlows struct {
	Implicit          *OAuthFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty" yaml:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}

OAuthFlows represents OAuth flows

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI    string                  `json:"openapi" yaml:"openapi"`
	Info       InfoSpec                `json:"info" yaml:"info"`
	Servers    []ServerSpec            `json:"servers,omitempty" yaml:"servers,omitempty"`
	Paths      map[string]PathItemSpec `json:"paths" yaml:"paths"`
	Components ComponentsSpec          `json:"components" yaml:"components"`
	Security   []map[string][]string   `json:"security,omitempty" yaml:"security,omitempty"`
	Tags       []TagSpec               `json:"tags,omitempty" yaml:"tags,omitempty"`
	// contains filtered or unexported fields
}

OpenAPISpec represents the complete OpenAPI 3.0 specification

func NewOpenAPISpec

func NewOpenAPISpec(title, version, description string, servers []ServerSpec) *OpenAPISpec

NewOpenAPISpec creates a new OpenAPI specification. servers is the list of server entries; if nil/empty, the Servers field will be empty.

func (*OpenAPISpec) AddEndpoint

func (s *OpenAPISpec) AddEndpoint(endpoint *EndpointSpec)

AddEndpoint adds an endpoint to the specification

func (*OpenAPISpec) FinalizeSecuritySchemes

func (s *OpenAPISpec) FinalizeSecuritySchemes(oauthAuthorize, oauthToken string)

FinalizeSecuritySchemes adds an OAuth2 security scheme with all collected permission scopes. This should be called after all endpoints have been added. oauthAuthorize and oauthToken are the OAuth2 authorization and token URLs respectively. If both are empty and there are scopes, the scheme is still created with empty URLs.

type OperationSpec

type OperationSpec struct {
	Tags        []string               `json:"tags,omitempty" yaml:"tags,omitempty"`
	Summary     string                 `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string                 `json:"description,omitempty" yaml:"description,omitempty"`
	OperationID string                 `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Parameters  []ParameterRef         `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody *RequestBodyRef        `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses   map[string]ResponseRef `json:"responses" yaml:"responses"`
	Security    []map[string][]string  `json:"security,omitempty" yaml:"security,omitempty"`
	Deprecated  bool                   `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
}

OperationSpec represents an HTTP operation

type ParameterRef

type ParameterRef struct {
	Name        string      `json:"name,omitempty" yaml:"name,omitempty"`
	In          string      `json:"in,omitempty" yaml:"in,omitempty"`
	Description string      `json:"description,omitempty" yaml:"description,omitempty"`
	Required    bool        `json:"required,omitempty" yaml:"required,omitempty"`
	Schema      *SchemaSpec `json:"schema,omitempty" yaml:"schema,omitempty"`
	Ref         string      `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

ParameterRef represents a parameter (inline or reference)

type ParameterSpec

type ParameterSpec struct {
	Name        string
	In          string // path, query, header
	Required    bool
	Description string
	Schema      SchemaSpec
}

ParameterSpec represents a path, query, or header parameter

type PathItemSpec

type PathItemSpec struct {
	Summary     string         `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string         `json:"description,omitempty" yaml:"description,omitempty"`
	Get         *OperationSpec `json:"get,omitempty" yaml:"get,omitempty"`
	Post        *OperationSpec `json:"post,omitempty" yaml:"post,omitempty"`
	Put         *OperationSpec `json:"put,omitempty" yaml:"put,omitempty"`
	Delete      *OperationSpec `json:"delete,omitempty" yaml:"delete,omitempty"`
	Patch       *OperationSpec `json:"patch,omitempty" yaml:"patch,omitempty"`
	Options     *OperationSpec `json:"options,omitempty" yaml:"options,omitempty"`
	Head        *OperationSpec `json:"head,omitempty" yaml:"head,omitempty"`
	Parameters  []ParameterRef `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

PathItemSpec represents a path item with operations

type RequestBodyRef

type RequestBodyRef struct {
	Description string                   `json:"description,omitempty" yaml:"description,omitempty"`
	Required    bool                     `json:"required,omitempty" yaml:"required,omitempty"`
	Content     map[string]MediaTypeSpec `json:"content,omitempty" yaml:"content,omitempty"`
	Ref         string                   `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

RequestBodyRef represents a request body (inline or reference)

type RequestBodySpec

type RequestBodySpec struct {
	Description string
	Required    bool
	ContentType string
	Schema      SchemaSpec
}

RequestBodySpec represents the request body

type ResponseRef

type ResponseRef struct {
	Description string                   `json:"description,omitempty" yaml:"description,omitempty"`
	Content     map[string]MediaTypeSpec `json:"content,omitempty" yaml:"content,omitempty"`
	Ref         string                   `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

ResponseRef represents a response (inline or reference)

type ResponseSpec

type ResponseSpec struct {
	Description string
	ContentType string
	Schema      SchemaSpec
}

ResponseSpec represents a response

type SchemaSpec

type SchemaSpec struct {
	Type                 string                `json:"type,omitempty" yaml:"type,omitempty"`
	Format               string                `json:"format,omitempty" yaml:"format,omitempty"`
	Description          string                `json:"description,omitempty" yaml:"description,omitempty"`
	Ref                  string                `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Properties           map[string]SchemaSpec `json:"properties,omitempty" yaml:"properties,omitempty"`
	Required             []string              `json:"required,omitempty" yaml:"required,omitempty"`
	Items                *SchemaSpec           `json:"items,omitempty" yaml:"items,omitempty"`
	Enum                 []interface{}         `json:"enum,omitempty" yaml:"enum,omitempty"`
	Minimum              *float64              `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	Maximum              *float64              `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	MinLength            *int                  `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	MaxLength            *int                  `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	Pattern              string                `json:"pattern,omitempty" yaml:"pattern,omitempty"`
	AdditionalProperties interface{}           `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
}

SchemaSpec represents a JSON schema

type SecurityRequirement

type SecurityRequirement struct {
	Name   string
	Scopes []string
}

SecurityRequirement represents security requirements

type SecuritySchemeSpec

type SecuritySchemeSpec struct {
	Type             string      `json:"type" yaml:"type"`
	Description      string      `json:"description,omitempty" yaml:"description,omitempty"`
	Name             string      `json:"name,omitempty" yaml:"name,omitempty"`
	In               string      `json:"in,omitempty" yaml:"in,omitempty"`
	Scheme           string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`
	BearerFormat     string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
	OpenIdConnectUrl string      `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
	Flows            *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
}

SecuritySchemeSpec represents a security scheme

type ServerSpec

type ServerSpec struct {
	URL         string                    `json:"url" yaml:"url"`
	Description string                    `json:"description,omitempty" yaml:"description,omitempty"`
	Variables   map[string]ServerVariable `json:"variables,omitempty" yaml:"variables,omitempty"`
}

ServerSpec represents a server

type ServerVariable

type ServerVariable struct {
	Default     string   `json:"default" yaml:"default"`
	Description string   `json:"description,omitempty" yaml:"description,omitempty"`
	Enum        []string `json:"enum,omitempty" yaml:"enum,omitempty"`
}

ServerVariable represents a server variable

type TagSpec

type TagSpec struct {
	Name        string `json:"name" yaml:"name"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

TagSpec represents a tag

type TypeResolver

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

TypeResolver resolves Go types to schemas

func NewTypeResolver

func NewTypeResolver(projectRoot string, modelsDir string, verbose bool) *TypeResolver

NewTypeResolver creates a new type resolver

func (*TypeResolver) GetSchemas

func (r *TypeResolver) GetSchemas() map[string]SchemaSpec

GetSchemas returns all resolved schemas

func (*TypeResolver) ResolveType

func (r *TypeResolver) ResolveType(typeName string) (SchemaSpec, error)

ResolveType resolves a Go type to a schema

Jump to

Keyboard shortcuts

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