swagger.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // Package swagger implements the structures of the Swagger
  2. // https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md
  3. package swagger
  4. const swaggerVersion = "1.2"
  5. // 4.3.3 Data Type Fields
  6. type DataTypeFields struct {
  7. Type *string `json:"type,omitempty"` // if Ref not used
  8. Ref *string `json:"$ref,omitempty"` // if Type not used
  9. Format string `json:"format,omitempty"`
  10. DefaultValue Special `json:"defaultValue,omitempty"`
  11. Enum []string `json:"enum,omitempty"`
  12. Minimum string `json:"minimum,omitempty"`
  13. Maximum string `json:"maximum,omitempty"`
  14. Items *Item `json:"items,omitempty"`
  15. UniqueItems *bool `json:"uniqueItems,omitempty"`
  16. }
  17. type Special string
  18. // 4.3.4 Items Object
  19. type Item struct {
  20. Type *string `json:"type,omitempty"`
  21. Ref *string `json:"$ref,omitempty"`
  22. Format string `json:"format,omitempty"`
  23. }
  24. // 5.1 Resource Listing
  25. type ResourceListing struct {
  26. SwaggerVersion string `json:"swaggerVersion"` // e.g 1.2
  27. Apis []Resource `json:"apis"`
  28. ApiVersion string `json:"apiVersion"`
  29. Info Info `json:"info"`
  30. Authorizations []Authorization `json:"authorizations,omitempty"`
  31. }
  32. // 5.1.2 Resource Object
  33. type Resource struct {
  34. Path string `json:"path"` // relative or absolute, must start with /
  35. Description string `json:"description"`
  36. }
  37. // 5.1.3 Info Object
  38. type Info struct {
  39. Title string `json:"title"`
  40. Description string `json:"description"`
  41. TermsOfServiceUrl string `json:"termsOfServiceUrl,omitempty"`
  42. Contact string `json:"contact,omitempty"`
  43. License string `json:"license,omitempty"`
  44. LicenseUrl string `json:"licenseUrl,omitempty"`
  45. }
  46. // 5.1.5
  47. type Authorization struct {
  48. Type string `json:"type"`
  49. PassAs string `json:"passAs"`
  50. Keyname string `json:"keyname"`
  51. Scopes []Scope `json:"scopes"`
  52. GrantTypes []GrantType `json:"grandTypes"`
  53. }
  54. // 5.1.6, 5.2.11
  55. type Scope struct {
  56. // Required. The name of the scope.
  57. Scope string `json:"scope"`
  58. // Recommended. A short description of the scope.
  59. Description string `json:"description"`
  60. }
  61. // 5.1.7
  62. type GrantType struct {
  63. Implicit Implicit `json:"implicit"`
  64. AuthorizationCode AuthorizationCode `json:"authorization_code"`
  65. }
  66. // 5.1.8 Implicit Object
  67. type Implicit struct {
  68. // Required. The login endpoint definition.
  69. loginEndpoint LoginEndpoint `json:"loginEndpoint"`
  70. // An optional alternative name to standard "access_token" OAuth2 parameter.
  71. TokenName string `json:"tokenName"`
  72. }
  73. // 5.1.9 Authorization Code Object
  74. type AuthorizationCode struct {
  75. TokenRequestEndpoint TokenRequestEndpoint `json:"tokenRequestEndpoint"`
  76. TokenEndpoint TokenEndpoint `json:"tokenEndpoint"`
  77. }
  78. // 5.1.10 Login Endpoint Object
  79. type LoginEndpoint struct {
  80. // Required. The URL of the authorization endpoint for the implicit grant flow. The value SHOULD be in a URL format.
  81. Url string `json:"url"`
  82. }
  83. // 5.1.11 Token Request Endpoint Object
  84. type TokenRequestEndpoint struct {
  85. // Required. The URL of the authorization endpoint for the authentication code grant flow. The value SHOULD be in a URL format.
  86. Url string `json:"url"`
  87. // An optional alternative name to standard "client_id" OAuth2 parameter.
  88. ClientIdName string `json:"clientIdName"`
  89. // An optional alternative name to the standard "client_secret" OAuth2 parameter.
  90. ClientSecretName string `json:"clientSecretName"`
  91. }
  92. // 5.1.12 Token Endpoint Object
  93. type TokenEndpoint struct {
  94. // Required. The URL of the token endpoint for the authentication code grant flow. The value SHOULD be in a URL format.
  95. Url string `json:"url"`
  96. // An optional alternative name to standard "access_token" OAuth2 parameter.
  97. TokenName string `json:"tokenName"`
  98. }
  99. // 5.2 API Declaration
  100. type ApiDeclaration struct {
  101. SwaggerVersion string `json:"swaggerVersion"`
  102. ApiVersion string `json:"apiVersion"`
  103. BasePath string `json:"basePath"`
  104. ResourcePath string `json:"resourcePath"` // must start with /
  105. Info Info `json:"info"`
  106. Apis []Api `json:"apis,omitempty"`
  107. Models ModelList `json:"models,omitempty"`
  108. Produces []string `json:"produces,omitempty"`
  109. Consumes []string `json:"consumes,omitempty"`
  110. Authorizations []Authorization `json:"authorizations,omitempty"`
  111. }
  112. // 5.2.2 API Object
  113. type Api struct {
  114. Path string `json:"path"` // relative or absolute, must start with /
  115. Description string `json:"description"`
  116. Operations []Operation `json:"operations,omitempty"`
  117. }
  118. // 5.2.3 Operation Object
  119. type Operation struct {
  120. DataTypeFields
  121. Method string `json:"method"`
  122. Summary string `json:"summary,omitempty"`
  123. Notes string `json:"notes,omitempty"`
  124. Nickname string `json:"nickname"`
  125. Authorizations []Authorization `json:"authorizations,omitempty"`
  126. Parameters []Parameter `json:"parameters"`
  127. ResponseMessages []ResponseMessage `json:"responseMessages,omitempty"` // optional
  128. Produces []string `json:"produces,omitempty"`
  129. Consumes []string `json:"consumes,omitempty"`
  130. Deprecated string `json:"deprecated,omitempty"`
  131. }
  132. // 5.2.4 Parameter Object
  133. type Parameter struct {
  134. DataTypeFields
  135. ParamType string `json:"paramType"` // path,query,body,header,form
  136. Name string `json:"name"`
  137. Description string `json:"description"`
  138. Required bool `json:"required"`
  139. AllowMultiple bool `json:"allowMultiple"`
  140. }
  141. // 5.2.5 Response Message Object
  142. type ResponseMessage struct {
  143. Code int `json:"code"`
  144. Message string `json:"message"`
  145. ResponseModel string `json:"responseModel,omitempty"`
  146. }
  147. // 5.2.6, 5.2.7 Models Object
  148. type Model struct {
  149. Id string `json:"id"`
  150. Description string `json:"description,omitempty"`
  151. Required []string `json:"required,omitempty"`
  152. Properties ModelPropertyList `json:"properties"`
  153. SubTypes []string `json:"subTypes,omitempty"`
  154. Discriminator string `json:"discriminator,omitempty"`
  155. }
  156. // 5.2.8 Properties Object
  157. type ModelProperty struct {
  158. DataTypeFields
  159. Description string `json:"description,omitempty"`
  160. }
  161. // 5.2.10
  162. type Authorizations map[string]Authorization