Documentation ¶
Overview ¶
Package openapi provides tools and mappings for OpenAPI specs.
Index ¶
- Constants
- func SanitizeMethodPath(method, pathPattern string) (cleanMethod string, cleanPath string, pathParams []string, err error)
- func WithOperationCtx(oc OperationContext, isProcessingResponse bool, in In) func(rc *jsonschema.ReflectContext)
- type ContentOption
- type ContentUnit
- type In
- type JSONSchemaCallback
- type JSONSchemaWalker
- type OperationContext
- type OperationInfo
- type OperationState
- type Reflector
- type RequestBodyEnforcer
- type RequestJSONBodyEnforcer
- type SpecSchema
Constants ¶
const ( InPath = In("path") InQuery = In("query") InHeader = In("header") InCookie = In("cookie") InFormData = In("formData") InBody = In("body") )
In values enumeration.
Variables ¶
This section is empty.
Functions ¶
func SanitizeMethodPath ¶
func SanitizeMethodPath(method, pathPattern string) (cleanMethod string, cleanPath string, pathParams []string, err error)
SanitizeMethodPath validates method and parses path element names.
func WithOperationCtx ¶
func WithOperationCtx(oc OperationContext, isProcessingResponse bool, in In) func(rc *jsonschema.ReflectContext)
WithOperationCtx is a jsonschema.ReflectContext option.
Types ¶
type ContentUnit ¶
type ContentUnit struct { Structure interface{} ContentType string Format string HTTPStatus int Description string // contains filtered or unexported fields }
ContentUnit defines HTTP content.
func (ContentUnit) FieldMapping ¶
func (c ContentUnit) FieldMapping(in In) map[string]string
FieldMapping returns custom field mapping.
func (*ContentUnit) SetFieldMapping ¶
func (c *ContentUnit) SetFieldMapping(in In, fieldToParamName map[string]string)
SetFieldMapping sets custom field mapping.
type JSONSchemaCallback ¶
type JSONSchemaCallback func(in In, paramName string, schema *jsonschema.SchemaOrBool, required bool) error
JSONSchemaCallback is a user function called by JSONSchemaWalker.
type JSONSchemaWalker ¶
type JSONSchemaWalker interface { ResolveJSONSchemaRef(ref string) (s jsonschema.SchemaOrBool, found bool) WalkRequestJSONSchemas(method string, cu ContentUnit, cb JSONSchemaCallback, done func(oc OperationContext)) error WalkResponseJSONSchemas(cu ContentUnit, cb JSONSchemaCallback, done func(oc OperationContext)) error }
JSONSchemaWalker can extract JSON schemas (for example, for validation purposes) from a ContentUnit.
type OperationContext ¶
type OperationContext interface { OperationInfo OperationState Method() string PathPattern() string Request() []ContentUnit Response() []ContentUnit AddReqStructure(i interface{}, options ...ContentOption) AddRespStructure(o interface{}, options ...ContentOption) UnknownParamsAreForbidden(in In) bool }
OperationContext defines operation and processing state.
func OperationCtx ¶
func OperationCtx(rc *jsonschema.ReflectContext) (OperationContext, bool)
OperationCtx retrieves operation context from reflect context.
type OperationInfo ¶
type OperationInfo interface { SetTags(tags ...string) SetIsDeprecated(isDeprecated bool) SetSummary(summary string) SetDescription(description string) SetID(operationID string) AddSecurity(securityName string, scopes ...string) }
OperationInfo extends OperationContext with general information.
type OperationState ¶
type OperationState interface { IsProcessingResponse() bool ProcessingIn() In SetIsProcessingResponse(bool) SetProcessingIn(in In) }
OperationState extends OperationContext with processing state information.
type Reflector ¶
type Reflector interface { JSONSchemaWalker NewOperationContext(method, pathPattern string) (OperationContext, error) AddOperation(oc OperationContext) error SpecSchema() SpecSchema JSONSchemaReflector() *jsonschema.Reflector }
Reflector defines OpenAPI reflector behavior.
type RequestBodyEnforcer ¶
type RequestBodyEnforcer interface {
ForceRequestBody()
}
RequestBodyEnforcer enables request body for GET and HEAD methods.
Should be implemented on input structure, function body can be empty. Forcing request body is not recommended and should only be used for backwards compatibility.
type RequestJSONBodyEnforcer ¶
type RequestJSONBodyEnforcer interface {
ForceJSONRequestBody()
}
RequestJSONBodyEnforcer enables JSON request body for structures with `formData` tags.
Should be implemented on input structure, function body can be empty.
type SpecSchema ¶ added in v0.2.36
SpecSchema abstracts OpenAPI schema implementation to generalize multiple revisions.