codegen

package
v1.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenFieldsFromProperties

func GenFieldsFromProperties(props []Property) []string

Given a list of schema descriptors, produce corresponding field names with JSON annotations

func GenStructFromSchema

func GenStructFromSchema(schema Schema) string

func PathToTypeName

func PathToTypeName(path []string) string

This converts a path, like Object/field1/nestedField into a go type name.

func PropertiesEqual

func PropertiesEqual(a, b Property) bool

func RefPathToGoType

func RefPathToGoType(refPath string) (string, error)

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

func SchemaHasAdditionalProperties(schema *openapi3.Schema) bool

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

func SchemaNameToTypeName(name string) string

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

func SortedSchemaKeys(dict map[string]*openapi3.SchemaRef) []string

This function returns the keys of the given SchemaRef dictionary in sorted order, since Golang scrambles dictionary keys

func StringInArray

func StringInArray(str string, array []string) bool

This function checks whether the specified string is present in an array of strings

func StringToGoComment

func StringToGoComment(in string) string

StringToGoComment renders a possible multi-line string as a valid Go-Comment. Each line is prefixed as a comment.

func ToCamelCase

func ToCamelCase(str string) string

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

type Property struct {
	Description   string
	JsonFieldName string
	Schema        Schema
	Required      bool
}

func (Property) GoFieldName

func (p Property) GoFieldName() string

func (Property) GoTypeDef

func (p Property) GoTypeDef() string

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

}

This describes a Schema, a type definition.

func GenerateGoSchema

func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error)

func (Schema) GetAdditionalTypeDefs

func (s Schema) GetAdditionalTypeDefs() []TypeDefinition

func (Schema) IsRef

func (s Schema) IsRef() bool

func (*Schema) MergeProperty

func (s *Schema) MergeProperty(p Property) error

func (Schema) TypeDecl

func (s Schema) TypeDecl() string

type SchemaDescriptor

type SchemaDescriptor struct {
	Fields                   []FieldDescriptor
	HasAdditionalProperties  bool
	AdditionalPropertiesType string
}

This describes a Schema, a type definition.

type TypeDefinition

type TypeDefinition struct {
	TypeName     string
	JsonName     string
	ResponseName string
	Schema       Schema
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL