[BUG][NODEJS-EXPRESS-SERVER] Body data will not be processed.
Created by: cjuenger
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
The generated server stub does not handle data (defined as schema in OpenAPI 3.0) transferred in the body HTTP. The generated code uses the name of the schema (here: bodyData) as the name of the input parameter of the generated service method (here: static addDataPerBody({bodyData}).
That is the issue, the controller parses all data in the body of a HTTP request into 'requestParams.body' which won't work for destructuring the assignment to '{bodyData}'.
See 'Suggest a fix' below for a possible fix.
openapi-generator version
Version 4.2.2
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Titel
description: Some description
version: 0.0.0.0
servers:
- url: /some/uri
paths:
/groups:
post:
operationId: addDataPerBody
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/BodyData'
required: true
responses:
'200':
description: Id of added data.
content:
application/json:
schema:
$ref: '#/components/schemas/DataId'
components:
schemas:
BodyData:
type: object
properties:
id:
type: integer
name:
type: string
info:
type: string
created:
type: string
changed:
type: string
required:
- name
DataId:
type: object
properties:
id:
type: integer
description: ID of the group.
Command line used for generation
openapi-generator generate -g nodejs-express-server -i .\FILE.yaml -o .\TARGET\DIR
Steps to reproduce
Related issues/PRs
Suggest a fix
Every service function parameter simply needs to be identified by 'body' and aliased by the schema name.
For example: Change 'static addDataPerBody({bodyData})' to 'static addDataPerBody({'body': bodyData})'