Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultRes = models.Response{ Description: "Successful Response", Content: map[string]*models.MediaType{ "application/json": { Schema: &models.Schema{}, }, }, }
var OPENAPI = models.OpenAPI{}
var Version = "http://json-schema.org/draft-04/schema#"
Version is the JSON SchemaChild version. If extending JSON SchemaChild with custom values use a custom URI. RFC draft-wright-json-schema-00, section 6
Functions ¶
func GetExample ¶
Types ¶
type ContentType ¶
type ContentType string
const ( //Html ContentType = "text/html" //Text ContentType = "text/plain" //TextXml ContentType = "text/xml" //Gif ContentType = "image/gif" //Jpeg ContentType = "image/jpeg" //Png ContentType = "image/png" //AppXml ContentType = "application/xml" Json ContentType = "application/json" //Pdf ContentType = "application/pdf" //Stream ContentType = "application/octet-stream" Form ContentType = "application/x-www-form-urlencoded" FormData ContentType = "multipart/form-data" )
type Definitions ¶
Definitions hold schema definitions. http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.26 RFC draft-wright-json-schema-validation-00, section 5.26 body
type IContentType ¶
type IContentType interface {
GetContentType() ContentType
}
IContentType 返回的结构体在请求或返回参数的类型
type Reflector ¶
type Reflector struct { // AllowAdditionalProperties will cause the Reflector to generate a schema // with additionalProperties to 'true' for all struct types. This means // the presence of additional keys in JSON objects will not cause validation // to fail. Note said additional keys will simply be dropped when the // validated JSON is unmarshalled. AllowAdditionalProperties bool // RequiredFromJSONSchemaTags will cause the Reflector to generate a schema // that requires any key tagged with `jsonschema:required`, overriding the // default of requiring any key *not* tagged with `json:,omitempty`. RequiredFromJSONSchemaTags bool // YAMLEmbeddedStructs will cause the Reflector to generate a schema that does // not inline embedded structs. This should be enabled if the JSON schemas are // used with yaml.Marshal/Unmarshal. YAMLEmbeddedStructs bool // Prefer yaml: tags over json: tags to generate the schema even if json: tags // are present PreferYAMLSchema bool // ExpandedStruct will cause the toplevel definitions of the schema not // be referenced itself to a definition. //把根打散 ExpandedStruct bool // Do not reference definitions. // All types are still registered under the "definitions" top-level object, // but instead of $ref fields in containing types, the entire definition // of the contained type is inserted. // This will cause the entire structure of types to be output in one tree. DoNotReference bool // Use package paths as well as type names, to avoid conflicts. // Without this setting, if two packages contain a type with the same name, // and both are present in a schema, they will conflict and overwrite in // the definition map and produce bad output. This is particularly // noticeable when using DoNotReference. FullyQualifyTypeNames bool // IgnoredTypes defines a slice of types that should be ignored in the schema, // switching to just allowing additional properties instead. IgnoredTypes []interface{} // TypeMapper is a function that can be used to map custom Go types to jsonschema types. TypeMapper func(reflect.Type) *models.Schema // TypeNamer allows customizing of type names TypeNamer func(reflect.Type) string // AdditionalFields allows adding structfields for a given type AdditionalFields func(reflect.Type) []reflect.StructField }
A Reflector reflects values into a SchemaChild.
func (*Reflector) Reflect ¶
func (n *Reflector) Reflect(v interface{}) *SchemaChild
Reflect reflects to SchemaChild from a value.
func (*Reflector) ReflectFromType ¶
func (n *Reflector) ReflectFromType(t reflect.Type) *SchemaChild
ReflectFromType generates root schema
type RouteStruct ¶
type RouterHelper ¶
type RouterHelper struct { Body *models.RequestBody //这才是真正应该有的body Components Definitions //Body,包含content forms,files Parameters Parameters //path,query,header,cookie, todo path之后在处理 Response map[string]*models.Response *models.Schema ReqContentType string }
func NewOpenapiRequest ¶
func NewOpenapiRequest(v RouteStruct) *RouterHelper
func Register2Openapi ¶
func Register2Openapi(n RouteStruct) *RouterHelper
func (*RouterHelper) GetSchema ¶
func (n *RouterHelper) GetSchema() *models.Schema
func (*RouterHelper) GetSchemaStruct ¶
func (n *RouterHelper) GetSchemaStruct(schema *models.Schema) *models.Schema
func (*RouterHelper) WriteRes ¶
func (n *RouterHelper) WriteRes(exceptRes map[int]interface{})
type SchemaChild ¶
type SchemaChild struct { *models.Schema //根schema Components Definitions //Body,包含content forms,files }
SchemaChild is the root schema. RFC draft-wright-json-schema-00, section 4.5
func Reflect ¶
func Reflect(v interface{}) *SchemaChild
Reflect represents a JSON SchemaChild object type. Reflect reflects to SchemaChild from a value using the default Reflector
func ReflectFromType ¶
func ReflectFromType(t reflect.Type) *SchemaChild
ReflectFromType generates root schema using the default Reflector
func (*SchemaChild) MarshalJSON ¶
func (n *SchemaChild) MarshalJSON() ([]byte, error)