OpenAPITools / OpenAPITools/openapi-generator
[scala][scala-play-server][Question] How to use non 200 response codes?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I ran a code generation of the petstore spec for Scala Play server (see below).
The spec mentions HTTP error codes, for instance getting a pet by id /pet/{petId} could return a 404 if the pet is not found. (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml#L181)
However, the generated code only returns Ok. There seems to be no way of avoiding this.
* GET /v2/pet/:petId
* @param petId ID of pet to return
*/
def getPetById(petId: Long): Action[AnyContent] = Action { request =>
def executeApi(): Pet = {
api.getPetById(petId)
}
val result = executeApi()
val json = Json.toJson(result)
Ok(json)
}
We use this code generation as a compile step so we expect routes, models and controllers to be correct according to the .yml spec. Is this a wrong assumption to make? Or am I overseeing something?
openapi-generator version
5.0.1
OpenAPI declaration file content or url
Generation Details
openapi-generator-cli generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-play-server -o play-new`
Steps to reproduce
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the scala-play-server output for getPetById and compare it with the petstore.yaml operation linked in the issue, including its documented 404 response. Trace how response codes are represented in the generated controller and run the provided openapi-generator command. Done means the generated server handles the declared non-200 response codes consistently with the specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100