guardrail-dev / guardrail-dev/guardrail
Only one response type is generated
- Dominant language
- Scala
- Stars
- 541
- Forks
- 138
- PR merge metrics
- No merged PRs in 30d
Description
Hello!
Thanks for this library.
I wanted to have a server endpoint return different response schemas depending on the media type, like so:
```json
"/login": {
"post": {
"description": "Mint token",
"operationId": "mintAccountTokenFromSiteCredential",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MintAccountTokenFromSiteCredentialResponse"
}
},
"text/plain": {
"schema": {
"$ref": "#/components/schemas/AccountToken"
}
}
},
"description": "account access token"
}
}
}
}
```
I see the generated code doesn't permit providing the `text/plain` response, as there's only code for providing the object response:
```scala
case class MintAccountTokenFromSiteCredentialResponseOK(value: _root_.com.damlhub.openapi.definitions.MintAccountTokenFromSiteCredentialResponse) extends MintAccountTokenFromSiteCredentialResponse(StatusCodes.OK)
```
When removing the `application/json` and keeping only the `text/plain` response:
```scala
case class MintAccountTokenFromSiteCredentialResponseOK(value: String) extends MintAccountTokenFromSiteCredentialResponse(StatusCodes.OK)
```
Also, I assume I would have to manually add the `Accept` header to the openapi definition to be able to decide which response Media Type to return in my handlers?
Contributor guide
Research direction
Start with the generated Scala response case classes shown in the issue and trace how the OpenAPI response content is turned into them. Verify behavior for the provided application/json and text/plain schemas, then confirm that handlers can represent both media types for the same status code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100