Documentation ¶
Index ¶
- Variables
- func IsDebug(ctx context.Context) bool
- func SetDebug(ctx context.Context) context.Context
- type BoolOrSchema
- type Config
- type Discriminator
- type GoBaseType
- type Helper
- type Import
- type Imports
- type ItemsField
- type JSONType
- type Loader
- type Plan
- type Planner
- type RefOrSchema
- type Schema
- type TagMap
- type TypeField
- type TypeInfo
Constants ¶
This section is empty.
Variables ¶
var ErrContinue = errors.New("continue")
ErrContinue can be returned from a Planner if there is no match. Other planners may then be tried.
Functions ¶
Types ¶
type BoolOrSchema ¶
type BoolOrSchema struct { Bool *bool Schema *RefOrSchema }
BoolOrSchema may have either a boolean or a RefOrSchema.
func (*BoolOrSchema) Present ¶
func (a *BoolOrSchema) Present() bool
func (*BoolOrSchema) UnmarshalJSON ¶
func (a *BoolOrSchema) UnmarshalJSON(data []byte) error
UnmarshalJSON performs some custom deserialization of JSON into BoolOrSchema
type Config ¶
type Config struct { GoPath string `json:"gopath"` Exclude bool `json:"exclude"` Discriminator Discriminator `json:"Discriminator"` NoValidate bool `json:"noValidate"` PromoteFields bool `json:"promoteFields"` NoOmitEmpty bool `json:"noOmitEmpty"` }
Config is a series of jsonschema2go user extensions
type Discriminator ¶
type Discriminator struct { PropertyName string `json:"propertyName"` Mapping map[string]string `json:"mapping"` }
Discriminator is jsonschema2go specific info for discriminating between multiple oneOf objects
func (*Discriminator) IsSet ¶
func (d *Discriminator) IsSet() bool
IsSet returns whether there is a discriminator present.
type GoBaseType ¶
type GoBaseType int
const ( GoUnknown GoBaseType = iota GoBool GoInt64 GoFloat64 GoString GoEmpty GoSlice GoArray GoMap GoStruct )
type Helper ¶
type Helper interface { Loader Dep(ctx context.Context, schemas ...*Schema) error TypeInfo(s *Schema) (TypeInfo, error) ErrSimpleTypeUnknown(err error) bool DetectSimpleType(ctx context.Context, s *Schema) (JSONType, error) DetectGoBaseType(ctx context.Context, s *Schema) (GoBaseType, error) TypeInfoHinted(s *Schema, t JSONType) TypeInfo JSONPropertyExported(name string) string Primitive(s JSONType) string }
Helper is an interface provided to each planner
type Import ¶
type Import struct {
GoPath, Alias string
}
Import contains GoPath and Alias information, if any.
type Imports ¶
type Imports struct {
// contains filtered or unexported fields
}
Imports encapsulates knowledge about the current imports and namespace. It provides utilities for generating appropriately qualified names.
func NewImports ¶
NewImports creates a new Imports. Paths and aliases for the `importGoPaths` will be derived according to the `currentGoPath`
func (*Imports) CurPackage ¶
CurPackage the current package for this Imports
type ItemsField ¶
type ItemsField struct { Items *RefOrSchema TupleFields []*RefOrSchema }
ItemsField contains information indicating whether the modified array is a dynamically sized list of multiple types or a "tuple" -- a specifically sized array with potentially different types for each position.
func (*ItemsField) Present ¶
func (i *ItemsField) Present() bool
func (*ItemsField) UnmarshalJSON ¶
func (i *ItemsField) UnmarshalJSON(data []byte) error
UnmarshalJSON conditionally deserializes into ItemsField according to the shape of the provided JSON
type Loader ¶
type Loader interface { io.Closer // Read returns a schema for a URL Load(ctx context.Context, u *url.URL) (*Schema, error) }
Loader is the contract required to be able to resolve a schema.
type Plan ¶
type Plan interface { // Type returns the TypeInfo for the current type Type() TypeInfo // Deps returns any dependent types for the current type (i.e. any types requiring import) Deps() []TypeInfo // Execute is provided a resolved imports and should provide the type rendered as a string. Execute(imports *Imports) (string, error) }
Plan is the contract that must be filled for a type to be rendered.
type Planner ¶
type Planner interface { // Plan generates a Plan from a Schema. If the error matches `errors.Is(err, ErrContinue)`, processing may continue. Plan(ctx context.Context, helper Helper, schema *Schema) (Plan, error) }
Planner is a strategy for generating a Plan from a Schema
type RefOrSchema ¶
type RefOrSchema struct {
// contains filtered or unexported fields
}
RefOrSchema is either a schema or a reference to a schema.
func NewRefOrSchema ¶
func NewRefOrSchema(s *Schema, ref *string) *RefOrSchema
NewRefOrSchema is a convenience constructor for RefOrSchema
func (*RefOrSchema) Resolve ¶
Resolve either returns the schema if set or else resolves the reference using the referer schema and loader.
func (*RefOrSchema) UnmarshalJSON ¶
func (r *RefOrSchema) UnmarshalJSON(b []byte) error
UnmarshalJSON conditionally deserializes the JSON, either into a reference or a schema.
type Schema ¶
type Schema struct { // this could be a ref Ref *string `json:"$ref,omitempty"` // meta ID *url.URL `json:"-"` // set either from "$id", "id", or calculated based on parent (see IDCalc); never nil IDCalc bool `json:"-"` // whether this ID was calculated Src *url.URL `json:"-"` // the resource from which this schema was loaded; never nil Schema string `json:"$schema,omitempty"` // number qualifiers MultipleOf *float64 `json:"multipleOf,omitempty"` Maximum *float64 `json:"maximum,omitempty"` ExclusiveMaximum *bool `json:"exclusiveMaximum,omitempty"` Minimum *float64 `json:"minimum,omitempty"` ExclusiveMinimum *bool `json:"exclusiveMinimum,omitempty"` // string qualifiers MaxLength *uint64 `json:"maxLength,omitempty"` MinLength uint64 `json:"minLength,omitempty"` Pattern *string `json:"pattern,omitempty"` // array qualifiers AdditionalItems *BoolOrSchema `json:"additionalItems,omitempty"` Items *ItemsField `json:"items,omitempty"` MaxItems *uint64 `json:"maxItems,omitempty"` MinItems uint64 `json:"minItems,omitempty"` UniqueItems bool `json:"uniqueItems,omitempty"` // object qualifiers MaxProperties *uint64 `json:"maxProperties,omitempty"` MinProperties uint64 `json:"minProperties,omitempty"` Required []string `json:"required,omitempty"` AdditionalProperties *BoolOrSchema `json:"additionalProperties,omitempty"` Definitions map[string]*RefOrSchema `json:"definitions,omitempty"` Properties map[string]*RefOrSchema `json:"properties,omitempty"` PatternProperties map[string]*RefOrSchema `json:"patternProperties,omitempty"` Dependencies map[string]*RefOrSchema `json:"dependencies,omitempty"` // extra special Enum []interface{} `json:"enum,omitempty"` Type *TypeField `json:"type,omitempty"` Format string `json:"format,omitempty"` // polymorphic support AllOf []*RefOrSchema `json:"allOf,omitempty"` AnyOf []*RefOrSchema `json:"anyOf,omitempty"` OneOf []*RefOrSchema `json:"oneOf,omitempty"` Not *RefOrSchema `json:"not,omitempty"` // jsonschema2go Config Config Config `json:"x-jsonschema2go"` // user extensible Annotations TagMap `json:"-"` }
Schema is the core representation of the JSONSchema meta schema.
func (*Schema) ChooseType ¶
ChooseType returns the best known type for this field.
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON is custom JSON deserialization for the Schema type
type TagMap ¶
type TagMap map[string]json.RawMessage
TagMap contains all of the different user extended tags as json.RawMessage for later deserialization
func (TagMap) GetString ¶
GetString attempts to deserialize the value for the provided key into a string. If the key is absent or there is an error deserializing the value, the returned string will be empty.
type TypeField ¶
type TypeField []JSONType
TypeField wraps the type field in JSONSchema, supporting either an array of types or a single type as the metaschema allows
func (*TypeField) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into the TypeField