MCPcopy Create free account
hub / github.com/goadesign/goa / responseFromExpr

Function responseFromExpr

http/codegen/openapi/v3/response.go:33–100  ·  view source on GitHub ↗
(r *expr.HTTPResponseExpr, bodies map[int][]*openapi.Schema, rand *expr.ExampleGenerator)

Source from the content-addressed store, hash-verified

31}
32
33func responseFromExpr(r *expr.HTTPResponseExpr, bodies map[int][]*openapi.Schema, rand *expr.ExampleGenerator) *Response {
34 ct := r.ContentType
35 rt, ok := r.Body.Type.(*expr.ResultTypeExpr)
36 if ok && ct == "" {
37 ct = rt.ContentType
38 }
39 if ct == "" {
40 // Default to application/json
41 ct = "application/json"
42 }
43 headers := headersFromAttr(r.Headers, rand)
44 cookies := headersFromAttr(r.Cookies, rand)
45 if len(cookies) > 0 {
46 if headers == nil {
47 headers = make(map[string]*HeaderRef)
48 }
49 if len(cookies) == 1 {
50 for _, v := range cookies {
51 headers["Set-Cookie"] = v
52 }
53 } else {
54 // Generic cookies header
55 headers["Set-Cookie"] = &HeaderRef{
56 Value: &Header{
57 Description: "Cookies set by the server",
58 Required: true,
59 Schema: &openapi.Schema{
60 Type: "string",
61 },
62 },
63 }
64 }
65 }
66
67 var content map[string]*MediaType
68 {
69 if r.Body.Type != expr.Empty {
70 content = make(map[string]*MediaType)
71 content[ct] = &MediaType{
72 Schema: bodies[r.StatusCode][0],
73 Extensions: openapi.ExtensionsFromExpr(r.Body.Meta),
74 }
75 initExamples(content[ct], r.Body, rand)
76 } else if r.StatusCode != expr.StatusNoContent &&
77 isSkipResponseBodyEncodeDecode(r.Parent) {
78 // When SkipResponseBodyEncodeDecode is declared, the response type
79 // is Empty, but the response code is not 204 and has content.
80 content = make(map[string]*MediaType)
81 content[ct] = &MediaType{
82 Schema: &openapi.Schema{
83 Type: "string",
84 Format: "binary",
85 },
86 Extensions: openapi.ExtensionsFromExpr(r.Body.Meta),
87 }
88 }
89 }
90 desc := r.Description

Callers 1

buildOperationFunction · 0.85

Calls 4

ExtensionsFromExprFunction · 0.92
headersFromAttrFunction · 0.85
initExamplesFunction · 0.85

Tested by

no test coverage detected