// 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")
		})
	})

}
// JSONResourceObject creates a single resource object
func JSONResourceObject(name string, attributes *d.UserTypeDefinition, relationships *d.UserTypeDefinition) *d.UserTypeDefinition {
	return a.Type(name, func() {
		a.Attribute("type", d.String, func() {
			a.Enum(strings.ToLower(name) + "s")
		})
		a.Attribute("id", d.String, "ID of the "+name, func() {
			a.Example("42")
		})
		a.Attribute("attributes", attributes)
		if relationships != nil {
			a.Attribute("relationships", relationships)
		}
		a.Required("type", "id", "attributes")
	})
}
// 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")
		})
	})
}
Exemple #4
0
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")
Exemple #5
0
		a.Routing(
			a.POST("refresh"),
		)
		a.Payload(refreshToken)
		a.Description("Refreshes access token")
		a.Response(d.OK, func() {
			a.Media(AuthToken)
		})
		a.Response(d.Unauthorized, JSONAPIErrors)
		a.Response(d.BadRequest, JSONAPIErrors)
		a.Response(d.InternalServerError, JSONAPIErrors)
	})
})

var refreshToken = a.Type("RefreshToken", func() {
	a.Attribute("refresh_token", d.String, "Refresh token")
})

// AuthToken represents an authentication JWT Token
var AuthToken = a.MediaType("application/vnd.authtoken+json", func() {
	a.TypeName("AuthToken")
	a.Description("JWT Token")
	a.Attributes(func() {
		a.Attribute("token", tokenData)
		a.Required("token")
	})
	a.View("default", func() {
		a.Attribute("token")
	})
})
Exemple #6
0
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")
Exemple #7
0
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)
Exemple #8
0
package design

import (
	d "github.com/goadesign/goa/design"
	a "github.com/goadesign/goa/design/apidsl"
)

var space = a.Type("Space", func() {
	a.Attribute("type", d.String, "The type of the related resource", func() {
		a.Enum("spaces")
	})
	a.Attribute("id", d.UUID, "ID of the space", func() {
		a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04")
	})
	a.Attribute("attributes", spaceAttributes)
	a.Attribute("links", genericLinks)
	a.Required("type", "attributes")
	a.Attribute("relationships", spaceRelationships)
})

var spaceRelationships = a.Type("SpaceRelationships", func() {
	a.Attribute("iterations", relationGeneric, "Space can have one or many iterations")
	a.Attribute("areas", relationGeneric, "Space can have one or many areas")
})

var spaceAttributes = a.Type("SpaceAttributes", func() {
	a.Attribute("name", d.String, "Name of the space", func() {
		a.Example("foobar")
	})
	a.Attribute("description", d.String, "Description for the space", func() {
		a.Example("This is the foobar collaboration space")
Exemple #9
0
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")
	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.")
	a.Attribute("links", a.HashOf(d.String, JSONAPILink), `a links object containing the following members:
* about: a link that leads to further details about this particular occurrence of the problem.`)
Exemple #11
0
package design

import (
	d "github.com/goadesign/goa/design"
	a "github.com/goadesign/goa/design/apidsl"
)

// genericLinksForWorkItem defines generic relations links that are specific to a workitem
var genericLinksForWorkItem = a.Type("GenericLinksForWorkItem", func() {
	a.Attribute("self", d.String)
	a.Attribute("related", d.String)
	a.Attribute("sourceLinkTypes", d.String, `URL to those work item link types
in which the current work item can be used in the source part of the link`)
	a.Attribute("targetLinkTypes", d.String, `URL to those work item link types
in which the current work item can be used in the target part of the link`)
	a.Attribute("meta", a.HashOf(d.String, d.Any))
})

// workItem2 defines how an update payload will look like
var workItem2 = a.Type("WorkItem2", func() {
	a.Attribute("type", d.String, func() {
		a.Enum("workitems")
	})
	a.Attribute("id", d.String, "ID of the work item which is being updated", func() {
		a.Example("42")
	})
	a.Attribute("attributes", a.HashOf(d.String, d.Any), func() {
		a.Example(map[string]interface{}{"version": "1", "system.state": "new", "system.title": "Example story"})
	})
	a.Attribute("relationships", workItemRelationships)
	a.Attribute("links", genericLinksForWorkItem)
Exemple #12
0
package design

import (
	d "github.com/goadesign/goa/design"
	a "github.com/goadesign/goa/design/apidsl"
)

// CreateWorkItemPayload defines the structure of work item payload
var CreateWorkItemPayload = a.Type("CreateWorkItemPayload", func() {
	a.Attribute("type", d.String, "The type of the newly created work item", func() {
		a.Example("userstory")
		a.MinLength(1)
		a.Pattern("^[\\p{L}.]+$")
	})
	a.Attribute("fields", a.HashOf(d.String, d.Any), "The field values, must conform to the type", func() {
		a.Example(map[string]interface{}{"system.creator": "user-ref", "system.state": "new", "system.title": "Example story"})
		a.MinLength(1)
	})
	a.Required("type", "fields")
})

// UpdateWorkItemPayload has been added because the design.WorkItem could
// not be used since it mandated the presence of the ID in the payload
// which ideally should be optional. The ID should be passed on to REST URL.
var UpdateWorkItemPayload = a.Type("UpdateWorkItemPayload", func() {
	a.Attribute("type", d.String, "The type of the newly created work item", func() {
		a.Example("userstory")
		a.MinLength(1)
		a.Pattern("^[\\p{L}.]+$")
	})
	a.Attribute("fields", a.HashOf(d.String, d.Any), "The field values, must conform to the type", func() {
package design

import (
	d "github.com/goadesign/goa/design"
	a "github.com/goadesign/goa/design/apidsl"
)

// workItemLinkLinks has `self` as of now according to http://jsonapi.org/format/#fetching-resources
var workItemLinkLinks = a.Type("WorkItemLinkLinks", func() {
	a.Attribute("self", d.String, func() {
		a.Example("http://api.almighty.io/api/workitemlinks/2d98c73d-6969-4ea6-958a-812c832b6c18")
	})
	a.Required("self")
})

// createWorkItemLinkPayload defines the structure of work item link payload in JSONAPI format during creation
var createWorkItemLinkPayload = a.Type("CreateWorkItemLinkPayload", func() {
	a.Attribute("data", workItemLinkData)
	a.Required("data")
})

// updateWorkItemLinkPayload defines the structure of work item link payload in JSONAPI format during update
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)
Exemple #14
0
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"
)

// createWorkItemLinkTypePayload defines the structure of work item link type payload in JSONAPI format during creation
var createWorkItemLinkTypePayload = a.Type("CreateWorkItemLinkTypePayload", func() {
	a.Attribute("data", workItemLinkTypeData)
	a.Required("data")
})

// updateWorkItemLinkTypePayload defines the structure of work item link type payload in JSONAPI format during update
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`)
package design

import (
	d "github.com/goadesign/goa/design"
	a "github.com/goadesign/goa/design/apidsl"
)

// workItemLinkCategoryLinks has `self` as of now according to http://jsonapi.org/format/#fetching-resources
var workItemLinkCategoryLinks = a.Type("WorkItemLinkCategoryLinks", func() {
	a.Attribute("self", d.String, func() {
		a.Example("http://api.almighty.io/api/workitemlinkcategories/2d98c73d-6969-4ea6-958a-812c832b6c18")
	})
	a.Required("self")
})

// createWorkItemLinkCategoryPayload defines the structure of work item link category payload in JSONAPI format during creation
var createWorkItemLinkCategoryPayload = a.Type("CreateWorkItemLinkCategoryPayload", func() {
	a.Attribute("data", workItemLinkCategoryData)
	a.Required("data")
})

// updateWorkItemLinkCategoryPayload defines the structure of work item link category payload in JSONAPI format during update
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)
Exemple #17
0
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")