Skip to content

text/plain response referencing component of string enum creates uncompilable code in Java #1909

@lukeramsden

Description

@lukeramsden

Here is a minimal recreation of the issue, tested using the integration tests locally. This is a heavily trimmed down version of Supertokens' FDI schema in its resolved form.

openapi: 3.0.0
info:
  title: Whatever
  version: 1.0.0
servers:
  - url: //localhost:1234/foo/
paths:
  /blah/blah:
    post:
      description: Do something!
      operationId: do-something
      responses:
        "500":
          description: error code 500
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/internalError'
components:
  schemas:
    internalError:
      type: string
      enum:
        - Internal Error

It logs warnings:

[info] WARNING: Don't know how to handle response of type issues.issuedraft.client.dropwizardVavr.definitions.InternalError for content type text/plain at .paths./blah/blah.operations.POST; falling back to String
[info] WARNING: Don't know how to handle response of type issues.issuedraft.client.dropwizard.definitions.InternalError for content type text/plain at .paths./blah/blah.operations.POST; falling back to String

And then fails with a compilation error:

[error] /Users/lukeramsden/workspace/guardrail/modules/sample-dropwizard/target/generated/issues/issuedraft/client/dropwizard/Client.java:96:1: incompatible types: java.lang.String cannot be converted to issues.issuedraft.client.dropwizard.definitions.InternalError
[error] response
[error]                                     .getResponseBody(AsyncHttpClientUtils.getResponseCharset(response)
[error]                                             .orElse(StandardCharsets.UTF_8))
[error] (sample-dropwizard / Compile / compileIncremental) javac returned non-zero exit code

It's quite easy to find where this code is generated (here https://github.com/guardrail-dev/guardrail/blob/e3c9b944ed2228a49bac03581d8b0ddc09ed3098/modules/java-async-http/src/main/scala/dev/guardrail/generators/java/asyncHttpClient/AsyncHttpClientClientGenerator.scala#L860C67-L860C67) but not clear to me if this is invalid OAS3 (the linters I can find all seem to allow it) or just a missing case here - if the body value type is an enum, I would expect it to use the object mapper to read it even for text/plain?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions