paramsFromHeadersAndCookies computes the OpenAPI spec parameters for the given endpoint HTTP headers and cookies.
(endpoint *expr.HTTPEndpointExpr, rand *expr.ExampleGenerator)
| 35 | // paramsFromHeadersAndCookies computes the OpenAPI spec parameters for the |
| 36 | // given endpoint HTTP headers and cookies. |
| 37 | func paramsFromHeadersAndCookies(endpoint *expr.HTTPEndpointExpr, rand *expr.ExampleGenerator) []*Parameter { |
| 38 | var params []*Parameter |
| 39 | |
| 40 | expr.WalkMappedAttr(endpoint.Headers, func(name, elem string, att *expr.AttributeExpr) error { // nolint: errcheck |
| 41 | if openapiinternal.IsSecurityParameter(endpoint, "header", elem) { |
| 42 | return nil |
| 43 | } |
| 44 | required := endpoint.Headers.IsRequiredNoDefault(name) |
| 45 | params = append(params, paramFor(att, elem, "header", required, rand)) |
| 46 | return nil |
| 47 | }) |
| 48 | expr.WalkMappedAttr(endpoint.Cookies, func(name, elem string, att *expr.AttributeExpr) error { // nolint: errcheck |
| 49 | if openapiinternal.IsSecurityParameter(endpoint, "cookie", elem) { |
| 50 | return nil |
| 51 | } |
| 52 | required := endpoint.Cookies.IsRequiredNoDefault(name) |
| 53 | params = append(params, paramFor(att, elem, "cookie", required, rand)) |
| 54 | return nil |
| 55 | }) |
| 56 | |
| 57 | return params |
| 58 | } |
| 59 | |
| 60 | // paramFor converts the given attribute into a OpenAPI spec parameter. |
| 61 | func paramFor(att *expr.AttributeExpr, name, in string, required bool, rand *expr.ExampleGenerator) *Parameter { |
no test coverage detected