# README
go-restful-openapi
openapi extension to the go-restful package, targeting version 2.0
The following Go field tags are translated to OpenAPI equivalents
- description
- minimum
- maximum
- optional ( if set to "true" then it is not listed in
required
) - unique
- modelDescription
- type (overrides the Go type String())
- enum
- readOnly
See TestThatExtraTagsAreReadIntoModel for examples.
dependencies
Go modules
Versions v1
of this package require Go module version v2
of the go-restful package.
To use version v3
of the go-restful package, you need to import v2
of this package, such as:
import (
restfulspec "github.com/emicklei/go-restful-openapi/v2"
restful "github.com/emicklei/go-restful/v3"
)
© 2017-2020, ernestmicklei.com. MIT License. Contributions welcome.
# Functions
BuildSwagger returns a Swagger object for all services' API endpoints.
DefaultNameHandler GoRestfulDefinition -> GoRestfulDefinition (not changed).
GoLowerCamelCasedNameHandler HTTPRestfulDefinition -> httpRestfulDefinition.
LowerCamelCasedNameHandler GoRestfulDefinition -> goRestfulDefinition.
LowerSnakeCasedNameHandler GoRestfulDefinition -> go_restful_definition.
NewOpenAPIService returns a new WebService that provides the API documentation of all services conform the OpenAPI documentation specifcation.
# Constants
ExtensionPrefix is the only prefix accepted for VendorExtensible extension keys.
KeyOpenAPITags is a Metadata key for a restful Route.
# Structs
Config holds service api metadata.
SchemaType is used to wrap any raw types For example, to return a "schema": "file" one can use Returns(http.StatusOK, http.StatusText(http.StatusOK), SchemaType{RawType: "file"}).
# Type aliases
DefinitionNameHandlerFunc generate name by this handler for definition without json tag.
MapModelTypeNameFunc can be used to return the desired typeName for a given type.
MapSchemaFormatFunc can be used to modify typeName at definition time.
PostBuildSwaggerObjectFunc can be used to change the creates Swagger Object before serving it.