Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http4s generator does not handle non-string headers #155

Open
blast-hardcheese opened this issue Jan 7, 2019 · 0 comments
Open

http4s generator does not handle non-string headers #155

blast-hardcheese opened this issue Jan 7, 2019 · 0 comments
Labels
bug Unexpected behaviour for functionality that either was intended to work, or has worked in the past good first issue Does not require deep knowledge of the codebase and is easily testable help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought scala-http4s Pertains to guardrail-scala-http4s

Comments

@blast-hardcheese
Copy link
Member

Related to #150

Currently, server headers are handled as:

req.headers.get("x-header".ci).map(_.value).map(Json.fromString(_).as[Boolean])

... resulting in attempting to parse the JSON literal "false" as a Boolean, which can never be true. This is related to a similar issue in the akka-http generator, where X-Header: "" will be silently converted to an empty string, as circe Decoders are used similar to parser.parse(str).orElse(Json.fromString(str)).flatMap(_.as[Boolean]) to attempt to decode all possible x-scala-type overrides.

I believe the most effective way to disambiguate this usecase is to alter headersToHttp4s (and likely formToHttp4s, and any other place Json.fromString is used) by adding an additional parameter to each case in directivesFromParams, baseType: Type.Name, to explicitly handle String decoders vs other JSON literal values.

Test swagger spec:

swagger: '2.0'
paths:
  /test:
    post:
      operationId: createFoo
      parameters:
        - in: header
          name: x-header
          type: boolean
          required: true
        - in: header
          name: x-optional-header
          type: boolean
          required: false
      responses:
        200:
          description: stub
@blast-hardcheese blast-hardcheese added help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought good first issue Does not require deep knowledge of the codebase and is easily testable bug Unexpected behaviour for functionality that either was intended to work, or has worked in the past scala-http4s Pertains to guardrail-scala-http4s labels Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour for functionality that either was intended to work, or has worked in the past good first issue Does not require deep knowledge of the codebase and is easily testable help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought scala-http4s Pertains to guardrail-scala-http4s
Projects
None yet
Development

No branches or pull requests

1 participant