Documentation ¶
Overview ¶
Package oas contains the logic that determines how to map OpenAPI schemas to the intermediate attrmapper types. OpenAPI 3.1 schemas are compatible with JSON schema, and OpenAPI 3.0 are "mostly" compatible.
Index ¶
- Variables
- func BuildSchema(proxy *base.SchemaProxy, schemaOpts SchemaOpts, globalOpts GlobalSchemaOpts) (*OASSchema, *SchemaError)
- type GlobalSchemaOpts
- type NodeType
- type OASSchema
- func (s *OASSchema) BuildBoolDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildBoolElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildBoolProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildBoolResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildCollectionDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildCollectionElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildCollectionProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildCollectionResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildDataSourceAttribute(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildDataSourceAttributes() (attrmapper.DataSourceAttributes, *SchemaError)
- func (s *OASSchema) BuildElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildIntegerDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildIntegerElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildIntegerProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildIntegerResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildMapDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildMapElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildMapProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildMapResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildNumberDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildNumberElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildNumberProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildNumberResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildObjectElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildProviderAttribute(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildProviderAttributes() (attrmapper.ProviderAttributes, *SchemaError)
- func (s *OASSchema) BuildResourceAttribute(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildResourceAttributes() (attrmapper.ResourceAttributes, *SchemaError)
- func (s *OASSchema) BuildSingleNestedDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildSingleNestedProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildSingleNestedResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) BuildStringDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
- func (s *OASSchema) BuildStringElementType() (schema.ElementType, *SchemaError)
- func (s *OASSchema) BuildStringProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
- func (s *OASSchema) BuildStringResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
- func (s *OASSchema) GetComputability(name string) schema.ComputedOptionalRequired
- func (s *OASSchema) GetDeprecationMessage() *string
- func (s *OASSchema) GetDescription() *string
- func (s *OASSchema) GetFloatValidators() []schema.Float64Validator
- func (s *OASSchema) GetIgnoresForNested(name string) []string
- func (s *OASSchema) GetIntegerValidators() []schema.Int64Validator
- func (s *OASSchema) GetListValidators() []schema.ListValidator
- func (s *OASSchema) GetMapValidators() []schema.MapValidator
- func (s *OASSchema) GetOptionalOrRequired(name string) schema.OptionalRequired
- func (s *OASSchema) GetSetValidators() []schema.SetValidator
- func (s *OASSchema) GetStringValidators() []schema.StringValidator
- func (s *OASSchema) IsMap() bool
- func (s *OASSchema) IsPropertyIgnored(name string) bool
- func (s *OASSchema) IsSensitive() *bool
- func (s *OASSchema) NestSchemaError(err *SchemaError, propName string) *SchemaError
- func (s *OASSchema) SchemaErrorFromProperty(err error, propName string) *SchemaError
- type SchemaError
- type SchemaOpts
Constants ¶
This section is empty.
Variables ¶
var ErrMultiTypeSchema = errors.New("unsupported multi-type, attribute cannot be created")
var ErrSchemaNotFound = errors.New("no compatible schema found")
Functions ¶
func BuildSchema ¶
func BuildSchema(proxy *base.SchemaProxy, schemaOpts SchemaOpts, globalOpts GlobalSchemaOpts) (*OASSchema, *SchemaError)
BuildSchema will build a schema from a schema proxy. It can also handle nullable schemas/types, implemented with oneOf/anyOf OAS keywords or an array on the "type" property
Types ¶
type GlobalSchemaOpts ¶
type GlobalSchemaOpts struct { // OverrideComputability will set all attribute and nested attribute `ComputedOptionalRequired` fields // to this value. This ensures that an optional attribute from a higher precedence operation, such as a // create request for a resource, does not become required from a lower precedence operation, such as an // read response for a resource. OverrideComputability schema.ComputedOptionalRequired }
GlobalSchemaOpts is passed recursively through built OASSchema structs. This is used for options that need to control the entire of a schema and it's potential nested schemas, like overriding computability. (Required, Optional, Computed)
type OASSchema ¶
type OASSchema struct { Type string Format string Schema *base.Schema GlobalSchemaOpts GlobalSchemaOpts SchemaOpts SchemaOpts }
func BuildSchemaFromRequest ¶
func BuildSchemaFromRequest(op *high.Operation, schemaOpts SchemaOpts, globalOpts GlobalSchemaOpts) (*OASSchema, error)
BuildSchemaFromRequest will extract and build the schema from the request body of an operation
- Media type will default to "application/json", then continue to the next available media type with a schema
func BuildSchemaFromResponse ¶
func BuildSchemaFromResponse(op *high.Operation, schemaOpts SchemaOpts, globalOpts GlobalSchemaOpts) (*OASSchema, error)
BuildSchemaFromResponse will extract and build the schema from the response body of an operation
- Response codes of 200 and then 201 will be prioritized, then will continue to the next available 2xx code
- Media type will default to "application/json", then continue to the next available media type with a schema
func (*OASSchema) BuildBoolDataSource ¶
func (s *OASSchema) BuildBoolDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildBoolElementType ¶
func (s *OASSchema) BuildBoolElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildBoolProvider ¶
func (s *OASSchema) BuildBoolProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildBoolResource ¶
func (s *OASSchema) BuildBoolResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildCollectionDataSource ¶
func (s *OASSchema) BuildCollectionDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildCollectionElementType ¶
func (s *OASSchema) BuildCollectionElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildCollectionProvider ¶
func (s *OASSchema) BuildCollectionProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildCollectionResource ¶
func (s *OASSchema) BuildCollectionResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildDataSourceAttribute ¶
func (s *OASSchema) BuildDataSourceAttribute(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildDataSourceAttributes ¶
func (s *OASSchema) BuildDataSourceAttributes() (attrmapper.DataSourceAttributes, *SchemaError)
func (*OASSchema) BuildElementType ¶
func (s *OASSchema) BuildElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildIntegerDataSource ¶
func (s *OASSchema) BuildIntegerDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildIntegerElementType ¶
func (s *OASSchema) BuildIntegerElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildIntegerProvider ¶
func (s *OASSchema) BuildIntegerProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildIntegerResource ¶
func (s *OASSchema) BuildIntegerResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildMapDataSource ¶
func (s *OASSchema) BuildMapDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildMapElementType ¶
func (s *OASSchema) BuildMapElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildMapProvider ¶
func (s *OASSchema) BuildMapProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildMapResource ¶
func (s *OASSchema) BuildMapResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildNumberDataSource ¶
func (s *OASSchema) BuildNumberDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildNumberElementType ¶
func (s *OASSchema) BuildNumberElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildNumberProvider ¶
func (s *OASSchema) BuildNumberProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildNumberResource ¶
func (s *OASSchema) BuildNumberResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildObjectElementType ¶
func (s *OASSchema) BuildObjectElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildProviderAttribute ¶
func (s *OASSchema) BuildProviderAttribute(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildProviderAttributes ¶
func (s *OASSchema) BuildProviderAttributes() (attrmapper.ProviderAttributes, *SchemaError)
func (*OASSchema) BuildResourceAttribute ¶
func (s *OASSchema) BuildResourceAttribute(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildResourceAttributes ¶
func (s *OASSchema) BuildResourceAttributes() (attrmapper.ResourceAttributes, *SchemaError)
func (*OASSchema) BuildSingleNestedDataSource ¶
func (s *OASSchema) BuildSingleNestedDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildSingleNestedProvider ¶
func (s *OASSchema) BuildSingleNestedProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildSingleNestedResource ¶
func (s *OASSchema) BuildSingleNestedResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) BuildStringDataSource ¶
func (s *OASSchema) BuildStringDataSource(name string, computability schema.ComputedOptionalRequired) (attrmapper.DataSourceAttribute, *SchemaError)
func (*OASSchema) BuildStringElementType ¶
func (s *OASSchema) BuildStringElementType() (schema.ElementType, *SchemaError)
func (*OASSchema) BuildStringProvider ¶
func (s *OASSchema) BuildStringProvider(name string, optionalOrRequired schema.OptionalRequired) (attrmapper.ProviderAttribute, *SchemaError)
func (*OASSchema) BuildStringResource ¶
func (s *OASSchema) BuildStringResource(name string, computability schema.ComputedOptionalRequired) (attrmapper.ResourceAttribute, *SchemaError)
func (*OASSchema) GetComputability ¶
func (s *OASSchema) GetComputability(name string) schema.ComputedOptionalRequired
TODO: Figure out a better way to handle computability, since it differs with provider vs. datasource/resource
func (*OASSchema) GetDeprecationMessage ¶
GetDeprecationMessage returns a deprecation message if the deprecated property is enabled. It defaults the message to "This attribute is deprecated" unless the SchemaOpts.OverrideDeprecationMessage is set.
func (*OASSchema) GetDescription ¶
func (*OASSchema) GetFloatValidators ¶
func (s *OASSchema) GetFloatValidators() []schema.Float64Validator
func (*OASSchema) GetIgnoresForNested ¶ added in v0.2.0
GetIgnoresForNested is a helper function that will return all nested ignores for a property. If no ignores or nested ignores are found, returns an empty string slice.
func (*OASSchema) GetIntegerValidators ¶
func (s *OASSchema) GetIntegerValidators() []schema.Int64Validator
func (*OASSchema) GetListValidators ¶
func (s *OASSchema) GetListValidators() []schema.ListValidator
func (*OASSchema) GetMapValidators ¶
func (s *OASSchema) GetMapValidators() []schema.MapValidator
func (*OASSchema) GetOptionalOrRequired ¶
func (s *OASSchema) GetOptionalOrRequired(name string) schema.OptionalRequired
func (*OASSchema) GetSetValidators ¶
func (s *OASSchema) GetSetValidators() []schema.SetValidator
func (*OASSchema) GetStringValidators ¶
func (s *OASSchema) GetStringValidators() []schema.StringValidator
func (*OASSchema) IsMap ¶
IsMap checks the `additionalProperties` field to determine if a map type is appropriate (refer to JSON Schema - additionalProperties).
func (*OASSchema) IsPropertyIgnored ¶ added in v0.2.0
IsPropertyIgnored checks if a property should be ignored
func (*OASSchema) IsSensitive ¶
func (*OASSchema) NestSchemaError ¶
func (s *OASSchema) NestSchemaError(err *SchemaError, propName string) *SchemaError
NestSchemaError is a helper function for creating a nested SchemaError struct for a property.
func (*OASSchema) SchemaErrorFromProperty ¶
func (s *OASSchema) SchemaErrorFromProperty(err error, propName string) *SchemaError
SchemaErrorFromProperty is a helper function for creating an SchemaError struct for a property.
type SchemaError ¶
type SchemaError struct {
// contains filtered or unexported fields
}
SchemaError contains additional details about an error that occurred when processing an OpenAPI schema, such as the line number of the invalid schema or nested path information.
func NewSchemaError ¶
func NewSchemaError(err error, lineNumber int, path ...string) *SchemaError
NewSchemaError returns a new SchemaError error struct
func SchemaErrorFromNode ¶
func SchemaErrorFromNode(err error, schema *base.Schema, nodeType NodeType) *SchemaError
SchemaErrorFromNode returns a new SchemaError error struct that has no path information, using a schema node to get the line number if available.
func SchemaErrorFromProxy ¶
func SchemaErrorFromProxy(err error, proxy *base.SchemaProxy) *SchemaError
SchemaErrorFromProxy returns a new SchemaError error struct that has no path information, using a schema proxy to get the line number.
func (*SchemaError) Error ¶
func (e *SchemaError) Error() string
Error implements the error interface by returning the original error string
func (*SchemaError) LineNumber ¶
func (e *SchemaError) LineNumber() int
LineNumber returns the line number closest to the schema where the error occurred.
func (*SchemaError) NestedSchemaError ¶
func (e *SchemaError) NestedSchemaError(parentName string, lineNumber int) *SchemaError
NestedSchemaError creates a new SchemaError, appending the parent name to the path. This allows a parent OpenAPI schema to preserve the error and line number from a child schema, while creating a path name that is an absolute reference.
If no line number exists for the child schema, the parent schema line number will be added.
func (*SchemaError) Path ¶
func (e *SchemaError) Path() string
Path returns an absolute reference to the schema where the error occurred.
type SchemaOpts ¶
type SchemaOpts struct { // Ignores contains all potentially relevant ignores for a schema and it's potential nested schemas Ignores []string // OverrideDeprecationMessage will set the attribute deprecation message to // this field if populated, otherwise the attribute deprecation message will // be set to a default "This attribute is deprecated." message when the // deprecated property is enabled. OverrideDeprecationMessage string // OverrideDescription will set the attribute description to this field if populated, otherwise the attribute description // will be set to the description field of the `schema`. OverrideDescription string }
SchemaOpts is NOT passed recursively through built OASSchema structs, and will only be available to the top level schema. This is used for options that need to control just the top level schema, like overriding descriptions.