Ejemplo n.º 1
0
// 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")
		})
	})

}
Ejemplo n.º 2
0
// 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")
		})
	})
}
Ejemplo n.º 3
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")
Ejemplo n.º 4
0
		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")
	})
})

var tokenData = a.Type("TokenData", func() {
	a.Attribute("access_token", d.String, "Access token")
	a.Attribute("expires_in", d.Integer, "Access token expires in seconds")
	a.Attribute("refresh_expires_in", d.Integer, "Refresh token expires in seconds")
	a.Attribute("refresh_token", d.String, "Refresh token")
Ejemplo n.º 5
0
		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")
	a.Attribute("version", d.Integer, "Version for optimistic concurrency control")
	a.Attribute("type", d.String, "Name of the type of this work item")
	a.Attribute("fields", a.HashOf(d.String, d.Any), "The field values, according to the field type")

	a.Required("id")
	a.Required("version")
	a.Required("type")
	a.Required("fields")

	a.View("default", func() {
		a.Attribute("id")
		a.Attribute("version")
		a.Attribute("type")
Ejemplo n.º 6
0
Like title, this field’s value can be localized.`)
	a.Attribute("source", a.HashOf(d.String, d.Any), `an object containing references to the source of the error,
optionally including any of the following members

* pointer: a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object,
           or "/data/attributes/title" for a specific attribute].
* parameter: a string indicating which URI query parameter caused the error.`)
	a.Attribute("meta", a.HashOf(d.String, d.Any), "a meta object containing non-standard meta-information about the error")

	a.Required("detail")
})

// JSONAPIErrors is an array of JSONAPI error objects
var JSONAPIErrors = a.MediaType("application/vnd.jsonapierrors+json", func() {
	a.UseTrait("jsonapi-media-type")
	a.TypeName("JSONAPIErrors")
	a.Description(``)
	a.Attributes(func() {
		a.Attribute("errors", a.ArrayOf(JSONAPIError))
		a.Required("errors")
	})
	a.View("default", func() {
		a.Attribute("errors")
		a.Required("errors")
	})
})

// relationGeneric is a top level structure for 'other' relationships
var relationGeneric = a.Type("RelationGeneric", func() {
	a.Attribute("data", genericData)
	a.Attribute("links", genericLinks)