Documentation ¶
Overview ¶
Package openapi provides common algorithms and data structures used to generate both OpenAPI v2 and v3 specifications from Goa designs.
Index ¶
- Constants
- Variables
- func ExtensionsFromExpr(mdata expr.MetaExpr) map[string]interface{}
- func GenerateResultTypeDefinition(api *expr.APIExpr, mt *expr.ResultTypeExpr, view string)
- func GenerateServiceDefinition(api *expr.APIExpr, res *expr.HTTPServiceExpr)
- func GenerateTypeDefinition(api *expr.APIExpr, ut *expr.UserTypeExpr)
- func GenerateTypeDefinitionWithName(api *expr.APIExpr, ut *expr.UserTypeExpr, typeName string)
- func MarshalJSON(v interface{}, extensions map[string]interface{}) ([]byte, error)
- func MarshalYAML(v interface{}, extensions map[string]interface{}) (interface{}, error)
- func ResultTypeRef(api *expr.APIExpr, mt *expr.ResultTypeExpr, view string) string
- func ResultTypeRefWithPrefix(api *expr.APIExpr, mt *expr.ResultTypeExpr, view string, prefix string) string
- func TagNamesFromExpr(mdatas ...expr.MetaExpr) (tagNames []string)
- func ToString(val interface{}) string
- func ToStringMap(val interface{}) interface{}
- func TypeRef(api *expr.APIExpr, ut *expr.UserTypeExpr) string
- func TypeRefWithPrefix(api *expr.APIExpr, ut *expr.UserTypeExpr, prefix string) string
- type ExternalDocs
- type Link
- type Media
- type Schema
- func APISchema(api *expr.APIExpr, r *expr.RootExpr) *Schema
- func AttributeTypeSchema(api *expr.APIExpr, at *expr.AttributeExpr) *Schema
- func AttributeTypeSchemaWithPrefix(api *expr.APIExpr, at *expr.AttributeExpr, prefix string) *Schema
- func NewSchema() *Schema
- func TypeSchema(api *expr.APIExpr, t expr.DataType) *Schema
- func TypeSchemaWithPrefix(api *expr.APIExpr, t expr.DataType, prefix string) *Schema
- type Tag
- type Type
Constants ¶
const ( // Array represents a JSON array. Array Type = "array" // Boolean represents a JSON boolean. Boolean = "boolean" // Integer represents a JSON number without a fraction or exponent part. Integer = "integer" // Number represents any JSON number. Number includes integer. Number = "number" // Null represents the JSON null value. Null = "null" // Object represents a JSON object. Object = "object" // String represents a JSON string. String = "string" // File is an extension used by Swagger to represent a file download. File = "file" )
const SchemaRef = "http://json-schema.org/draft-04/hyper-schema"
SchemaRef is the JSON Hyper-schema standard href.
Variables ¶
var ( // Definitions contains the generated JSON schema definitions Definitions map[string]*Schema )
Functions ¶
func ExtensionsFromExpr ¶
ExtensionsFromExpr generates swagger extensions from the given meta expression.
func GenerateResultTypeDefinition ¶
func GenerateResultTypeDefinition(api *expr.APIExpr, mt *expr.ResultTypeExpr, view string)
GenerateResultTypeDefinition produces the JSON schema corresponding to the given media type and given view.
func GenerateServiceDefinition ¶
func GenerateServiceDefinition(api *expr.APIExpr, res *expr.HTTPServiceExpr)
GenerateServiceDefinition produces the JSON schema corresponding to the given service. It stores the results in cachedSchema.
func GenerateTypeDefinition ¶
func GenerateTypeDefinition(api *expr.APIExpr, ut *expr.UserTypeExpr)
GenerateTypeDefinition produces the JSON schema corresponding to the given type.
func GenerateTypeDefinitionWithName ¶
func GenerateTypeDefinitionWithName(api *expr.APIExpr, ut *expr.UserTypeExpr, typeName string)
GenerateTypeDefinitionWithName produces the JSON schema corresponding to the given type with provided type name.
func MarshalJSON ¶
MarshalJSON produces the JSON resulting from encoding an object composed of the fields in v (which must me a struct) and the keys in extensions.
func MarshalYAML ¶
MarshalYAML produces the JSON resulting from encoding an object composed of the fields in v (which must me a struct) and the keys in extensions.
func ResultTypeRef ¶
ResultTypeRef produces the JSON reference to the media type definition with the given view.
func ResultTypeRefWithPrefix ¶
func ResultTypeRefWithPrefix(api *expr.APIExpr, mt *expr.ResultTypeExpr, view string, prefix string) string
ResultTypeRefWithPrefix produces the JSON reference to the media type definition with the given view and adds the provided prefix to the type name
func TagNamesFromExpr ¶
TagNamesFromExpr computes the names of the swagger tags specified in the given metadata expressions.
func ToString ¶
func ToString(val interface{}) string
ToString returns the string representation of the given type.
func ToStringMap ¶
func ToStringMap(val interface{}) interface{}
ToStringMap converts map[interface{}]interface{} to a map[string]interface{} when possible.
func TypeRef ¶
func TypeRef(api *expr.APIExpr, ut *expr.UserTypeExpr) string
TypeRef produces the JSON reference to the type definition.
func TypeRefWithPrefix ¶
TypeRefWithPrefix produces the JSON reference to the type definition and adds the provided prefix to the type name
Types ¶
type ExternalDocs ¶
type ExternalDocs struct { Description string `json:"description,omitempty"` URL string `json:"url,omitempty"` Extensions map[string]interface{} `json:"-" yaml:"-"` }
ExternalDocs represents an OpenAPI External Documentation object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#externalDocumentationObject
func DocsFromExpr ¶
func DocsFromExpr(docs *expr.DocsExpr, meta expr.MetaExpr) *ExternalDocs
DocsFromExpr builds a ExternalDocs from the Goa docs expression.
type Link ¶
type Link struct { Title string `json:"title,omitempty" yaml:"title,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Rel string `json:"rel,omitempty" yaml:"rel,omitempty"` Href string `json:"href,omitempty" yaml:"href,omitempty"` Method string `json:"method,omitempty" yaml:"method,omitempty"` Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"` TargetSchema *Schema `json:"targetSchema,omitempty" yaml:"targetSchema,omitempty"` ResultType string `json:"mediaType,omitempty" yaml:"mediaType,omitempty"` EncType string `json:"encType,omitempty" yaml:"encType,omitempty"` }
Link represents a "link" field in a JSON hyper schema.
type Media ¶
type Media struct { BinaryEncoding string `json:"binaryEncoding,omitempty" yaml:"binaryEncoding,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"` }
Media represents a "media" field in a JSON hyper schema.
type Schema ¶
type Schema struct { Schema string `json:"$schema,omitempty" yaml:"$schema,omitempty"` // Core schema ID string `json:"id,omitempty" yaml:"id,omitempty"` Title string `json:"title,omitempty" yaml:"title,omitempty"` Type Type `json:"type,omitempty" yaml:"type,omitempty"` Items *Schema `json:"items,omitempty" yaml:"items,omitempty"` Properties map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"` Definitions map[string]*Schema `json:"definitions,omitempty" yaml:"definitions,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` DefaultValue interface{} `json:"default,omitempty" yaml:"default,omitempty"` Example interface{} `json:"example,omitempty" yaml:"example,omitempty"` // Hyper schema Media *Media `json:"media,omitempty" yaml:"media,omitempty"` ReadOnly bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"` PathStart string `json:"pathStart,omitempty" yaml:"pathStart,omitempty"` Links []*Link `json:"links,omitempty" yaml:"links,omitempty"` Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` // Validation Enum []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"` Format string `json:"format,omitempty" yaml:"format,omitempty"` Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"` Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"` Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"` MinLength *int `json:"minLength,omitempty" yaml:"minLength,omitempty"` MaxLength *int `json:"maxLength,omitempty" yaml:"maxLength,omitempty"` MinItems *int `json:"minItems,omitempty" yaml:"minItems,omitempty"` MaxItems *int `json:"maxItems,omitempty" yaml:"maxItems,omitempty"` Required []string `json:"required,omitempty" yaml:"required,omitempty"` AdditionalProperties bool `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"` // Union AnyOf []*Schema `json:"anyOf,omitempty" yaml:"anyOf,omitempty"` // Extensions defines the swagger extensions. Extensions map[string]interface{} `json:"-" yaml:"-"` }
Schema represents an instance of a JSON schema. See http://json-schema.org/documentation.html
func AttributeTypeSchema ¶
func AttributeTypeSchema(api *expr.APIExpr, at *expr.AttributeExpr) *Schema
AttributeTypeSchema produces the JSON schema corresponding to the given attribute.
func AttributeTypeSchemaWithPrefix ¶
func AttributeTypeSchemaWithPrefix(api *expr.APIExpr, at *expr.AttributeExpr, prefix string) *Schema
AttributeTypeSchemaWithPrefix produces the JSON schema corresponding to the given attribute and adds the provided prefix to the type name
func TypeSchema ¶
TypeSchema produces the JSON schema corresponding to the given data type.
func TypeSchemaWithPrefix ¶
TypeSchemaWithPrefix produces the JSON schema corresponding to the given data type and adds the provided prefix to the type name
func (*Schema) JSON ¶
JSON serializes the schema into JSON. It makes sure the "$schema" standard field is set if needed prior to delegating to the standard JSON marshaler.
func (*Schema) MarshalJSON ¶
MarshalJSON returns the JSON encoding of s.
func (*Schema) MarshalYAML ¶
MarshalYAML returns value which marshaled in place of the original value
type Tag ¶
type Tag struct { // Name of the tag. Name string `json:"name,omitempty" yaml:"name,omitempty"` // Description is a short description of the tag. // GFM syntax can be used for rich text representation. Description string `json:"description,omitempty" yaml:"description,omitempty"` // ExternalDocs is additional external documentation for this tag. ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"` // Extensions defines the swagger extensions. Extensions map[string]interface{} `json:"-" yaml:"-"` }
Tag allows adding meta data to a single tag that is used by the Operation Object. It is not mandatory to have a Tag Object per tag used there.
func TagsFromExpr ¶
TagsFromExpr extracts the swagger related metadata from the given expression.
func (Tag) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (Tag) MarshalYAML ¶
MarshalYAML returns value which marshaled in place of the original value
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package openapiv2 contains the algorithms and data structures used to generate OpenAPI v2 specifications from Goa designs.
|
Package openapiv2 contains the algorithms and data structures used to generate OpenAPI v2 specifications from Goa designs. |
Package openapiv3 contains the algorithms and data structures used to generate OpenAPI v3 specifications from Goa designs.
|
Package openapiv3 contains the algorithms and data structures used to generate OpenAPI v3 specifications from Goa designs. |