Documentation ¶
Index ¶
- func GenFieldsFromProperties(props []Property) []string
- func GenStructFromSchema(schema Schema) string
- func PathToTypeName(path []string) string
- func PropertiesEqual(a, b Property) bool
- func RefPathToGoType(refPath string) (string, error)
- func SchemaHasAdditionalProperties(schema *openapi3.Schema) bool
- func SchemaNameToTypeName(name string) string
- func SortedSchemaKeys(dict map[string]*openapi3.SchemaRef) []string
- func StringInArray(str string, array []string) bool
- func StringToGoComment(in string) string
- func ToCamelCase(str string) string
- type FieldDescriptor
- type Property
- type Schema
- type SchemaDescriptor
- type TypeDefinition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenFieldsFromProperties ¶
Given a list of schema descriptors, produce corresponding field names with JSON annotations
func GenStructFromSchema ¶
func PathToTypeName ¶
This converts a path, like Object/field1/nestedField into a go type name.
func PropertiesEqual ¶
func RefPathToGoType ¶
This function takes a $ref value and converts it to a Go typename. #/components/schemas/Foo -> Foo #/components/parameters/Bar -> Bar #/components/responses/Baz -> Baz Remote components (document.json#/Foo) are not yet supported URL components (http://deepmap.com/schemas/document.json#Foo) are not yet supported We only support flat components for now, so no components in a schema under components.
func SchemaHasAdditionalProperties ¶
According to the spec, additionalProperties may be true, false, or a schema. If not present, true is implied. If it's a schema, true is implied. If it's false, no additional properties are allowed. We're going to act a little differently, in that if you want additionalProperties code to be generated, you must specify an additionalProperties type If additionalProperties it true/false, this field will be non-nil.
func SchemaNameToTypeName ¶
Converts a Schema name to a valid Go type name. It converts to camel case, and makes sure the name is valid in Go
func SortedSchemaKeys ¶
This function returns the keys of the given SchemaRef dictionary in sorted order, since Golang scrambles dictionary keys
func StringInArray ¶
This function checks whether the specified string is present in an array of strings
func StringToGoComment ¶
StringToGoComment renders a possible multi-line string as a valid Go-Comment. Each line is prefixed as a comment.
func ToCamelCase ¶
Types ¶
type FieldDescriptor ¶
type FieldDescriptor struct { Required bool // Is the schema required? If not, we'll pass by pointer GoType string // The Go type needed to represent the json type. GoName string // The Go compatible type name for the type JsonName string // The json type name for the type IsRef bool // Is this schema a reference to predefined object? }
type Property ¶
func (Property) GoFieldName ¶
type Schema ¶
type Schema struct { GoType string // The Go type needed to represent the schema RefType string // If the type has a type name, this is set Properties []Property // For an object, the fields with names HasAdditionalProperties bool // Whether we support additional properties AdditionalPropertiesType *Schema // And if we do, their type AdditionalTypes []TypeDefinition // We may need to generate auxiliary helper types, stored here Nullable bool IsEnum bool }
This describes a Schema, a type definition.
func GenerateGoSchema ¶
func (Schema) GetAdditionalTypeDefs ¶
func (s Schema) GetAdditionalTypeDefs() []TypeDefinition
func (*Schema) MergeProperty ¶
type SchemaDescriptor ¶
type SchemaDescriptor struct { Fields []FieldDescriptor HasAdditionalProperties bool AdditionalPropertiesType string }
This describes a Schema, a type definition.