Documentation
¶
Index ¶
- func CapitaliseFirstLetter(s string) string
- func Contains(s []string, e string) bool
- func GetGolangName(s string) string
- func GetOrderedFieldNames(m map[string]*Field) []string
- func GetOrderedStructNames(m map[string]*Struct) []string
- func IsNotAGoNameCharacter(r rune) bool
- func LineAndCharacter(bytes []byte, offset int) (line int, character int, err error)
- func Output(w io.Writer, g *Generator, pkg string, originatingPaths []string, debug bool) error
- type AdditionalProperties
- type Field
- type Generator
- type RefResolver
- type Schema
- func (schema *Schema) FixMissingTypeValue()
- func (schema *Schema) GetRoot() *Schema
- func (schema *Schema) ID() string
- func (schema *Schema) Init()
- func (schema *Schema) IsRoot() bool
- func (schema *Schema) MultiType() ([]string, bool)
- func (schema *Schema) Type() (firstOrDefault string, multiple bool)
- type Struct
- type TypeInfo
- func (p *TypeInfo) AddAliasFor(name string)
- func (p *TypeInfo) AddFieldReference(f *Field)
- func (p *TypeInfo) GetTypeAsString() string
- func (p *TypeInfo) IsAlias() bool
- func (p *TypeInfo) LongName() string
- func (p *TypeInfo) RemoveFieldReference(f *Field) bool
- func (p *TypeInfo) Replaces(old *TypeInfo)
- func (p *TypeInfo) ShortName() string
- func (p *TypeInfo) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CapitaliseFirstLetter ¶
func GetGolangName ¶
func GetOrderedFieldNames ¶
func GetOrderedStructNames ¶
func IsNotAGoNameCharacter ¶
func LineAndCharacter ¶
Types ¶
type AdditionalProperties ¶
type AdditionalProperties Schema
AdditionalProperties handles additional properties present in the JSON schema.
func (*AdditionalProperties) UnmarshalJSON ¶
func (ap *AdditionalProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON handles unmarshalling AdditionalProperties from JSON.
type Field ¶
type Field struct {
Id string
// The golang name, e.g. "Address1"
Name string
// The JSON name, e.g. "address1"
JSONName string
// The golang type of the field, e.g. a built-in type like "string" or the name of a struct generated
// from the JSON schema.
Type *TypeInfo
// Required is set to true when the field is required.
Required bool
Descriptions []string
}
Field defines the data required to generate a field in Go.
type Generator ¶
type Generator struct {
Structs map[string]*Struct
Aliases map[string]*Field
// contains filtered or unexported fields
}
Generator will produce structs from the JSON schema.
func (*Generator) CreateTypes ¶
CreateTypes creates types from the JSON schemas, keyed by the golang name.
type RefResolver ¶
type RefResolver struct {
// contains filtered or unexported fields
}
RefResolver allows references to be resolved.
func NewRefResolver ¶
func NewRefResolver(schemas []*Schema) *RefResolver
NewRefResolver creates a reference resolver.
func (*RefResolver) GetPath ¶
func (r *RefResolver) GetPath(schema *Schema) string
GetPath generates a path to given schema.
func (*RefResolver) GetSchemaByReference ¶
func (r *RefResolver) GetSchemaByReference(schema *Schema) (*Schema, error)
GetSchemaByReference returns the schema.
type Schema ¶
type Schema struct {
// SchemaType identifies the schema version.
// http://json-schema.org/draft-07/json-schema-core.html#rfc.section.7
SchemaType string `json:"$schema"`
// ID{04,06} is the schema URI identifier.
// http://json-schema.org/draft-07/json-schema-core.html#rfc.section.8.2
ID04 string `json:"id"` // up to draft-04
ID06 string `json:"$id"` // from draft-06 onwards
// Title and Description state the intent of the schema.
Title string
Description string
// TypeValue is the schema instance type.
// http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.6.1.1
TypeValue interface{} `json:"type"`
// Definitions are inline re-usable schemas.
// http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.9
Definitions map[string]*Schema
// Properties, Required and AdditionalProperties describe an object's child instances.
// http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.6.5
Properties map[string]*Schema
Required []string
// "additionalProperties": {...}
AdditionalProperties *AdditionalProperties
// "additionalProperties": false
AdditionalPropertiesBool *bool `json:"-"`
AnyOf []*Schema
AllOf []*Schema
OneOf []*Schema
// Default can be used to supply a default JSON value associated with a particular schema.
// http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.10.2
Default interface{}
// Examples ...
// http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.10.4
Examples []interface{}
// Reference is a URI reference to a schema.
// http://json-schema.org/draft-07/json-schema-core.html#rfc.section.8
Reference string `json:"$ref"`
// Items represents the types that are permitted in the array.
// http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.6.4
Items *Schema
// NameCount is the number of times the instance name was encountered across the schema.
NameCount int `json:"-" `
// Parent schema
Parent *Schema `json:"-" `
// Key of this schema i.e. { "JSONKey": { "type": "object", ....
JSONKey string `json:"-" `
// path element - for creating a path by traversing back to the root element
PathElement string `json:"-"`
// calculated struct name of this object, cached here
GeneratedType *TypeInfo `json:"-"`
}
Schema represents JSON schema.
func ParseWithSchemaKeyRequired ¶
func ParseWithSchemaKeyRequired(schema string, uri *url.URL, schemaKeyRequired bool) (*Schema, error)
ParseWithSchemaKeyRequired parses a JSON schema from a string with a flag to set whether the schema key is required.
func ReadInputFiles ¶
ReadInputFiles from disk and convert to JSON schema.
func (*Schema) FixMissingTypeValue ¶
func (schema *Schema) FixMissingTypeValue()
FixMissingTypeValue is backwards compatible, guessing the users intention when they didn't specify a type.
type Struct ¶
type Struct struct {
// The ID within the JSON schema, e.g. #/definitions/address
ID string
// The golang type information, e.g. "Address" or "*Address"
TypeInfo *TypeInfo
// Description of the struct
Description string
Fields map[string]*Field
GenerateCode bool
AdditionalType *TypeInfo
}
Struct defines the data required to generate a struct in Go.
type TypeInfo ¶ added in v0.0.7
type TypeInfo struct {
Id string
Name string
PrimitiveType string
SubType *TypeInfo
IsPointer bool
// contains filtered or unexported fields
}