github.com/go-swagger/go-swagger@v0.31.0/docs/reference/annotations/model.md (about) 1 --- 2 title: model 3 date: 2023-01-01T01:01:01-08:00 4 draft: true 5 --- 6 # swagger:model 7 8 A **swagger:model** annotation optionally gets a model name as extra data on the line. 9 when this appears anywhere in a comment for a struct, then that struct becomes a schema 10 in the definitions object of swagger. 11 12 <!--more--> 13 14 The struct gets analyzed and all the collected models are added to the tree. 15 The refs are tracked separately so that they can be renamed later on. 16 17 Definitions only appear in the generated spec when they are actually used somewhere in the application (eg. on a params or response struct) 18 19 ##### Syntax 20 21 ```go 22 swagger:model [?model name] 23 ``` 24 25 ##### Properties 26 27 Annotation | Description 28 **Items.*n*.Maximum** | specifies the maximum a number or integer value can have at the level *n* 29 **Items.*n*.Minimum** | specifies the minimum a number or integer value can have at the level *n* 30 **Items.*n*.Multiple of** | specifies a value a number or integer value must be a multiple of 31 **Items.*n*.Minimum length** | the minimum length for a string value at the level *n* 32 **Items.*n*.Maximum length** | the maximum length for a string value at the level *n* 33 **Items.*n*.Pattern** | a regular expression a string value needs to match at the level *n* 34 **Items.*n*.Minimum items** | the minimum number of items a slice needs to have at the level *n* 35 **Items.*n*.Maximum items** | the maximum number of items a slice can have at the level *n* 36 **Items.*n*.Unique** | when set to true the slice can only contain unique items at the level *n* 37 38 ##### Example 39 40 ```go 41 // User represents the user for this application 42 // 43 // A user is the security principal for this application. 44 // It's also used as one of main axes for reporting. 45 // 46 // A user can have friends with whom they can share what they like. 47 // 48 // swagger:model 49 type User struct { 50 // the id for this user 51 // 52 // required: true 53 // min: 1 54 ID int64 `json:"id"` 55 56 // the name for this user 57 // required: true 58 // min length: 3 59 Name string `json:"name"` 60 61 // the email address for this user 62 // 63 // required: true 64 // example: user@provider.net 65 Email strfmt.Email `json:"login"` 66 67 // the friends for this user 68 // 69 // Extensions: 70 // --- 71 // x-property-value: value 72 // x-property-array: 73 // - value1 74 // - value2 75 // x-property-array-obj: 76 // - name: obj 77 // value: field 78 // --- 79 Friends []User `json:"friends"` 80 } 81 ``` 82 83 ##### Result 84 85 ```yaml 86 ```