Documentation ¶
Overview ¶
Package ir contains definitions for the intermediate representation of OpenAPI objects and generated Go types.
Index ¶
- func PrintGoValue(v any) string
- type ContentType
- type CustomFormat
- type Default
- type Encoding
- type EnumVariant
- type ExternalType
- type Field
- type GenericVariant
- type InlineField
- type JSON
- func (j JSON) AdditionalProps() *Field
- func (j JSON) Decode() string
- func (j JSON) Fields() (fields JSONFields)
- func (j JSON) Fn() string
- func (j JSON) Format() string
- func (j JSON) IsBase64() bool
- func (j JSON) PatternProps() (fields []*Field)
- func (j JSON) Sum() SumJSON
- func (j JSON) SumTypes() string
- func (j JSON) Type() string
- type JSONFields
- type Kind
- type Media
- type NilSemantic
- type OTELAttribute
- type Operation
- func (op *Operation) CookieParams() []*Parameter
- func (op Operation) GoDoc() []string
- func (op Operation) HasHeaderParams() bool
- func (op Operation) HasQueryParams() bool
- func (op *Operation) HeaderParams() []*Parameter
- func (op *Operation) ListResponseTypes() []ResponseInfo
- func (op Operation) OTELAttributes() (r []OTELAttribute)
- func (op Operation) PathParamIndex(name string) int
- func (op *Operation) PathParams() []*Parameter
- func (op Operation) PathParamsCount() (r int)
- func (op Operation) PrettyOperationID() string
- func (op *Operation) QueryParams() []*Parameter
- type Parameter
- type PathPart
- type PrimitiveType
- type Request
- type Response
- type ResponseInfo
- type Responses
- type Security
- type SecurityFormat
- type SecurityKind
- type SecurityRequirements
- type Server
- type ServerParam
- type Servers
- type SumJSON
- type SumJSONType
- type SumSpec
- type SumSpecMap
- type Tag
- type Type
- func Alias(name string, to *Type) *Type
- func Any(schema *jsonschema.Schema) *Type
- func Array(item *Type, sem NilSemantic, schema *jsonschema.Schema) *Type
- func Generic(name string, of *Type, v GenericVariant) *Type
- func Interface(name string) *Type
- func Pointer(to *Type, sem NilSemantic) *Type
- func Primitive(typ PrimitiveType, schema *jsonschema.Schema) *Type
- func Stream(name string, schema *jsonschema.Schema) *Type
- func (t *Type) AddFeature(feature string)
- func (t *Type) AddMethod(name string)
- func (t Type) CanGeneric() bool
- func (t *Type) CanHaveMethods() bool
- func (t *Type) CloneFeatures() []string
- func (t Type) Default() Default
- func (t Type) DefaultFields() (r []*Field)
- func (t *Type) DoPassByPointer() bool
- func (t *Type) EncodeFn() string
- func (t *Type) Equal(target *Type) bool
- func (t *Type) Examples() (r []string)
- func (t Type) FakeFields() (r []*Field)
- func (t *Type) FakeValue() string
- func (t Type) FileParameters() (params []Parameter)
- func (t Type) FormParameters() (params []Parameter)
- func (t *Type) Format() bool
- func (t Type) FromString() string
- func (t *Type) Go() string
- func (t Type) GoDoc() []string
- func (t Type) HasDefaultFields() bool
- func (t *Type) HasFeature(feature string) bool
- func (t *Type) Implement(i *Type)
- func (t *Type) Is(vs ...Kind) bool
- func (t *Type) IsAlias() bool
- func (t *Type) IsAny() bool
- func (t *Type) IsArray() bool
- func (t *Type) IsBase64Stream() bool
- func (t *Type) IsEnum() bool
- func (t *Type) IsFloat() bool
- func (t *Type) IsGeneric() bool
- func (t *Type) IsInteger() bool
- func (t *Type) IsInterface() bool
- func (t *Type) IsMap() bool
- func (t *Type) IsNull() bool
- func (t *Type) IsNumeric() bool
- func (t *Type) IsPointer() bool
- func (t *Type) IsPrimitive() bool
- func (t *Type) IsStream() bool
- func (t *Type) IsStruct() bool
- func (t *Type) IsSum() bool
- func (t *Type) JSON() JSON
- func (t *Type) ListImplementations() []*Type
- func (t *Type) Methods() []string
- func (t *Type) MustField(name string) *Field
- func (t *Type) NamePostfix() string
- func (t *Type) NeedValidation() bool
- func (t *Type) Pointer(sem NilSemantic) *Type
- func (t *Type) ReadOnlyReceiver() string
- func (t *Type) RecursiveTo(target *Type) bool
- func (t *Type) SetFieldType(name string, newT *Type)
- func (t Type) String() string
- func (t Type) ToString() string
- func (t *Type) TypeDiscriminator() (r []TypeDiscriminatorCase)
- func (t *Type) Unimplement(i *Type)
- type TypeDiscriminatorCase
- type Validators
- func (v *Validators) SetArray(schema *jsonschema.Schema)
- func (v *Validators) SetFloat(schema *jsonschema.Schema) error
- func (v *Validators) SetInt(schema *jsonschema.Schema) error
- func (v *Validators) SetObject(schema *jsonschema.Schema)
- func (v *Validators) SetString(schema *jsonschema.Schema) (err error)
- type WebhookInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ContentType ¶
type ContentType string
ContentType is a Content-Type header value.
func (ContentType) Mask ¶ added in v0.35.0
func (t ContentType) Mask() bool
func (ContentType) String ¶
func (t ContentType) String() string
type CustomFormat ¶ added in v0.56.0
type CustomFormat struct { // Name is name of custom format. Name string // GoName is valid Go name for this custom format. GoName string // Type is type of custom format. Type ExternalType // JSON is JSON encoder/decoder for custom format. JSON ExternalType // Text is text encoder/decoder for custom format. Text ExternalType }
CustomFormat defines custom format type.
func (*CustomFormat) String ¶ added in v0.56.0
func (c *CustomFormat) String() string
String returns string representation of CustomFormat.
type Encoding ¶ added in v0.44.0
type Encoding string
Encoding of body.
const ( // EncodingJSON is Encoding for json. EncodingJSON Encoding = "application/json" // EncodingFormURLEncoded is Encoding for URL-encoded form. EncodingFormURLEncoded Encoding = "application/x-www-form-urlencoded" // EncodingMultipart is Encoding for multipart form. EncodingMultipart Encoding = "multipart/form-data" // EncodingOctetStream is Encoding for binary. EncodingOctetStream Encoding = "application/octet-stream" // EncodingTextPlain is Encoding for text. EncodingTextPlain Encoding = "text/plain" )
func (Encoding) FormURLEncoded ¶ added in v0.44.0
func (Encoding) MultipartForm ¶ added in v0.44.0
func (Encoding) OctetStream ¶ added in v0.44.0
type EnumVariant ¶
func (*EnumVariant) ValueGo ¶
func (v *EnumVariant) ValueGo() string
type ExternalType ¶ added in v0.56.0
ExternalType defines external type.
func (ExternalType) Go ¶ added in v0.56.0
func (c ExternalType) Go() string
Go returns valid Go type for this ExternalType.
type Field ¶
type Field struct { // Go Name of field. Name string // Type of field. Type *Type // JSON tag. May be empty. Tag Tag // Whether field is inlined map (i.e. additionalProperties, patternProperties). Inline InlineField // Spec is property schema. May be nil. Spec *jsonschema.Property }
Field of structure.
func (Field) ValidationName ¶
ValidationName returns name for FieldError.
type GenericVariant ¶
func (GenericVariant) Any ¶
func (v GenericVariant) Any() bool
func (GenericVariant) Name ¶
func (v GenericVariant) Name() string
func (GenericVariant) NullableOptional ¶
func (v GenericVariant) NullableOptional() bool
func (GenericVariant) OnlyNullable ¶
func (v GenericVariant) OnlyNullable() bool
func (GenericVariant) OnlyOptional ¶
func (v GenericVariant) OnlyOptional() bool
type InlineField ¶
type InlineField int
InlineField defines how to inline field.
const ( InlineNone InlineField = iota InlineAdditional InlinePattern )
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON specifies json encoding and decoding for Type.
func (JSON) AdditionalProps ¶
AdditionalProps return field of Type that should be encoded as inlined map.
func (JSON) Fields ¶
func (j JSON) Fields() (fields JSONFields)
Fields return all fields of Type that should be encoded via json.
func (JSON) Fn ¶
Fn returns jx.Encoder or jx.Decoder method name.
If blank, value cannot be encoded with single method call.
func (JSON) Format ¶
Format returns format name for handling json encoding or decoding.
Mostly used for encoding or decoding of string formats, like `json.EncodeUUID`, where UUID is Format.
func (JSON) PatternProps ¶
PatternProps return field of Type that should be encoded as inlined map with pattern.
type JSONFields ¶
type JSONFields []*Field
func (JSONFields) FirstRequiredIndex ¶
func (j JSONFields) FirstRequiredIndex() int
FirstRequiredIndex returns first required field index.
Or -1 if there is no required fields.
func (JSONFields) HasRequired ¶
func (j JSONFields) HasRequired() bool
HasRequired whether object has required fields
func (JSONFields) NotEmpty ¶
func (j JSONFields) NotEmpty() bool
NotEmpty whether field slice is not empty.
func (JSONFields) RequiredMask ¶
func (j JSONFields) RequiredMask() []uint8
RequiredMask returns array of 64-bit bitmasks for required fields.
type Kind ¶
type Kind string
const ( KindPrimitive Kind = "primitive" KindArray Kind = "array" KindMap Kind = "map" KindAlias Kind = "alias" KindEnum Kind = "enum" KindStruct Kind = "struct" KindPointer Kind = "pointer" KindInterface Kind = "interface" KindGeneric Kind = "generic" KindSum Kind = "sum" KindAny Kind = "any" KindStream Kind = "stream" )
type NilSemantic ¶
type NilSemantic string
NilSemantic specifies nil value semantics.
const ( NilInvalid NilSemantic = "invalid" // nil is invalid NilOptional NilSemantic = "optional" // nil is "no value" NilNull NilSemantic = "null" // nil is null )
Possible nil value semantics.
func (NilSemantic) Invalid ¶
func (n NilSemantic) Invalid() bool
func (NilSemantic) Null ¶
func (n NilSemantic) Null() bool
func (NilSemantic) Optional ¶
func (n NilSemantic) Optional() bool
type OTELAttribute ¶ added in v0.53.0
type OTELAttribute struct { // Key is a name of the attribute constructor in otelogen package. Key string // Value is a value of the attribute. Value string }
OTELAttribute represents OpenTelemetry attribute defined by otelogen package.
func (OTELAttribute) String ¶ added in v0.53.0
func (a OTELAttribute) String() string
String returns call to the constructor of this attribute.
type Operation ¶
type Operation struct { Name string Summary string Description string Deprecated bool WebhookInfo *WebhookInfo PathParts []*PathPart Params []*Parameter Request *Request Responses *Responses Security SecurityRequirements Spec *openapi.Operation }
func (*Operation) CookieParams ¶
func (Operation) HasHeaderParams ¶ added in v0.33.0
func (Operation) HasQueryParams ¶
func (*Operation) HeaderParams ¶
func (*Operation) ListResponseTypes ¶
func (op *Operation) ListResponseTypes() []ResponseInfo
func (Operation) OTELAttributes ¶ added in v0.53.0
func (op Operation) OTELAttributes() (r []OTELAttribute)
OTELAttributes returns OpenTelemetry attributes for this operation.
func (Operation) PathParamIndex ¶
func (*Operation) PathParams ¶
func (Operation) PathParamsCount ¶
func (Operation) PrettyOperationID ¶ added in v0.37.0
func (*Operation) QueryParams ¶
type Parameter ¶
type PrimitiveType ¶
type PrimitiveType int
const ( None PrimitiveType = iota String ByteSlice Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Float32 Float64 Bool Null Time Duration UUID IP URL File Custom )
func (PrimitiveType) IsString ¶
func (p PrimitiveType) IsString() bool
IsString whether this type is string.
func (PrimitiveType) String ¶
func (p PrimitiveType) String() string
type Request ¶
type Request struct { Type *Type EmptyBody *Type Contents map[ContentType]Media Spec *openapi.RequestBody }
type Response ¶
type Response struct { NoContent *Type Contents map[ContentType]Media Spec *openapi.Response Headers map[string]*Parameter // Indicates that all response types // are wrappers with StatusCode field. WithStatusCode bool // Indicates that all response types // are wrappers with response header fields. WithHeaders bool }
func (Response) ResponseInfo ¶ added in v0.33.0
func (s Response) ResponseInfo() []ResponseInfo
type ResponseInfo ¶
type Responses ¶ added in v0.33.0
type Responses struct { Type *Type Pattern [5]*Response StatusCode map[int]*Response Default *Response }
func (*Responses) DoPass ¶ added in v0.56.0
DoPass whether response type should be present in result tuple.
func (*Responses) DoTakePtr ¶ added in v0.56.0
DoTakePtr returns true if type should be taken by pointer.
func (*Responses) HasPattern ¶ added in v0.44.0
func (*Responses) ResultTuple ¶ added in v0.56.0
ResultTuple returns result tuple for this response.
type Security ¶
type Security struct { Kind SecurityKind Format SecurityFormat ParameterName string Description string Type *Type }
type SecurityFormat ¶
type SecurityFormat string
SecurityFormat defines security parameter format.
const ( // APIKeySecurityFormat is plain value format. APIKeySecurityFormat SecurityFormat = "apiKey" // BearerSecurityFormat is Bearer authentication (RFC 6750) format. // // Unsupported yet. BearerSecurityFormat SecurityFormat = "bearer" // BasicHTTPSecurityFormat is Basic HTTP authentication (RFC 7617) format. BasicHTTPSecurityFormat SecurityFormat = "basic" // DigestHTTPSecurityFormat is Digest HTTP authentication (RFC 7616) format. // // Unsupported yet. DigestHTTPSecurityFormat SecurityFormat = "digest" )
func (SecurityFormat) IsAPIKeySecurity ¶
func (s SecurityFormat) IsAPIKeySecurity() bool
IsAPIKeySecurity whether s is APIKeySecurityFormat.
func (SecurityFormat) IsBasicHTTPSecurity ¶
func (s SecurityFormat) IsBasicHTTPSecurity() bool
IsBasicHTTPSecurity whether s is BasicHTTPSecurityFormat.
func (SecurityFormat) IsBearerSecurity ¶
func (s SecurityFormat) IsBearerSecurity() bool
IsBearerSecurity whether s is BearerSecurityFormat.
func (SecurityFormat) IsDigestHTTPSecurity ¶
func (s SecurityFormat) IsDigestHTTPSecurity() bool
IsDigestHTTPSecurity whether s is DigestHTTPSecurityFormat.
type SecurityKind ¶
type SecurityKind string
SecurityKind defines security kind.
const ( // QuerySecurity is URL query security parameter. Matches "apiKey" type with "in" = "query". QuerySecurity SecurityKind = "query" // HeaderSecurity is HTTP header security parameter. Matches some "http" schemes and "apiKey" with "in" = "header". HeaderSecurity SecurityKind = "header" // OAuth2Security is special type for OAuth2-based authentication. Matches "oauth2" and "openIdConnect". OAuth2Security SecurityKind = "oauth2" )
func (SecurityKind) IsHeader ¶
func (s SecurityKind) IsHeader() bool
IsHeader whether s is HeaderSecurity.
func (SecurityKind) IsOAuth2 ¶
func (s SecurityKind) IsOAuth2() bool
IsOAuth2 whether s is OAuth2Security.
func (SecurityKind) IsQuery ¶
func (s SecurityKind) IsQuery() bool
IsQuery whether s is QuerySecurity.
type SecurityRequirements ¶ added in v0.57.0
func (SecurityRequirements) BitArrayLen ¶ added in v0.57.0
func (s SecurityRequirements) BitArrayLen() (r int)
BitArrayLen returns the length for bitset's underlying array.
type Server ¶ added in v0.52.0
type Server struct { Name string Params []ServerParam Spec openapi.Server }
Server describes a OpenAPI server.
func (Server) FormatString ¶ added in v0.52.0
FormatString returns a format string (fmt.Sprintf) for the server.
If the server has no variables, returns plain string.
func (Server) IsTemplate ¶ added in v0.52.0
IsTemplate returns true if server URL has variables.
type ServerParam ¶ added in v0.52.0
type ServerParam struct { // Name is a Go name of the parameter. Name string Spec openapi.ServerVariable }
ServerParam describes a server template parameter.
type Servers ¶ added in v0.52.0
type Servers []Server
Servers is a list of servers.
type SumJSON ¶
type SumJSON struct {
Type SumJSONType
}
SumJSON specifies rules for parsing sum types in json.
func (SumJSON) Discriminator ¶
func (SumJSON) TypeDiscriminator ¶
type SumJSONType ¶
type SumJSONType byte
const ( SumJSONPrimitive SumJSONType = iota SumJSONFields SumJSONDiscriminator SumJSONTypeDiscriminator )
type SumSpec ¶
type SumSpec struct { Unique []*Field // DefaultMapping is name of default mapping. // // Used for variant which has no unique fields. DefaultMapping string // Discriminator is field name of sum type discriminator. Discriminator string // Mapping is discriminator value -> variant mapping. Mapping []SumSpecMap // TypeDiscriminator denotes to distinguish variants by type. TypeDiscriminator bool }
SumSpec for KindSum.
type SumSpecMap ¶
type Tag ¶
type Tag struct { JSON string // json tag, empty for none Form *openapi.Parameter // query form parameter }
Tag of Field.
func (Tag) EscapedJSON ¶
EscapedJSON returns quoted and escaped JSON tag.
type Type ¶
type Type struct { Doc string // ogen documentation Kind Kind // kind Name string // only for struct, alias, interface, enum, stream, generic, map, sum Primitive PrimitiveType // only for primitive, enum CustomFormat *CustomFormat // only for primitive AliasTo *Type // only for alias PointerTo *Type // only for pointer SumOf []*Type // only for sum SumSpec SumSpec // only for sum Item *Type // only for array, map EnumVariants []*EnumVariant // only for enum Fields []*Field // only for struct Implements map[*Type]struct{} // only for struct, alias, enum Implementations map[*Type]struct{} // only for interface InterfaceMethods map[string]struct{} // only for interface Schema *jsonschema.Schema // for all kinds except pointer, interface. Can be nil. NilSemantic NilSemantic // only for pointer GenericOf *Type // only for generic GenericVariant GenericVariant // only for generic MapPattern ogenregex.Regexp // only for map DenyAdditionalProps bool // only for map and struct Validators Validators // Features contains a set of features the type must implement. // Available features: 'json', 'uri'. // // If some of these features are set, generator // generates additional encoding methods if needed. Features []string }
func Any ¶
func Any(schema *jsonschema.Schema) *Type
func Array ¶
func Array(item *Type, sem NilSemantic, schema *jsonschema.Schema) *Type
func Pointer ¶
func Pointer(to *Type, sem NilSemantic) *Type
func Primitive ¶
func Primitive(typ PrimitiveType, schema *jsonschema.Schema) *Type
func (*Type) AddFeature ¶
func (Type) CanGeneric ¶
CanGeneric reports whether Type can be boxed to KindGeneric.
func (*Type) CanHaveMethods ¶
func (*Type) CloneFeatures ¶
func (Type) DefaultFields ¶
DefaultFields returns fields with default values.
func (*Type) DoPassByPointer ¶ added in v0.56.0
DoPassByPointer returns true if type should be passed by pointer.
func (Type) FakeFields ¶
func (Type) FileParameters ¶ added in v0.41.0
func (Type) FormParameters ¶ added in v0.41.0
func (*Type) Format ¶
Format denotes whether custom formatting for Type is required while encoding or decoding.
TODO(ernado): can we use t.JSON here?
func (Type) FromString ¶
func (Type) HasDefaultFields ¶
HasDefaultFields whether type has fields with default values.
func (*Type) HasFeature ¶
func (*Type) IsBase64Stream ¶ added in v0.55.0
func (*Type) IsInterface ¶
func (*Type) IsPrimitive ¶
func (*Type) ListImplementations ¶
func (*Type) NamePostfix ¶
NamePostfix returns name postfix for optional wrapper.
func (*Type) NeedValidation ¶
func (*Type) Pointer ¶
func (t *Type) Pointer(sem NilSemantic) *Type
func (*Type) ReadOnlyReceiver ¶ added in v0.56.0
ReadOnlyReceiver returns the receiver type for read-only methods.
func (*Type) RecursiveTo ¶
func (*Type) SetFieldType ¶
func (*Type) TypeDiscriminator ¶ added in v0.56.0
func (t *Type) TypeDiscriminator() (r []TypeDiscriminatorCase)
func (*Type) Unimplement ¶
type TypeDiscriminatorCase ¶ added in v0.56.0
type TypeDiscriminatorCase struct { // JXTypes is jx.Type values list. JXTypes string // Type is the type to be used for this case. Type *Type // IntType is the type to be used for this case when the type discriminator should distinguish // between integer and float types. IntType *Type }
TypeDiscriminatorCase is a helper struct for describing type discriminator case.
type Validators ¶
type Validators struct { String validate.String Int validate.Int Float validate.Float Array validate.Array Object validate.Object }
func (*Validators) SetArray ¶
func (v *Validators) SetArray(schema *jsonschema.Schema)
func (*Validators) SetFloat ¶
func (v *Validators) SetFloat(schema *jsonschema.Schema) error
func (*Validators) SetInt ¶
func (v *Validators) SetInt(schema *jsonschema.Schema) error
func (*Validators) SetObject ¶
func (v *Validators) SetObject(schema *jsonschema.Schema)
func (*Validators) SetString ¶
func (v *Validators) SetString(schema *jsonschema.Schema) (err error)
type WebhookInfo ¶ added in v0.53.0
type WebhookInfo struct { // Name is the name of the webhook. Name string }
WebhookInfo contains information about webhook.
Source Files ¶
- constructors.go
- custom_format.go
- default.go
- description.go
- enum.go
- equal.go
- examples.go
- faker.go
- field.go
- generics.go
- go.go
- ir.go
- json.go
- media.go
- nil_semantic.go
- operation.go
- panic.go
- params.go
- primitive.go
- recursion.go
- responses.go
- security.go
- server.go
- template_helpers.go
- type.go
- type_features.go
- type_iface.go
- validation.go