Documentation
¶
Index ¶
- func GenerateJSONTags[T any](schema asyncapi.Validations[T], field string) string
- func GenerateValidateTags[T any](schema asyncapi.Validations[T], isPointer bool, schemaType string) string
- func GetChildrenObjectSchemas[T TemplateSchema[T]](s T) []*T
- func IsFieldPointer[T TemplateSchema[T]](parent T, field string, schema T) bool
- func IsRequired[T TemplateSchema[T]](schema T, field string) bool
- func ReferenceToStructAttributePath(ref string) string
- func SetForcePointers(force bool)
- type Side
- type TemplateSchema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateJSONTags ¶ added in v0.43.0
func GenerateJSONTags[T any](schema asyncapi.Validations[T], field string) string
GenerateJSONTags returns the "json" tag for a given field in a struct, based on the asyncapi contract.
func GenerateValidateTags ¶ added in v0.40.0
func GenerateValidateTags[T any](schema asyncapi.Validations[T], isPointer bool, schemaType string) string
GenerateValidateTags returns the "validate" tag for a given field in a struct, based on the asyncapi contract. This tag can then be used by go-playground/validator/v10 to validate the struct's content.
func GetChildrenObjectSchemas ¶ added in v0.46.5
func GetChildrenObjectSchemas[T TemplateSchema[T]](s T) []*T
GetChildrenObjectSchemas returns all the children object schemas of a schema, only from the first level and without AnyOf, AllOf and OneOf.
func IsFieldPointer ¶ added in v0.46.5
func IsFieldPointer[T TemplateSchema[T]](parent T, field string, schema T) bool
IsFieldPointer reports whether a struct field should be generated as a pointer.
func IsRequired ¶ added in v0.46.5
func IsRequired[T TemplateSchema[T]](schema T, field string) bool
IsRequired checks if a field is required in an asyncapi schema.
func ReferenceToStructAttributePath ¶ added in v0.46.5
ReferenceToStructAttributePath converts a reference to a struct attribute path in the form of "a.b.c" where a, b and c are struct attributes in the form of golang conventional type names.
func SetForcePointers ¶ added in v0.46.5
func SetForcePointers(force bool)
SetForcePointers configures whether all struct fields (except arrays) should be generated as pointers.
Types ¶
type Side ¶ added in v0.3.1
type Side string
Side represents the side of the code generation based on asyncapi documentation, i.e in front (user) or behind (application) asyncapi specification.
const ( // SideIsApplication is the application side based on asyncapi documentation, // i.e. the side that stand behind of the asyncapi specification. SideIsApplication Side = "app" // SideIsUser is the user side based on asyncapi documentation, // i.e. the side that use the asyncapi specification. SideIsUser Side = "user" )
type TemplateSchema ¶ added in v0.46.5
type TemplateSchema[T any] interface { GetType() string GetIsRequired() bool IsFieldRequired(field string) bool GetProperties() map[string]*T GetItems() *T GetAdditionalProperties() *T }
TemplateSchema is the minimal view of an asyncapi Schema (v2 or v3) needed by the template helpers shared between both versions. The type parameter T is the concrete Schema type, so child schemas keep their concrete type. Both asyncapi/v2.Schema and asyncapi/v3.Schema implement TemplateSchema of themselves.