1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-14 06:50:54 +00:00
Beego/swagger/docs_spec.go

161 lines
5.8 KiB
Go
Raw Normal View History

2014-08-18 08:41:43 +00:00
// Copyright 2014 beego Author. All Rights Reserved.
2014-07-03 15:40:21 +00:00
//
2014-08-18 08:41:43 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2014-07-03 15:40:21 +00:00
//
2014-08-18 08:41:43 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2014-07-03 15:40:21 +00:00
//
2014-08-18 08:41:43 +00:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2015-09-12 15:15:23 +00:00
// Package swagger struct definition
2014-06-18 02:36:15 +00:00
package swagger
2014-06-16 08:05:15 +00:00
2015-09-12 15:15:23 +00:00
// SwaggerVersion show the current swagger version
2014-06-18 02:36:15 +00:00
const SwaggerVersion = "1.2"
2014-06-16 08:05:15 +00:00
2015-09-12 15:15:23 +00:00
// ResourceListing list the resource
2014-06-16 08:05:15 +00:00
type ResourceListing struct {
2015-09-12 15:15:23 +00:00
APIVersion string `json:"apiVersion"`
2014-06-16 08:05:15 +00:00
SwaggerVersion string `json:"swaggerVersion"` // e.g 1.2
// BasePath string `json:"basePath"` obsolete in 1.1
2016-01-17 15:57:07 +00:00
APIs []APIRef `json:"apis"`
Info Information `json:"info"`
2014-06-16 08:05:15 +00:00
}
2015-09-12 15:15:23 +00:00
// APIRef description the api path and description
type APIRef struct {
2014-06-16 08:05:15 +00:00
Path string `json:"path"` // relative or absolute, must start with /
Description string `json:"description"`
}
2016-01-15 06:14:09 +00:00
// Information show the API Information
type Information struct {
2014-06-16 08:05:15 +00:00
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Contact string `json:"contact,omitempty"`
2015-09-12 15:15:23 +00:00
TermsOfServiceURL string `json:"termsOfServiceUrl,omitempty"`
2014-06-16 08:05:15 +00:00
License string `json:"license,omitempty"`
2015-09-12 15:15:23 +00:00
LicenseURL string `json:"licenseUrl,omitempty"`
2014-06-16 08:05:15 +00:00
}
2015-09-12 15:15:23 +00:00
// APIDeclaration see https://github.com/wordnik/swagger-core/blob/scala_2.10-1.3-RC3/schemas/api-declaration-schema.json
type APIDeclaration struct {
APIVersion string `json:"apiVersion"`
2014-06-16 08:05:15 +00:00
SwaggerVersion string `json:"swaggerVersion"`
BasePath string `json:"basePath"`
ResourcePath string `json:"resourcePath"` // must start with /
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
2015-09-12 15:15:23 +00:00
APIs []API `json:"apis,omitempty"`
2014-06-16 08:05:15 +00:00
Models map[string]Model `json:"models,omitempty"`
}
2015-09-12 15:15:23 +00:00
// API show tha API struct
type API struct {
2014-06-16 08:05:15 +00:00
Path string `json:"path"` // relative or absolute, must start with /
Description string `json:"description"`
Operations []Operation `json:"operations,omitempty"`
}
2015-09-12 15:15:23 +00:00
// Operation desc the Operation
2014-06-16 08:05:15 +00:00
type Operation struct {
2015-09-12 15:15:23 +00:00
HTTPMethod string `json:"httpMethod"`
2014-06-16 08:05:15 +00:00
Nickname string `json:"nickname"`
Type string `json:"type"` // in 1.1 = DataType
// ResponseClass string `json:"responseClass"` obsolete in 1.2
Summary string `json:"summary,omitempty"`
Notes string `json:"notes,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
ResponseMessages []ResponseMessage `json:"responseMessages,omitempty"` // optional
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Authorizations []Authorization `json:"authorizations,omitempty"`
Protocols []Protocol `json:"protocols,omitempty"`
}
2015-09-12 15:15:23 +00:00
// Protocol support which Protocol
2014-06-16 08:05:15 +00:00
type Protocol struct {
}
2015-09-12 15:15:23 +00:00
// ResponseMessage Show the
2014-06-16 08:05:15 +00:00
type ResponseMessage struct {
Code int `json:"code"`
Message string `json:"message"`
ResponseModel string `json:"responseModel"`
}
2015-09-12 15:15:23 +00:00
// Parameter desc the request parameters
2014-06-16 08:05:15 +00:00
type Parameter struct {
ParamType string `json:"paramType"` // path,query,body,header,form
Name string `json:"name"`
Description string `json:"description"`
DataType string `json:"dataType"` // 1.2 needed?
Type string `json:"type"` // integer
Format string `json:"format"` // int64
AllowMultiple bool `json:"allowMultiple"`
Required bool `json:"required"`
Minimum int `json:"minimum"`
Maximum int `json:"maximum"`
}
2015-09-12 15:15:23 +00:00
// ErrorResponse desc response
2014-06-16 08:05:15 +00:00
type ErrorResponse struct {
Code int `json:"code"`
Reason string `json:"reason"`
}
2015-09-12 15:15:23 +00:00
// Model define the data model
2014-06-16 08:05:15 +00:00
type Model struct {
2015-09-12 15:15:23 +00:00
ID string `json:"id"`
2014-06-16 08:05:15 +00:00
Required []string `json:"required,omitempty"`
Properties map[string]ModelProperty `json:"properties"`
}
2015-09-12 15:15:23 +00:00
// ModelProperty define the properties
2014-06-16 08:05:15 +00:00
type ModelProperty struct {
Type string `json:"type"`
Description string `json:"description"`
Items map[string]string `json:"items,omitempty"`
Format string `json:"format"`
}
2015-09-12 15:15:23 +00:00
// Authorization see https://github.com/wordnik/swagger-core/wiki/authorizations
2014-06-16 08:05:15 +00:00
type Authorization struct {
LocalOAuth OAuth `json:"local-oauth"`
2015-09-12 15:15:23 +00:00
APIKey APIKey `json:"apiKey"`
2014-06-16 08:05:15 +00:00
}
2015-09-12 15:15:23 +00:00
// OAuth see https://github.com/wordnik/swagger-core/wiki/authorizations
2014-06-16 08:05:15 +00:00
type OAuth struct {
Type string `json:"type"` // e.g. oauth2
Scopes []string `json:"scopes"` // e.g. PUBLIC
GrantTypes map[string]GrantType `json:"grantTypes"`
}
2015-09-12 15:15:23 +00:00
// GrantType see https://github.com/wordnik/swagger-core/wiki/authorizations
2014-06-16 08:05:15 +00:00
type GrantType struct {
LoginEndpoint Endpoint `json:"loginEndpoint"`
TokenName string `json:"tokenName"` // e.g. access_code
TokenRequestEndpoint Endpoint `json:"tokenRequestEndpoint"`
TokenEndpoint Endpoint `json:"tokenEndpoint"`
}
2015-09-12 15:15:23 +00:00
// Endpoint see https://github.com/wordnik/swagger-core/wiki/authorizations
2014-06-16 08:05:15 +00:00
type Endpoint struct {
2015-09-12 15:15:23 +00:00
URL string `json:"url"`
ClientIDName string `json:"clientIdName"`
2014-06-16 08:05:15 +00:00
ClientSecretName string `json:"clientSecretName"`
TokenName string `json:"tokenName"`
}
2015-09-12 15:15:23 +00:00
// APIKey see https://github.com/wordnik/swagger-core/wiki/authorizations
type APIKey struct {
2014-06-16 08:05:15 +00:00
Type string `json:"type"` // e.g. apiKey
PassAs string `json:"passAs"` // e.g. header
}