Open
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);