github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/openapi/v3/model.go (about) 1 package v3 2 3 import ( 4 "io" 5 ) 6 7 // Contact https://spec.openapis.org/oas/v3.0.3#contact-object 8 type Contact struct { 9 Email string `json:"email,omitempty"` 10 } 11 12 // License https://spec.openapis.org/oas/v3.0.3#license-object 13 type License struct { 14 Name string `json:"name,omitempty"` 15 URL string `json:"url,omitempty"` 16 } 17 18 // Info https://spec.openapis.org/oas/v3.0.3#info-object 19 type Info struct { 20 Title string `json:"title,omitempty"` 21 Description string `json:"description,omitempty"` 22 TermsOfService string `json:"termsOfService,omitempty"` 23 Contact *Contact `json:"contact,omitempty"` 24 License *License `json:"license,omitempty"` 25 Version string `json:"version,omitempty"` 26 } 27 28 // Server https://spec.openapis.org/oas/v3.0.3#server-object 29 type Server struct { 30 URL string `json:"url,omitempty"` 31 } 32 33 // ExternalDocs https://spec.openapis.org/oas/v3.0.3#external-documentation-object 34 type ExternalDocs struct { 35 Description string `json:"description,omitempty"` 36 URL string `json:"url,omitempty"` 37 } 38 39 // Tag https://spec.openapis.org/oas/v3.0.3#tag-object 40 type Tag struct { 41 Name string `json:"name,omitempty"` 42 Description string `json:"description,omitempty"` 43 ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` 44 } 45 46 // In represents parameter position 47 type In string 48 49 const ( 50 // InQuery query string parameter 51 InQuery In = "query" 52 // InPath TODO not implemented yet 53 InPath In = "path" 54 // InHeader TODO not implemented yet 55 InHeader In = "header" 56 // InCookie TODO not implemented yet 57 InCookie In = "cookie" 58 ) 59 60 // Example https://spec.openapis.org/oas/v3.0.3#example-object 61 type Example struct { 62 // TODO 63 } 64 65 // Encoding https://spec.openapis.org/oas/v3.0.3#encoding-object 66 type Encoding struct { 67 // TODO 68 } 69 70 // MediaType https://spec.openapis.org/oas/v3.0.3#media-type-object 71 type MediaType struct { 72 Schema *Schema `json:"schema,omitempty"` 73 Example interface{} `json:"example,omitempty"` 74 Examples map[string]Example `json:"examples,omitempty"` 75 Encoding map[string]Encoding `json:"encoding,omitempty"` 76 } 77 78 // Content REQUIRED. The content of the request body. The key is a media type or [media type range]appendix-D) 79 // and the value describes it. For requests that match multiple keys, only the most specific key is applicable. 80 // e.g. text/plain overrides text/* 81 type Content struct { 82 TextPlain *MediaType `json:"text/plain,omitempty"` 83 JSON *MediaType `json:"application/json,omitempty"` 84 FormURL *MediaType `json:"application/x-www-form-urlencoded,omitempty"` 85 Stream *MediaType `json:"application/octet-stream,omitempty"` 86 FormData *MediaType `json:"multipart/form-data,omitempty"` 87 Default *MediaType `json:"*/*,omitempty"` 88 } 89 90 // Parameter https://spec.openapis.org/oas/v3.0.3#parameter-object 91 type Parameter struct { 92 Name string `json:"name,omitempty"` 93 In In `json:"in,omitempty"` 94 Description string `json:"description,omitempty"` 95 Required bool `json:"required,omitempty"` 96 Deprecated bool `json:"deprecated,omitempty"` 97 Example interface{} `json:"example,omitempty"` 98 Schema *Schema `json:"schema,omitempty"` 99 Style string `json:"style,omitempty"` 100 Explode bool `json:"explode,omitempty"` 101 AllowReserved bool `json:"allowReserved,omitempty"` 102 Content *Content `json:"content,omitempty"` 103 AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` 104 } 105 106 // RequestBody https://spec.openapis.org/oas/v3.0.3#request-body-object 107 type RequestBody struct { 108 Description string `json:"description,omitempty"` 109 Content *Content `json:"content,omitempty"` 110 Required bool `json:"required,omitempty"` 111 Ref string `json:"$ref,omitempty"` 112 } 113 114 // Header https://spec.openapis.org/oas/v3.0.3#header-object 115 type Header struct { 116 Ref string `json:"$ref,omitempty"` 117 Description string `json:"description,omitempty"` 118 Required bool `json:"required,omitempty"` 119 Deprecated bool `json:"deprecated,omitempty"` 120 Example interface{} `json:"example,omitempty"` 121 Schema *Schema `json:"schema,omitempty"` 122 } 123 124 // Link https://spec.openapis.org/oas/v3.0.3#link-object 125 type Link struct { 126 // TODO 127 } 128 129 // Response https://spec.openapis.org/oas/v3.0.3#response-object 130 type Response struct { 131 Description string `json:"description"` 132 Content *Content `json:"content,omitempty"` 133 // TODO 134 Headers map[string]Header `json:"headers,omitempty"` 135 Links map[string]Link `json:"links,omitempty"` 136 Ref string `json:"$ref,omitempty"` 137 } 138 139 // Responses https://spec.openapis.org/oas/v3.0.3#responses-object 140 type Responses struct { 141 Resp200 *Response `json:"200,omitempty"` 142 Resp400 *Response `json:"400,omitempty"` 143 Resp401 *Response `json:"401,omitempty"` 144 Resp403 *Response `json:"403,omitempty"` 145 Resp404 *Response `json:"404,omitempty"` 146 Resp405 *Response `json:"405,omitempty"` 147 Default *Response `json:"default,omitempty"` 148 } 149 150 // Callback https://spec.openapis.org/oas/v3.0.3#callback-object 151 type Callback struct { 152 // TODO 153 } 154 155 // Security not implemented yet 156 type Security struct { 157 // TODO 158 } 159 160 // Operation https://spec.openapis.org/oas/v3.0.3#operation-object 161 type Operation struct { 162 Tags []string `json:"tags,omitempty"` 163 Summary string `json:"summary,omitempty"` 164 Description string `json:"description,omitempty"` 165 OperationID string `json:"operationId,omitempty"` 166 Parameters []Parameter `json:"parameters,omitempty"` 167 RequestBody *RequestBody `json:"requestBody,omitempty"` 168 Responses *Responses `json:"responses,omitempty"` 169 Deprecated bool `json:"deprecated,omitempty"` 170 ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` 171 Callbacks map[string]Callback `json:"callbacks,omitempty"` 172 Security []Security `json:"security,omitempty"` 173 Servers []Server `json:"servers,omitempty"` 174 } 175 176 // Path https://spec.openapis.org/oas/v3.0.3#path-item-object 177 type Path struct { 178 Get *Operation `json:"get,omitempty"` 179 Post *Operation `json:"post,omitempty"` 180 Put *Operation `json:"put,omitempty"` 181 Delete *Operation `json:"delete,omitempty"` 182 // TODO 183 Parameters []Parameter `json:"parameters,omitempty"` 184 } 185 186 // SecurityScheme https://spec.openapis.org/oas/v3.0.3#security-scheme-object 187 type SecurityScheme struct { 188 // TODO 189 } 190 191 // Discriminator https://spec.openapis.org/oas/v3.0.3#discriminator-object 192 type Discriminator struct { 193 PropertyName string `json:"propertyName,omitempty"` 194 Mapping map[string]string `json:"mapping,omitempty"` 195 } 196 197 // Schema https://spec.openapis.org/oas/v3.0.3#schema-object 198 type Schema struct { 199 Ref string `json:"$ref,omitempty"` 200 Title string `json:"title,omitempty"` 201 Type Type `json:"type,omitempty"` 202 Properties map[string]*Schema `json:"properties,omitempty"` 203 Format Format `json:"format,omitempty"` 204 Items *Schema `json:"items,omitempty"` 205 Description string `json:"description,omitempty"` 206 Default interface{} `json:"default,omitempty"` 207 Example interface{} `json:"example,omitempty"` 208 Deprecated bool `json:"deprecated,omitempty"` 209 Discriminator *Discriminator `json:"discriminator,omitempty"` 210 Nullable bool `json:"nullable,omitempty"` 211 Maximum interface{} `json:"maximum,omitempty"` 212 Minimum interface{} `json:"minimum,omitempty"` 213 ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"` 214 ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"` 215 MaxLength int `json:"maxLength,omitempty"` 216 MinLength int `json:"minLength,omitempty"` 217 Required []string `json:"required,omitempty"` 218 Enum []interface{} `json:"enum,omitempty"` 219 AllOf []*Schema `json:"allOf,omitempty"` 220 OneOf []*Schema `json:"oneOf,omitempty"` 221 AnyOf []*Schema `json:"anyOf,omitempty"` 222 Not []*Schema `json:"not,omitempty"` 223 // AdditionalProperties *Schema or bool 224 AdditionalProperties interface{} `json:"additionalProperties,omitempty"` 225 Pattern interface{} `json:"pattern,omitempty"` 226 XMapType string `json:"x-map-type,omitempty"` 227 } 228 229 // Components https://spec.openapis.org/oas/v3.0.3#components-object 230 type Components struct { 231 Schemas map[string]Schema `json:"schemas,omitempty"` 232 RequestBodies map[string]RequestBody `json:"requestBodies,omitempty"` 233 Responses map[string]Response `json:"responses,omitempty"` 234 // TODO 235 Parameters map[string]Parameter `json:"parameters,omitempty"` 236 // TODO 237 Examples map[string]Example `json:"examples,omitempty"` 238 // TODO 239 Headers map[string]Header `json:"headers,omitempty"` 240 // TODO 241 SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"` 242 // TODO 243 Links map[string]Link `json:"links,omitempty"` 244 // TODO 245 Callbacks map[string]Callback `json:"callbacks,omitempty"` 246 } 247 248 // API https://spec.openapis.org/oas/v3.0.3#openapi-object 249 type API struct { 250 Openapi string `json:"openapi,omitempty"` 251 Info *Info `json:"info,omitempty"` 252 Servers []Server `json:"servers,omitempty"` 253 Tags []Tag `json:"tags,omitempty"` 254 Paths map[string]Path `json:"paths,omitempty"` 255 Components *Components `json:"components,omitempty"` 256 ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` 257 } 258 259 // Type represents types in OpenAPI3.0 spec 260 type Type string 261 262 const ( 263 // IntegerT integer 264 IntegerT Type = "integer" 265 // StringT string 266 StringT Type = "string" 267 // BooleanT boolean 268 BooleanT Type = "boolean" 269 // NumberT number 270 NumberT Type = "number" 271 // ObjectT object 272 ObjectT Type = "object" 273 // ArrayT array 274 ArrayT Type = "array" 275 ) 276 277 // Format represents format in OpenAPI3.0 spec 278 type Format string 279 280 const ( 281 // Int32F int32 282 Int32F Format = "int32" 283 // Int64F int64 284 Int64F Format = "int64" 285 // FloatF float 286 FloatF Format = "float" 287 // DoubleF double 288 DoubleF Format = "double" 289 // DateTimeF date-time 290 DateTimeF Format = "date-time" 291 // BinaryF binary 292 BinaryF Format = "binary" 293 DecimalF Format = "decimal" 294 ) 295 296 var ( 297 // Any constant schema for object 298 Any = &Schema{ 299 Type: ObjectT, 300 } 301 // Int constant schema for int 302 Int = &Schema{ 303 Type: IntegerT, 304 Format: Int32F, 305 } 306 // Int64 constant schema for int64 307 Int64 = &Schema{ 308 Type: IntegerT, 309 Format: Int64F, 310 } 311 // String constant schema for string 312 String = &Schema{ 313 Type: StringT, 314 } 315 // Time constant schema for time 316 Time = &Schema{ 317 Type: StringT, 318 Format: DateTimeF, 319 } 320 // Bool constant schema for bool 321 Bool = &Schema{ 322 Type: BooleanT, 323 } 324 // Float32 constant schema for float32 325 Float32 = &Schema{ 326 Type: NumberT, 327 Format: FloatF, 328 } 329 // Float64 constant schema for float64 330 Float64 = &Schema{ 331 Type: NumberT, 332 Format: DoubleF, 333 } 334 // File constant schema for file 335 File = &Schema{ 336 Type: StringT, 337 Format: BinaryF, 338 } 339 // FileArray constant schema for file slice 340 FileArray = &Schema{ 341 Type: ArrayT, 342 Items: File, 343 } 344 Decimal = &Schema{ 345 Type: StringT, 346 Format: DecimalF, 347 } 348 ) 349 350 type FileModel struct { 351 Filename string 352 Reader io.ReadCloser 353 } 354 355 func (f *FileModel) Close() error { 356 return f.Reader.Close() 357 } 358 359 type IEnum interface { 360 StringSetter(value string) 361 StringGetter() string 362 UnmarshalJSON(bytes []byte) error 363 MarshalJSON() ([]byte, error) 364 } 365 366 var IEnumMethods = []string{ 367 "func StringSetter(value string)", 368 "func StringGetter() string", 369 "func UnmarshalJSON(bytes []byte) error", 370 "func MarshalJSON() ([]byte, error)", 371 } 372 373 type ExampleType int 374 375 const ( 376 UNKNOWN_EXAMPLE ExampleType = iota 377 JSON_EXAMPLE 378 TEXT_EXAMPLE 379 )