(_ *V2, root *expr.RootExpr, r *expr.HTTPResponseExpr, typeNamePrefix string)
| 343 | } |
| 344 | |
| 345 | func responseSpecFromExpr(_ *V2, root *expr.RootExpr, r *expr.HTTPResponseExpr, typeNamePrefix string) *Response { |
| 346 | var schema *openapi.Schema |
| 347 | if mt, ok := r.Body.Type.(*expr.ResultTypeExpr); ok { |
| 348 | view := expr.DefaultView |
| 349 | if v, ok := r.Body.Meta.Last(expr.ViewMetaKey); ok { |
| 350 | view = v |
| 351 | } |
| 352 | schema = openapi.NewSchema() |
| 353 | schema.Ref = openapi.ResultTypeRefWithPrefix(root.API, mt, view, typeNamePrefix) |
| 354 | } else if r.Body.Type != expr.Empty { |
| 355 | schema = openapi.AttributeTypeSchemaWithPrefix(root.API, r.Body, typeNamePrefix) |
| 356 | } |
| 357 | if schema != nil { |
| 358 | schema.Extensions = openapi.ExtensionsFromExpr(r.Meta) |
| 359 | } |
| 360 | headers := headersFromExpr(r.Headers) |
| 361 | desc := r.Description |
| 362 | if desc == "" { |
| 363 | desc = fmt.Sprintf("%s response.", http.StatusText(r.StatusCode)) |
| 364 | } |
| 365 | return &Response{ |
| 366 | Description: desc, |
| 367 | Schema: schema, |
| 368 | Headers: headers, |
| 369 | Extensions: openapi.ExtensionsFromExpr(r.Meta), |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | func headersFromExpr(headers *expr.MappedAttributeExpr) map[string]*Header { |
| 374 | if headers == nil { |
no test coverage detected