swagger.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright 2014 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // Swagger is a project used to describe and document RESTful APIs.
  16. //
  17. // The Swagger specification defines a set of files required to describe such an API. These files can then be used by the Swagger-UI project to display the API and Swagger-Codegen to generate clients in various languages. Additional utilities can also take advantage of the resulting files, such as testing tools.
  18. // Now in version 2.0, Swagger is more enabling than ever. And it's 100% open source software.
  19. // Package swagger struct definition
  20. package main
  21. // Swagger list the resource
  22. type Swagger struct {
  23. SwaggerVersion string `json:"swagger,omitempty" yaml:"swagger,omitempty"`
  24. Infos Information `json:"info" yaml:"info"`
  25. Host string `json:"host,omitempty" yaml:"host,omitempty"`
  26. BasePath string `json:"basePath,omitempty" yaml:"basePath,omitempty"`
  27. Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"`
  28. Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"`
  29. Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"`
  30. Paths map[string]*Item `json:"paths" yaml:"paths"`
  31. Definitions map[string]*Schema `json:"definitions,omitempty" yaml:"definitions,omitempty"`
  32. SecurityDefinitions map[string]Security `json:"securityDefinitions,omitempty" yaml:"securityDefinitions,omitempty"`
  33. Security []map[string][]string `json:"security,omitempty" yaml:"security,omitempty"`
  34. Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty"`
  35. ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
  36. }
  37. // Information Provides metadata about the API. The metadata can be used by the clients if needed.
  38. type Information struct {
  39. Title string `json:"title,omitempty" yaml:"title,omitempty"`
  40. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  41. Version string `json:"version,omitempty" yaml:"version,omitempty"`
  42. TermsOfService string `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
  43. Contact Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
  44. License *License `json:"license,omitempty" yaml:"license,omitempty"`
  45. }
  46. // Contact information for the exposed API.
  47. type Contact struct {
  48. Name string `json:"name,omitempty" yaml:"name,omitempty"`
  49. URL string `json:"url,omitempty" yaml:"url,omitempty"`
  50. EMail string `json:"email,omitempty" yaml:"email,omitempty"`
  51. }
  52. // License information for the exposed API.
  53. type License struct {
  54. Name string `json:"name,omitempty" yaml:"name,omitempty"`
  55. URL string `json:"url,omitempty" yaml:"url,omitempty"`
  56. }
  57. // Item Describes the operations available on a single path.
  58. type Item struct {
  59. Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
  60. Get *Operation `json:"get,omitempty" yaml:"get,omitempty"`
  61. Put *Operation `json:"put,omitempty" yaml:"put,omitempty"`
  62. Post *Operation `json:"post,omitempty" yaml:"post,omitempty"`
  63. Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
  64. Options *Operation `json:"options,omitempty" yaml:"options,omitempty"`
  65. Head *Operation `json:"head,omitempty" yaml:"head,omitempty"`
  66. Patch *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
  67. }
  68. // Operation Describes a single API operation on a path.
  69. type Operation struct {
  70. Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
  71. Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
  72. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  73. OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
  74. Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"`
  75. Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"`
  76. Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"`
  77. Parameters []*Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
  78. Responses map[string]*Response `json:"responses,omitempty" yaml:"responses,omitempty"`
  79. Security []map[string][]string `json:"security,omitempty" yaml:"security,omitempty"`
  80. Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
  81. }
  82. // Parameter Describes a single operation parameter.
  83. type Parameter struct {
  84. In string `json:"in,omitempty" yaml:"in,omitempty"`
  85. Name string `json:"name,omitempty" yaml:"name,omitempty"`
  86. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  87. Required bool `json:"required,omitempty" yaml:"required,omitempty"`
  88. Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
  89. Type string `json:"type,omitempty" yaml:"type,omitempty"`
  90. Format string `json:"format,omitempty" yaml:"format,omitempty"`
  91. Items *ParameterItems `json:"items,omitempty" yaml:"items,omitempty"`
  92. Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
  93. }
  94. // ParameterItems A limited subset of JSON-Schema's items object. It is used by parameter definitions that are not located in "body".
  95. // http://swagger.io/specification/#itemsObject
  96. type ParameterItems struct {
  97. Type string `json:"type,omitempty" yaml:"type,omitempty"`
  98. Format string `json:"format,omitempty" yaml:"format,omitempty"`
  99. Items []*ParameterItems `json:"items,omitempty" yaml:"items,omitempty"` //Required if type is "array". Describes the type of items in the array.
  100. CollectionFormat string `json:"collectionFormat,omitempty" yaml:"collectionFormat,omitempty"`
  101. Default string `json:"default,omitempty" yaml:"default,omitempty"`
  102. }
  103. // Schema Object allows the definition of input and output data types.
  104. type Schema struct {
  105. Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
  106. Title string `json:"title,omitempty" yaml:"title,omitempty"`
  107. Format string `json:"format,omitempty" yaml:"format,omitempty"`
  108. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  109. Required []string `json:"required,omitempty" yaml:"required,omitempty"`
  110. Type string `json:"type,omitempty" yaml:"type,omitempty"`
  111. Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`
  112. Properties map[string]*Propertie `json:"properties,omitempty" yaml:"properties,omitempty"`
  113. }
  114. // Propertie are taken from the JSON Schema definition but their definitions were adjusted to the Swagger Specification
  115. type Propertie struct {
  116. Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
  117. Title string `json:"title,omitempty" yaml:"title,omitempty"`
  118. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  119. Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
  120. Type string `json:"type,omitempty" yaml:"type,omitempty"`
  121. Example string `json:"example,omitempty" yaml:"example,omitempty"`
  122. Required []string `json:"required,omitempty" yaml:"required,omitempty"`
  123. Format string `json:"format,omitempty" yaml:"format,omitempty"`
  124. ReadOnly bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
  125. Properties map[string]Propertie `json:"properties,omitempty" yaml:"properties,omitempty"`
  126. Items *Propertie `json:"items,omitempty" yaml:"items,omitempty"`
  127. AdditionalProperties *Propertie `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
  128. RefImport string `json:"-"`
  129. }
  130. // Response as they are returned from executing this operation.
  131. type Response struct {
  132. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  133. Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
  134. Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
  135. }
  136. // Security Allows the definition of a security scheme that can be used by the operations
  137. type Security struct {
  138. Type string `json:"type,omitempty" yaml:"type,omitempty"` // Valid values are "basic", "apiKey" or "oauth2".
  139. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  140. Name string `json:"name,omitempty" yaml:"name,omitempty"`
  141. In string `json:"in,omitempty" yaml:"in,omitempty"` // Valid values are "query" or "header".
  142. Flow string `json:"flow,omitempty" yaml:"flow,omitempty"` // Valid values are "implicit", "password", "application" or "accessCode".
  143. AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
  144. TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
  145. Scopes map[string]string `json:"scopes,omitempty" yaml:"scopes,omitempty"` // The available scopes for the OAuth2 security scheme.
  146. }
  147. // Tag Allows adding meta data to a single tag that is used by the Operation Object
  148. type Tag struct {
  149. Name string `json:"name,omitempty" yaml:"name,omitempty"`
  150. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  151. ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
  152. }
  153. // ExternalDocs include Additional external documentation
  154. type ExternalDocs struct {
  155. Description string `json:"description,omitempty" yaml:"description,omitempty"`
  156. URL string `json:"url,omitempty" yaml:"url,omitempty"`
  157. }