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

Comments

Projects
None yet
1 participant
@blast-hardcheese
Copy link
Collaborator

blast-hardcheese commented Jan 7, 2019

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment