github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/fixtures/bugs/2385/test.yaml (about) 1 --- 2 swagger: "2.0" 3 info: 4 version: "1.0" 5 title: "external types imports: external anonymous types" 6 description: | 7 This sample specification exercises external types, with both x-go-type in definitions and inlined. 8 9 It demonstrates how to use the x-go-type extension to plug external type definitions in the generated code, 10 for models (e.g. for properties, arrays or maps) or operations. 11 12 Notice that x-go-type works for schemas and is not supported for simple swagger types, 13 used for response headers and query & path parameters. 14 15 paths: 16 /test: 17 get: 18 responses: 19 default: 20 description: "ok" 21 schema: 22 23 definitions: 24 NoValidateExternal: 25 description: | 26 27 This type demonstrates how we can disable validation for an external type. 28 29 This is useful if you want to reuse some types from the standard library and don't 30 want to resort to an embedded type. 31 32 type: object 33 x-go-type: 34 type: Request 35 import: 36 package: net/http 37 hints: 38 noValidation: true 39 40 ObjectWithNoValidate: 41 description: | 42 A reference to the NoValidateExternal external type. 43 44 If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method. 45 46 type: object 47 required: [ myMandatoryRequest ] 48 properties: 49 myRequest: 50 $ref: '#/definitions/NoValidateExternal' 51 myMandatoryRequest: 52 $ref: '#/definitions/NoValidateExternal' 53 54 ArrayWithNoValidate: 55 description: | 56 A slice of NoValidateExternal external types. 57 58 If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method. 59 60 type: array 61 maxItems: 12 62 uniqueItems: true 63 items: 64 $ref: '#/definitions/NoValidateExternal' 65 66 MapWithNoValidate: 67 description: | 68 A map of NoValidateExternal external types. 69 70 If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method. 71 72 type: object 73 additionalProperties: 74 $ref: '#/definitions/NoValidateExternal' 75 76 TupleWithNoValidate: 77 description: | 78 A tuple of NoValidateExternal external types. 79 80 If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method. 81 82 Notice that "additionalItems" is not a construct that pass swagger validation, 83 but is supported by go-swagger. 84 85 type: array 86 items: 87 - $ref: '#/definitions/NoValidateExternal' 88 - $ref: '#/definitions/NoValidateExternal' 89 additionalItems: 90 $ref: '#/definitions/NoValidateExternal' 91 92 NoValidatePrimitive: 93 description: | 94 95 This type demonstrates how we can disable validation for an external primitive type. 96 97 type: integer 98 x-go-type: 99 type: Duration 100 import: 101 package: time 102 hints: 103 noValidation: true 104 105 MapOfPrimitives: 106 description: | 107 A map of NoValidatePrimitive external types. 108 109 If the "noValidation" hint is omitted in the definition above, this code won't build because `time.Duration` has no `Validate` method. 110 111 type: object 112 additionalProperties: 113 $ref: '#/definitions/NoValidatePrimitive'