github.com/shogo82148/goa-v1@v1.6.2/goagen/gen_swagger/internal/design/resources.go (about) 1 package design 2 3 import ( 4 . "github.com/shogo82148/goa-v1/design" 5 . "github.com/shogo82148/goa-v1/design/apidsl" 6 ) 7 8 var _ = Resource("account", func() { 9 10 DefaultMedia(Account) 11 BasePath("/accounts") 12 13 Action("list", func() { 14 Routing( 15 GET(""), 16 ) 17 Description("Retrieve all accounts.") 18 Response(OK, CollectionOf(Account)) 19 }) 20 21 Action("show", func() { 22 Routing( 23 GET("/:accountID"), 24 ) 25 Description("Retrieve account with given id. IDs 1 and 2 pre-exist in the system.") 26 Params(func() { 27 Param("accountID", Integer, "Account ID", func() { 28 Minimum(1) 29 }) 30 }) 31 Response(OK) 32 Response(NotFound) 33 Response(BadRequest, ErrorMedia) 34 }) 35 36 Action("create", func() { 37 Routing( 38 POST(""), 39 ) 40 Description("Create new account") 41 Payload(func() { 42 Member("name") 43 Required("name") 44 }) 45 Response(Created, "/accounts/[0-9]+") 46 Response(BadRequest, ErrorMedia) 47 }) 48 49 Action("update", func() { 50 Routing( 51 PUT("/:accountID"), 52 ) 53 Description("Change account name") 54 Params(func() { 55 Param("accountID", Integer, "Account ID") 56 }) 57 Payload(func() { 58 Member("name") 59 Required("name") 60 }) 61 Response(NoContent) 62 Response(NotFound) 63 Response(BadRequest, ErrorMedia) 64 }) 65 66 Action("delete", func() { 67 Routing( 68 DELETE("/:accountID"), 69 ) 70 Params(func() { 71 Param("accountID", Integer, "Account ID") 72 }) 73 Response(NoContent) 74 Response(NotFound) 75 Response(BadRequest, ErrorMedia) 76 }) 77 }) 78 79 var _ = Resource("bottle", func() { 80 81 DefaultMedia(Bottle) 82 BasePath("bottles") 83 Parent("account") 84 85 Action("list", func() { 86 Routing( 87 GET(""), 88 ) 89 Description("List all bottles in account optionally filtering by year") 90 Params(func() { 91 Param("years", ArrayOf(Integer), "Filter by years") 92 }) 93 Response(OK, func() { 94 Media(CollectionOf(Bottle, func() { 95 View("default") 96 View("tiny") 97 })) 98 }) 99 Response(NotFound) 100 Response(BadRequest, ErrorMedia) 101 }) 102 103 Action("show", func() { 104 Routing( 105 GET("/:bottleID"), 106 ) 107 Description("Retrieve bottle with given id") 108 Params(func() { 109 Param("bottleID", Integer) 110 }) 111 Response(OK) 112 Response(NotFound) 113 Response(BadRequest, ErrorMedia) 114 }) 115 116 Action("watch", func() { 117 Routing( 118 GET("/:bottleID/watch"), 119 ) 120 Scheme("ws") 121 Description("Retrieve bottle with given id") 122 Params(func() { 123 Param("bottleID", Integer) 124 }) 125 Response(SwitchingProtocols) 126 Response(BadRequest, ErrorMedia) 127 }) 128 129 Action("create", func() { 130 Routing( 131 POST(""), 132 ) 133 Description("Record new bottle") 134 Payload(BottlePayload, func() { 135 Required("name", "vineyard", "varietal", "vintage", "color") 136 }) 137 Response(Created, "^/accounts/[0-9]+/bottles/[0-9]+$") 138 Response(NotFound) 139 Response(BadRequest, ErrorMedia) 140 }) 141 142 Action("update", func() { 143 Routing( 144 PATCH("/:bottleID"), 145 ) 146 Params(func() { 147 Param("bottleID", Integer) 148 }) 149 Payload(BottlePayload) 150 Response(NoContent) 151 Response(NotFound) 152 Response(BadRequest, ErrorMedia) 153 }) 154 155 Action("rate", func() { 156 Routing( 157 PUT("/:bottleID/actions/rate"), 158 ) 159 Params(func() { 160 Param("bottleID", Integer) 161 }) 162 Payload(func() { 163 Member("rating", Integer) 164 Required("rating") 165 }) 166 Response(NoContent) 167 Response(NotFound) 168 Response(BadRequest, ErrorMedia) 169 }) 170 171 Action("delete", func() { 172 Routing( 173 DELETE("/:bottleID"), 174 ) 175 Params(func() { 176 Param("bottleID", Integer) 177 }) 178 Response(NoContent) 179 Response(NotFound) 180 Response(BadRequest, ErrorMedia) 181 }) 182 }) 183 184 var _ = Resource("public", func() { 185 Origin("*", func() { 186 Methods("GET", "OPTIONS") 187 }) 188 Files("/ui", "public/html/index.html") 189 }) 190 191 var _ = Resource("js", func() { 192 Origin("*", func() { 193 Methods("GET", "OPTIONS") 194 }) 195 Files("/js/*filepath", "public/js") 196 }) 197 198 var _ = Resource("swagger", func() { 199 Origin("*", func() { 200 Methods("GET", "OPTIONS") 201 }) 202 Files("/swagger.json", "public/swagger/swagger.json") 203 })