Back to godoc.org

Package common

v0.0.0-...-8b50664
Latest Go to latest

The latest major version is .

Published: Sep 23, 2020 | License: Apache-2.0 | Module: k8s.io/kube-openapi

Overview

package common holds shared code and types between open API code generator and spec generator.

Index

Constants

const (
	// TODO: Make this configurable.
	ExtensionPrefix   = "x-kubernetes-"
	ExtensionV2Schema = ExtensionPrefix + "v2-schema"
)

func EscapeJsonPointer

func EscapeJsonPointer(p string) string

func GetOpenAPITypeFormat

func GetOpenAPITypeFormat(typeName string) (string, string)

This function is a reference for converting go (or any custom type) to a simple open API type,format pair. There are two ways to customize spec for a type. If you add it here, a type will be converted to a simple type and the type comment (the comment that is added before type definition) will be lost. The spec will still have the property comment. The second way is to implement OpenAPIDefinitionGetter interface. That function can customize the spec (so the spec does not need to be simple type,format) or can even return a simple type,format (e.g. IntOrString). For simple type formats, the benefit of adding OpenAPIDefinitionGetter interface is to keep both type and property documentation. Example: type Sample struct {

...
// port of the server
port IntOrString
...

} // IntOrString documentation... type IntOrString { ... }

Adding IntOrString to this function: "port" : {

format:      "string",
type:        "int-or-string",
Description: "port of the server"

}

Implement OpenAPIDefinitionGetter for IntOrString:

"port" : {

$Ref:    "#/definitions/IntOrString"
Description: "port of the server"

} ... definitions: {

"IntOrString": {
          format:      "string",
          type:        "int-or-string",
          Description: "IntOrString documentation..."    // new
}

}

type Config

type Config struct {
	// List of supported protocols such as https, http, etc.
	ProtocolList []string

	// Info is general information about the API.
	Info *spec.Info

	// DefaultResponse will be used if an operation does not have any responses listed. It
	// will show up as ... "responses" : {"default" : $DefaultResponse} in the spec.
	DefaultResponse *spec.Response

	// ResponseDefinitions will be added to "responses" under the top-level swagger object. This is an object
	// that holds responses definitions that can be used across operations. This property does not define
	// global responses for all operations. For more info please refer:
	//     https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields
	ResponseDefinitions map[string]spec.Response

	// CommonResponses will be added as a response to all operation specs. This is a good place to add common
	// responses such as authorization failed.
	CommonResponses map[int]spec.Response

	// List of webservice's path prefixes to ignore
	IgnorePrefixes []string

	// OpenAPIDefinitions should provide definition for all models used by routes. Failure to provide this map
	// or any of the models will result in spec generation failure.
	GetDefinitions GetOpenAPIDefinitions

	// GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
	GetOperationIDAndTags func(r *restful.Route) (string, []string, error)

	// GetDefinitionName returns a friendly name for a definition base on the serving path. parameter `name` is the full name of the definition.
	// It is an optional function to customize model names.
	GetDefinitionName func(name string) (string, spec.Extensions)

	// PostProcessSpec runs after the spec is ready to serve. It allows a final modification to the spec before serving.
	PostProcessSpec func(*spec.Swagger) (*spec.Swagger, error)

	// SecurityDefinitions is list of all security definitions for OpenAPI service. If this is not nil, the user of config
	// is responsible to provide DefaultSecurity and (maybe) add unauthorized response to CommonResponses.
	SecurityDefinitions *spec.SecurityDefinitions

	// DefaultSecurity for all operations. This will pass as spec.SwaggerProps.Security to OpenAPI.
	// For most cases, this will be list of acceptable definitions in SecurityDefinitions.
	DefaultSecurity []map[string][]string
}

Config is set of configuration for openAPI spec generation.

type GetOpenAPIDefinitions

type GetOpenAPIDefinitions func(ReferenceCallback) map[string]OpenAPIDefinition

GetOpenAPIDefinitions is collection of all definitions.

type OpenAPIDefinition

type OpenAPIDefinition struct {
	Schema       spec.Schema
	Dependencies []string
}

OpenAPIDefinition describes single type. Normally these definitions are auto-generated using gen-openapi.

func EmbedOpenAPIDefinitionIntoV2Extension

func EmbedOpenAPIDefinitionIntoV2Extension(main OpenAPIDefinition, embedded OpenAPIDefinition) OpenAPIDefinition

type OpenAPIDefinitionGetter

type OpenAPIDefinitionGetter interface {
	OpenAPIDefinition() *OpenAPIDefinition
}

OpenAPIDefinitionGetter gets openAPI definitions for a given type. If a type implements this interface, the definition returned by it will be used, otherwise the auto-generated definitions will be used. See GetOpenAPITypeFormat for more information about trade-offs of using this interface or GetOpenAPITypeFormat method when possible.

type OpenAPIV3DefinitionGetter

type OpenAPIV3DefinitionGetter interface {
	OpenAPIV3Definition() *OpenAPIDefinition
}

type PathHandler

type PathHandler interface {
	Handle(path string, handler http.Handler)
}

type ReferenceCallback

type ReferenceCallback func(path string) spec.Ref

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier