Skip to content

Instantly share code, notes, and snippets.

@azihsoyn
Forked from ikawaha/design.go
Last active April 4, 2017 08:00
Show Gist options
  • Save azihsoyn/1ff3ab9c7cdf1746cfe8c49c13fb0099 to your computer and use it in GitHub Desktop.
Save azihsoyn/1ff3ab9c7cdf1746cfe8c49c13fb0099 to your computer and use it in GitHub Desktop.
KeyがEnumで制限されているHashOf
package design // The convention consists of naming the design
// package "design"
import (
. "github.com/goadesign/goa/design" // Use . imports to enable the DSL
. "github.com/goadesign/goa/design/apidsl"
)
var _ = API("cellar", func() { // API defines the microservice endpoint and
Title("The virtual wine cellar") // other global properties. There should be one
Description("A simple goa service") // and exactly one API definition appearing in
Scheme("http") // the design.
Host("localhost:8080")
})
var CategoryHash = Type("category_hash", func() {
Attribute("red", Category)
Attribute("white", Category)
Attribute("rose", Category)
})
var Category = Type("category", func() {
Attribute("category", String, "Category", func() {
Enum("red", "white", "rose")
})
})
var BottlePayload = Type("BottlePayload", func() {
Member("bottles", CategoryHash)
// Member("bottles", HashOf(Category, Category)) これはできない
Required("bottles")
})
var _ = Resource("bottle", func() { // Resources group related API endpoints
BasePath("/bottles") // together. They map to REST resources for REST
DefaultMedia(BottleMedia) // services.
Action("show", func() { // Actions define a single API endpoint together
Description("Get bottle by id") // with its path, parameters (both path
Routing(GET("/:bottleID")) // parameters and querystring values) and payload
Params(func() { // (shape of the request body).
Param("bottleID", Integer, "Bottle ID")
})
Payload(BottlePayload)
Response(OK) // Responses define the shape and status code
Response(NotFound) // of HTTP responses.
})
})
// BottleMedia defines the media type used to render bottles.
var BottleMedia = MediaType("application/vnd.goa.example.bottle+json", func() {
Description("A bottle of wine")
Attributes(func() { // Attributes define the media type shape.
Attribute("id", Integer, "Unique bottle ID")
Attribute("href", String, "API href for making requests on the bottle")
Attribute("name", String, "Name of wine")
Required("id", "href", "name")
})
View("default", func() { // View defines a rendering of the media type.
Attribute("id") // Media types may have multiple views and must
Attribute("href") // have a "default" view.
Attribute("name")
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment