forked from fabric8-services/fabric8-wit
/
render.go
80 lines (72 loc) · 2.72 KB
/
render.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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")
})
a.Required("content")
a.Required("markup")
})
// MarkupRenderingMediaType is the media type for rendering result
var markupRenderingMediaType = JSONSingle(
"MarkupRendering",
`MarkupRenderingMediaType contains the
rendering of the 'content' provided in the request, using
the markup language specified by the 'markup' value.`,
markupRenderingMediaTypeData,
nil,
)
// MarkupRenderingMediaType is the data included in the rendering result response.
var markupRenderingMediaTypeData = a.Type("MarkupRenderingData", func() {
a.Attribute("id", d.String, "an ID to conform to the JSON-API spec, even though it is meaningless in the case of the rendering endpoint. Can be null", func() {
a.Example("42")
})
a.Attribute("type", d.String, func() {
a.Enum("rendering")
})
a.Attribute("attributes", markupRenderingMediaTypeDataAttributes)
a.Required("id")
a.Required("type")
a.Required("attributes")
})
// MarkupRenderingMediaType is the data included in the rendering result response.
var markupRenderingMediaTypeDataAttributes = a.Type("MarkupRenderingDataAttributes", func() {
a.Attribute("renderedContent", d.String, "The rendered content", func() {
a.Example("<h1>foo</h1>")
})
a.Required("renderedContent")
})
var _ = a.Resource("render", func() {
a.BasePath("/render")
a.Security("jwt")
a.Action("render", func() {
a.Description("Render some content using the markup language")
a.Routing(a.POST(""))
a.Payload(markupRenderingPayload)
a.Response(d.OK, markupRenderingMediaType)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
})
})