// JSONList creates a UserTypeDefinition func JSONList(name, description string, data *d.UserTypeDefinition, links *d.UserTypeDefinition, meta *d.UserTypeDefinition) *d.MediaTypeDefinition { return a.MediaType("application/vnd."+strings.ToLower(name)+"list+json", func() { a.UseTrait("jsonapi-media-type") a.TypeName(name + "List") a.Description(description) if links != nil { a.Attribute("links", links) } if meta != nil { a.Attribute("meta", meta) } a.Attribute("data", a.ArrayOf(data)) a.Attribute("included", a.ArrayOf(d.Any), "An array of mixed types") a.Required("data") a.View("default", func() { if links != nil { a.Attribute("links") } if meta != nil { a.Attribute("meta") } a.Attribute("data") a.Attribute("included") a.Required("data") }) }) }
// listWorkItemLinks defines the list action for endpoints that return an array // of work item links. func listWorkItemLinks() { a.Description("Retrieve work item link (as JSONAPI) for the given link ID.") a.Routing( a.GET(""), ) a.Response(d.OK, func() { a.Media(workItemLinkList) }) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) }
func createWorkItemLink() { a.Description("Create a work item link") a.Security("jwt") a.Routing( a.POST(""), ) a.Payload(createWorkItemLinkPayload) a.Response(d.Created, "/workitemlinks/.*", func() { a.Media(workItemLink) }) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) a.Response(d.Unauthorized, JSONAPIErrors) }
func showWorkItemLink() { a.Description("Retrieve work item link (as JSONAPI) for the given link ID.") a.Routing( a.GET("/:linkId"), ) a.Params(func() { a.Param("linkId", d.String, "ID of the work item link to show") }) a.Response(d.OK, func() { a.Media(workItemLink) }) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) a.Response(d.NotFound, JSONAPIErrors) }
func deleteWorkItemLink() { a.Description("Delete work item link with given id.") a.Security("jwt") a.Routing( a.DELETE("/:linkId"), ) a.Params(func() { a.Param("linkId", d.String, "ID of the work item link to be deleted") }) a.Response(d.OK) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) a.Response(d.NotFound, JSONAPIErrors) a.Response(d.Unauthorized, JSONAPIErrors) }
func updateWorkItemLink() { a.Description("Update the given work item link with given id.") a.Security("jwt") a.Routing( a.PATCH("/:linkId"), ) a.Params(func() { a.Param("linkId", d.String, "ID of the work item link to be updated") }) a.Payload(updateWorkItemLinkPayload) a.Response(d.OK, func() { a.Media(workItemLink) }) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) a.Response(d.NotFound, JSONAPIErrors) a.Response(d.Unauthorized, JSONAPIErrors) }
// JSONSingle creates a Single func JSONSingle(name, description string, data *d.UserTypeDefinition, links *d.UserTypeDefinition) *d.MediaTypeDefinition { // WorkItemSingle is the media type for work items return a.MediaType("application/vnd."+strings.ToLower(name)+"+json", func() { a.UseTrait("jsonapi-media-type") a.TypeName(name + "Single") a.Description(description) if links != nil { a.Attribute("links", links) } a.Attribute("data", data) a.Attribute("included", a.ArrayOf(d.Any), "An array of mixed types") a.Required("data") a.View("default", func() { if links != nil { a.Attribute("links") } a.Attribute("data") a.Attribute("included") a.Required("data") }) }) }
}) JustBeforeEach(func() { files, genErr = genschema.Generate() }) AfterEach(func() { workspace.Delete() }) Context("with a dummy API", func() { BeforeEach(func() { dslengine.Reset() apidsl.API("test api", func() { apidsl.Title("dummy API with no resource") apidsl.Description("I told you it's dummy") }) dslengine.Run() }) It("generates a dummy schema", func() { Ω(genErr).Should(BeNil()) Ω(files).Should(HaveLen(2)) content, err := ioutil.ReadFile(filepath.Join(testPkg.Abs(), "schema", "schema.json")) Ω(err).ShouldNot(HaveOccurred()) Ω(len(strings.Split(string(content), "\n"))).Should(BeNumerically("==", 1)) var s genschema.JSONSchema err = json.Unmarshal(content, &s) Ω(err).ShouldNot(HaveOccurred()) }) })
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var area = a.Type("Area", func() { a.Description(`JSONAPI store for the data of a Area. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("areas") }) a.Attribute("id", d.UUID, "ID of area", func() { a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04") }) a.Attribute("attributes", areaAttributes) a.Attribute("relationships", areaRelationships) a.Attribute("links", genericLinks) a.Required("type", "attributes") }) var areaAttributes = a.Type("AreaAttributes", func() { a.Description(`JSONAPI store for all the "attributes" of a Area. +See also see http://jsonapi.org/format/#document-resource-object-attributes`) a.Attribute("name", d.String, "The Area name", func() { a.Example("Area for Build related stuff") }) a.Attribute("created-at", d.DateTime, "When the area was created", func() { a.Example("2016-11-29T23:18:14Z") }) a.Attribute("version", d.Integer, "Version for optimistic concurrency control (optional during creating)", func() { a.Example(23)
pagingLinks, spaceListMeta) var spaceSingle = JSONSingle( "Space", "Holds a single response to a space request", space, nil) var _ = a.Resource("space", func() { a.BasePath("/spaces") a.Action("show", func() { a.Routing( a.GET("/:id"), ) a.Description("Retrieve space (as JSONAPI) for the given ID.") a.Params(func() { a.Param("id", d.String, "ID of the space") }) a.Response(d.OK, func() { a.Media(spaceSingle) }) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) a.Response(d.NotFound, JSONAPIErrors) }) a.Action("list", func() { a.Routing( a.GET(""), )
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) // ALMStatus defines the status of the current running ALM instance var ALMStatus = a.MediaType("application/vnd.status+json", func() { a.Description("The status of the current running instance") a.Attributes(func() { a.Attribute("commit", d.String, "Commit SHA this build is based on") a.Attribute("buildTime", d.String, "The time when built") a.Attribute("startTime", d.String, "The time when started") a.Attribute("error", d.String, "The error if any") a.Required("commit", "buildTime", "startTime") }) a.View("default", func() { a.Attribute("commit") a.Attribute("buildTime") a.Attribute("startTime") a.Attribute("error") }) }) // workItem is the media type for work items // Deprecated, but kept around as internal model for now. var workItem = a.MediaType("application/vnd.workitem+json", func() { a.TypeName("WorkItem") a.Description("A work item hold field values according to a given field type") a.Attribute("id", d.String, "unique id per installation")
import ( "strings" d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) //############################################################################# // // JSONAPI common // //############################################################################# // JSONAPILink represents a JSONAPI link object (see http://jsonapi.org/format/#document-links) var JSONAPILink = a.Type("JSONAPILink", func() { a.Description(`See also http://jsonapi.org/format/#document-links.`) a.Attribute("href", d.String, "a string containing the link's URL.", func() { a.Example("http://example.com/articles/1/comments") }) a.Attribute("meta", a.HashOf(d.String, d.Any), "a meta object containing non-standard meta-information about the link.") }) // JSONAPIError represents a JSONAPI error object (see http://jsonapi.org/format/#error-objects) var JSONAPIError = a.Type("JSONAPIError", func() { a.Description(`Error objects provide additional information about problems encountered while performing an operation. Error objects MUST be returned as an array keyed by errors in the top level of a JSON API document. See. also http://jsonapi.org/format/#error-objects.`) a.Attribute("id", d.String, "a unique identifier for this particular occurrence of the problem.")
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var comment = a.Type("Comment", func() { a.Description(`JSONAPI store for the data of a comment. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("comments") }) a.Attribute("id", d.UUID, "ID of comment", func() { a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04") }) a.Attribute("attributes", commentAttributes) a.Attribute("relationships", commentRelationships) a.Attribute("links", genericLinks) a.Required("type") }) var createComment = a.Type("CreateComment", func() { a.Description(`JSONAPI store for the data of a comment. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("comments") }) a.Attribute("attributes", createCommentAttributes) a.Required("type", "attributes") }) var commentAttributes = a.Type("CommentAttributes", func() {
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var _ = a.API("alm", func() { a.Title("ALMighty: One to rule them all") a.Description("The next big thing") a.Version("1.0") a.Host("almighty.io") a.Scheme("http") a.BasePath("/api") a.Consumes("application/json") a.Produces("application/json") a.License(func() { a.Name("Apache License Version 2.0") a.URL("http://www.apache.org/licenses/LICENSE-2.0") }) a.Origin("/[.*almighty.io|localhost]/", func() { a.Methods("GET", "POST", "PUT", "PATCH", "DELETE") a.Headers("X-Request-Id", "Content-Type", "Authorization") a.MaxAge(600) a.Credentials() }) a.Trait("jsonapi-media-type", func() { a.ContentType("application/vnd.api+json") })
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var _ = a.Resource("login", func() { a.BasePath("/login") a.Action("authorize", func() { a.Routing( a.GET("authorize"), ) a.Description("Authorize with the ALM") a.Response(d.Unauthorized, JSONAPIErrors) a.Response(d.TemporaryRedirect) }) a.Action("generate", func() { a.Routing( a.GET("generate"), ) a.Description("Generates a set of Tokens for different Auth levels. NOT FOR PRODUCTION. Only available if server is running in dev mode") a.Response(d.OK, func() { a.Media(a.CollectionOf(AuthToken)) }) a.Response(d.Unauthorized, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) })
import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var _ = a.Resource("workitemtype", func() { a.BasePath("/workitemtypes") a.Action("show", func() { a.Routing( a.GET("/:name"), ) a.Description("Retrieve work item type with given name.") a.Params(func() { a.Param("name", d.String, "name") }) a.Response(d.OK, func() { a.Media(workItemType) }) a.Response(d.NotFound, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) }) a.Action("create", func() { a.Security("jwt") a.Routing( a.POST(""), )
var updateWorkItemLinkPayload = a.Type("UpdateWorkItemLinkPayload", func() { a.Attribute("data", workItemLinkData) a.Required("data") }) // workItemLinkListMeta holds meta information for a work item link array response var workItemLinkListMeta = a.Type("WorkItemLinkListMeta", func() { a.Attribute("totalCount", d.Integer, func() { a.Minimum(0) }) a.Required("totalCount") }) // workItemLinkData is the JSONAPI store for the data of a work item link. var workItemLinkData = a.Type("WorkItemLinkData", func() { a.Description(`JSONAPI store for the data of a work item. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("workitemlinks") }) a.Attribute("id", d.String, "ID of work item link (optional during creation)", func() { a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04") }) a.Attribute("attributes", workItemLinkAttributes) a.Attribute("relationships", workItemLinkRelationships) a.Attribute("links", genericLinks) a.Required("type", "relationships") }) // workItemLinkAttributes is the JSONAPI store for all the "attributes" of a work item link type. var workItemLinkAttributes = a.Type("WorkItemLinkAttributes", func() { a.Description(`JSONAPI store for all the "attributes" of a work item link.
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var iteration = a.Type("Iteration", func() { a.Description(`JSONAPI store for the data of a iteration. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("iterations") }) a.Attribute("id", d.UUID, "ID of iteration", func() { a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04") }) a.Attribute("attributes", iterationAttributes) a.Attribute("relationships", iterationRelationships) a.Attribute("links", genericLinks) a.Required("type", "attributes") }) var iterationAttributes = a.Type("IterationAttributes", func() { a.Description(`JSONAPI store for all the "attributes" of a iteration. +See also see http://jsonapi.org/format/#document-resource-object-attributes`) a.Attribute("name", d.String, "The iteration name", func() { a.Example("Sprint #24") }) a.Attribute("description", d.String, "Description of the iteration ", func() { a.Example("Sprint #42 focusing on UI and build process improvements") }) a.Attribute("startAt", d.DateTime, "When the iteration starts", func() { a.Example("2016-11-29T23:18:14Z")
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) var _ = a.Resource("userspace", func() { a.BasePath("/userspace") a.Action("create", func() { a.Routing( a.PUT("/*"), ) a.Description("Data dump endpoint ") a.Payload(a.HashOf(d.String, d.Any)) a.Response(d.NoContent) a.Response(d.InternalServerError) }) a.Action("show", func() { a.Routing( a.GET("/*"), ) a.Description("Data dump endpoint ") a.Response(d.OK, a.HashOf(d.String, d.Any)) a.Response(d.InternalServerError) a.Response(d.NotFound) }) })
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) // identity represents an identified user object var identity = a.MediaType("application/vnd.identity+json", func() { a.UseTrait("jsonapi-media-type") a.TypeName("Identity") a.Description("ALM User Identity") a.Attributes(func() { a.Attribute("data", identityData) a.Required("data") }) a.View("default", func() { a.Attribute("data") a.Required("data") }) }) // identityArray represents an array of identified user objects var identityArray = a.MediaType("application/vnd.identity-array+json", func() { a.UseTrait("jsonapi-media-type") a.TypeName("IdentityArray") a.Description("ALM User Identity Array") a.Attributes(func() { a.Attribute("data", a.ArrayOf(identityData)) a.Required("data")
meta) // workItemSingle is the media type for work items var workItemSingle = JSONSingle( "WorkItem2", "A work item holds field values according to a given field type in JSONAPI form", workItem2, workItemLinks) // new version of "list" for migration var _ = a.Resource("workitem", func() { a.BasePath("/workitems") a.Action("show", func() { a.Routing( a.GET("/:id"), ) a.Description("Retrieve work item with given id.") a.Params(func() { a.Param("id", d.String, "id") }) a.Response(d.OK, func() { a.Media(workItemSingle) }) a.Response(d.BadRequest, JSONAPIErrors) a.Response(d.InternalServerError, JSONAPIErrors) a.Response(d.NotFound, JSONAPIErrors) }) a.Action("list", func() { a.Routing( a.GET(""), ) a.Description("List work items.")
meta) var searchSpaceList = JSONList( "SearchSpace", "Holds the paginated response to a search request", space, pagingLinks, spaceListMeta) var _ = a.Resource("search", func() { a.BasePath("/search") a.Action("show", func() { a.Routing( a.GET(""), ) a.Description("Search by ID, URL, full text capability") a.Params(func() { a.Param("q", d.String, `Following are valid input for search query 1) "id:100" :- Look for work item hainvg id 100 2) "url:http://demo.almighty.io/details/500" :- Search on WI having id 500 and check if this URL is mentioned in searchable columns of work item 3) "simple keywords separated by space" :- Search in Work Items based on these keywords.`) a.Param("page[offset]", d.String, "Paging start position") // #428 a.Param("page[limit]", d.Integer, "Paging size") a.Required("q") }) a.Response(d.OK, func() { a.Media(searchWorkItemList) }) a.Response(d.BadRequest, JSONAPIErrors)
var updateWorkItemLinkTypePayload = a.Type("UpdateWorkItemLinkTypePayload", func() { a.Attribute("data", workItemLinkTypeData) a.Required("data") }) // workItemLinkTypeListMeta holds meta information for a work item link type array response var workItemLinkTypeListMeta = a.Type("WorkItemLinkTypeListMeta", func() { a.Attribute("totalCount", d.Integer, func() { a.Minimum(0) }) a.Required("totalCount") }) // workItemLinkTypeData is the JSONAPI store for the data of a work item link type. var workItemLinkTypeData = a.Type("WorkItemLinkTypeData", func() { a.Description(`JSONAPI store for the data of a work item link type. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("workitemlinktypes") }) a.Attribute("id", d.String, "ID of work item link type (optional during creation)", func() { a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04") }) a.Attribute("attributes", workItemLinkTypeAttributes) a.Attribute("relationships", workItemLinkTypeRelationships) a.Attribute("links", genericLinks) a.Required("type", "attributes") }) // workItemLinkTypeAttributes is the JSONAPI store for all the "attributes" of a work item link type. var workItemLinkTypeAttributes = a.Type("WorkItemLinkTypeAttributes", func() { a.Description(`JSONAPI store for all the "attributes" of a work item link type.
var updateWorkItemLinkCategoryPayload = a.Type("UpdateWorkItemLinkCategoryPayload", func() { a.Attribute("data", workItemLinkCategoryData) a.Required("data") }) // workItemLinkCategoryListMeta holds meta information for a work item link category array response var workItemLinkCategoryListMeta = a.Type("WorkItemLinkCategoryListMeta", func() { a.Attribute("totalCount", d.Integer, func() { a.Minimum(0) }) a.Required("totalCount") }) // workItemLinkCategoryData is the JSONAPI store for the data of a work item link category. var workItemLinkCategoryData = a.Type("WorkItemLinkCategoryData", func() { a.Description(`JSONAPI store the data of a work item link category. See also http://jsonapi.org/format/#document-resource-object`) a.Attribute("type", d.String, func() { a.Enum("workitemlinkcategories") }) a.Attribute("id", d.String, "ID of work item link category (optional during creation)", func() { a.Example("6c5610be-30b2-4880-9fec-81e4f8e4fd76") }) a.Attribute("attributes", workItemLinkCategoryAttributes) a.Attribute("links", genericLinks) a.Required("type", "attributes") }) // workItemLinkCategoryAttributes is the JSONAPI store for all the "attributes" of a work item link category. var workItemLinkCategoryAttributes = a.Type("WorkItemLinkCategoryAttributes", func() { a.Description(`JSONAPI store for all the "attributes" of a work item link category. See also http://jsonapi.org/format/#document-resource-object-attributes`)
package design import ( d "github.com/goadesign/goa/design" a "github.com/goadesign/goa/design/apidsl" ) // MarkupRenderingPayload wraps the data in a JSONAPI compliant request var markupRenderingPayload = a.Type("MarkupRenderingPayload", func() { a.Description("A MarkupRenderingPayload describes the values that a render request can hold.") a.Attribute("data", markupRenderingPayloadData) a.Required("data") }) // MarkupRenderingPayloadData is the media type representing a rendering input. var markupRenderingPayloadData = a.Type("MarkupRenderingPayloadData", func() { a.Attribute("type", d.String, func() { a.Enum("rendering") }) a.Attribute("attributes", markupRenderingPayloadDataAttributes) a.Required("type") a.Required("attributes") }) // MarkupRenderingPayloadData is the media type representing a rendering input. var markupRenderingPayloadDataAttributes = a.Type("MarkupRenderingPayloadDataAttributes", func() { a.Attribute("content", d.String, "The content to render", func() { a.Example("# foo") }) a.Attribute("markup", d.String, "The markup language associated with the content to render", func() { a.Example("Markdown")