Documentation
¶
Index ¶
- Constants
- Variables
- type Channel
- type Components
- type CorrelationID
- type Extensions
- type GoTypeImportExtension
- type GoTypeImportName
- type GoTypeImportPath
- type Info
- type Message
- type MessageField
- type Operation
- type Parameter
- type Schema
- type SchemaType
- type Specification
- func (s *Specification) AddDependency(path string, spec asyncapi.Specification) error
- func (s Specification) CustomImports() ([]string, error)
- func (s Specification) GetPublishSubscribeCount() (publishCount, subscribeCount uint)
- func (s Specification) MajorVersion() int
- func (s *Specification) Process() error
- func (s Specification) ReferenceMessage(ref string) (*Message, error)
- func (s Specification) ReferenceParameter(ref string) (*Parameter, error)
- func (s Specification) ReferenceSchema(ref string) (*Schema, error)
Constants ¶
const (
// MajorVersion is the major version of this AsyncAPI implementation.
MajorVersion = 2
)
const (
// MessageSuffix is the suffix added to the name of the message.
MessageSuffix = "Message"
)
Variables ¶
var ( // ErrInvalidReference is sent when a reference is invalid. ErrInvalidReference = fmt.Errorf("%w: invalid reference", extensions.ErrAsyncAPI) )
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
Parameters map[string]*Parameter `json:"parameters"`
Subscribe *Operation `json:"subscribe"`
Publish *Operation `json:"publish"`
Name string `json:"-"`
Path string `json:"-"`
}
Channel is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#channelItemObject
type Components ¶
type Components struct {
Messages map[string]*Message `json:"messages"`
Schemas map[string]*Schema `json:"schemas"`
Parameters map[string]*Parameter `json:"parameters"`
}
Components is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#componentsObject
type CorrelationID ¶
type CorrelationID struct {
Description string `json:"description"`
Location string `json:"location"`
}
CorrelationID is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#correlationIdObject
type Extensions ¶
type Extensions struct {
// Setting custom Go type when generating schemas
ExtGoType string `json:"x-go-type"`
// Setting custom import statements for ExtGoType
ExtGoTypeImport *GoTypeImportExtension `json:"x-go-type-import"`
// Controls whether to include omitempty in JSON tags
// If false, omitempty will be removed from JSON tags even if the field can be null
ExtOmitEmpty *bool `json:"x-omitempty"`
// ExtraExtensions holds any other x-* extension keys from the spec (e.g. x-custom-tag).
// Used when generating code so custom extensions can be emitted as struct tags or comments.
ExtraExtensions map[string]any `json:"-"`
}
Extensions holds additional properties defined for asyncapi-codegen that are out of the AsyncAPI spec.
type GoTypeImportExtension ¶
type GoTypeImportExtension struct {
Name GoTypeImportName `json:"name"` // Package name for import, optional
Path GoTypeImportPath `json:"path"` // Path to package to import
}
GoTypeImportExtension specifies the required import statement for the x-go-type extension. For example, GoTypeImportExtension{Name: "myuuid", Path: "github.com/google/uuid"} will generate `import myuuid github.com/google/uuid`.
type GoTypeImportName ¶
type GoTypeImportName string
GoTypeImportName is the import name type for x-go-type-import.
type GoTypeImportPath ¶
type GoTypeImportPath string
GoTypeImportPath is the import path type for x-go-type-import.
type Info ¶
type Info struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description"`
}
Info is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#infoObject
type Message ¶
type Message struct {
Description string `json:"description"`
Headers *Schema `json:"headers"`
OneOf []*Message `json:"oneOf"`
Payload *Schema `json:"payload"`
CorrelationID *CorrelationID `json:"correlationID"`
Reference string `json:"$ref"`
Name string `json:"-"`
ReferenceTo *Message `json:"-"`
// CorrelationIDLocation will indicate where the correlation id is
// According to: https://www.asyncapi.com/docs/reference/specification/v2.6.0#correlationIDObject
CorrelationIDLocation string `json:"-"`
CorrelationIDRequired bool `json:"-"`
}
Message is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#messageObject
type MessageField ¶
type MessageField string
MessageField is a structure that represents the type of a field.
const ( // MessageFieldIsHeader represents the message field of a header. MessageFieldIsHeader MessageField = "header" // MessageFieldIsPayload represents the message field of a payload. MessageFieldIsPayload MessageField = "payload" )
func (MessageField) String ¶
func (t MessageField) String() string
String returns the string representation of the type.
type Operation ¶
type Operation struct {
OperationID string `json:"operationId"`
Message Message `json:"message"`
Name string `json:"-"`
}
Operation is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#operationObject
type Parameter ¶
type Parameter struct {
Description string `json:"description"`
Schema *Schema `json:"schema-name"`
Location string `json:"location"`
Reference string `json:"$ref"`
Name string `json:"-"`
ReferenceTo *Parameter `json:"-"`
}
Parameter is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#parameterObject
type Schema ¶
type Schema struct {
// --- JSON Schema fields --------------------------------------------------
Type string `json:"type"`
Description string `json:"description"`
Format string `json:"format"`
Properties map[string]*Schema `json:"properties"`
Items *Schema `json:"items"`
Reference string `json:"$ref"`
AdditionalProperties *Schema `json:"additionalProperties"`
Name string `json:"-"`
ReferenceTo *Schema `json:"-"`
// Embedded validation fields
asyncapi.Validations[Schema]
// Embedded extended fields
Extensions
}
Schema is a representation of the corresponding asyncapi object filled from an asyncapi specification that will be used to generate code. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#schemaObject
func NewSchema ¶
func NewSchema() Schema
NewSchema creates a new Schema structure with initialized fields.
func (Schema) IsFieldRequired ¶
IsFieldRequired checks if a field is required in the asyncapi struct.
func (*Schema) MergeWith ¶
func (s *Schema) MergeWith(spec Specification, s2 Schema) error
MergeWith merges the given Schema structure with another one (basically for AllOf, AnyOf, OneOf, etc).
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler so that any x-* key not in Extensions is stored in ExtraExtensions and can be used during code generation.
type SchemaType ¶
type SchemaType string
SchemaType is a structure that represents the type of a field.
const ( // SchemaTypeIsArray represents the type of an array. SchemaTypeIsArray SchemaType = "array" // SchemaTypeIsObject represents the type of an object. SchemaTypeIsObject SchemaType = "object" // SchemaTypeIsString represents the type of a string. SchemaTypeIsString SchemaType = "string" // SchemaTypeIsInteger represents the type of an integer. SchemaTypeIsInteger SchemaType = "integer" )
func (SchemaType) String ¶
func (st SchemaType) String() string
String returns the string representation of the type.
type Specification ¶
type Specification struct {
Version string `json:"asyncapi"`
Info Info `json:"info"`
Channels map[string]*Channel `json:"channels"`
Components Components `json:"components"`
// contains filtered or unexported fields
}
Specification is the asyncapi specification struct that will be used to generate code. It should contains every information given in the asyncapi specification. Source: https://www.asyncapi.com/docs/reference/specification/v2.6.0#schema
func FromUnknownVersion ¶
func FromUnknownVersion(s asyncapi.Specification) (*Specification, error)
FromUnknownVersion returns an AsyncAPI specification V2 from interface, if compatible. Note: Before using this, you should make sure that parsed data is in version 2.
func NewSpecification ¶
func NewSpecification() *Specification
NewSpecification creates a new Specification struct.
func (*Specification) AddDependency ¶
func (s *Specification) AddDependency(path string, spec asyncapi.Specification) error
AddDependency adds a specification dependency to the Specification.
func (Specification) CustomImports ¶
func (s Specification) CustomImports() ([]string, error)
CustomImports collects all custom import paths set by x-go-type-imports in all Schema Objects in the Specification. Returns import strings like `alias "abc.xyz/repo/package"` for code generation. Returns error when import name conflicts.
func (Specification) GetPublishSubscribeCount ¶
func (s Specification) GetPublishSubscribeCount() (publishCount, subscribeCount uint)
GetPublishSubscribeCount gets the count of 'publish' channels and the count of 'subscribe' channels inside the Specification.
func (Specification) MajorVersion ¶
func (s Specification) MajorVersion() int
MajorVersion returns the asyncapi major version of this document. This function is used mainly by the interface.
func (*Specification) Process ¶
func (s *Specification) Process() error
Process processes the Specification to make it ready for code generation.
func (Specification) ReferenceMessage ¶
func (s Specification) ReferenceMessage(ref string) (*Message, error)
ReferenceMessage returns the Message struct corresponding to the given reference.
func (Specification) ReferenceParameter ¶
func (s Specification) ReferenceParameter(ref string) (*Parameter, error)
ReferenceParameter returns the Parameter struct corresponding to the given reference.
func (Specification) ReferenceSchema ¶
func (s Specification) ReferenceSchema(ref string) (*Schema, error)
ReferenceSchema returns the Any struct corresponding to the given reference.