guardrail-dev / guardrail-dev/guardrail

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

Open
#1,909 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
541
Forks
138
PR merge metrics
No merged PRs in 30d

Description

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](https://app.swaggerhub.com/apis/supertokens/FDI/1.18.0#/) in its resolved form.

```yml
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.