OpenAPITools / OpenAPITools/openapi-generator
[BUG] [C++][Pistache] requestBody application/json schema "type: boolean" generates type mismatch
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If requestBody is specified as application/json type boolean, code similar to the following is generated...and request.body() can not be coerced into boolean without parse(...).get_to().
void DefaultApi::pet_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
// Getting the body param
bool body;
try {
body = request.body();
openapi-generator version
7.10.0...but have seen similar in many versions since 4.1.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Swagger Petstore - OpenAPI 3.0
version: 1.0.11
paths:
/pet:
post:
requestBody:
content:
application/json:
schema:
type: boolean
required: true
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
required:
- name
type: object
properties:
name:
type: string
example: doggie
Generation Details
Steps to reproduce
java -jar Downloads/openapi-generator-cli-7.10.0.jar generate -i dog.yaml -g cpp-pistache-server -o exp
Related issues/PRs
Appears to be caused by https://github.com/OpenAPITools/openapi-generator/pull/3509/files
Suggest a fix
Generate code similar to what 4.0.2 generates:
void DefaultApi::pet_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the body param
bool body;
try {
nlohmann::json::parse(request.body()).get_to(body);
this->pet_post(body, response);
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
Reproduce the issue with the provided OpenAPI declaration and the cpp-pistache-server generation command, then inspect the generated pet_post_handler body handling. Compare the current output with the 4.0.2 example; done when a boolean application/json request body is parsed as JSON before being passed to pet_post.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100