Open RalphBragg opened 4 years ago
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
cc @YishTish
I too have encountered this problem (with @openapitools/openapi-generator-cli@1.0.15-5.0.0-beta). Here is a minimal spec with endpoints for the case of having the body directly defined in the path definition (which works as expected) and using a body definition in /components/requestBodies (which fails).
openapi: "3.0.0"
info:
description: "Demonstrate a problem with openapi-generator generate -i openapi.yaml -g nodejs-express-server"
version: "0.0.0"
title: "Test $ref to requestBodies element"
tags:
- name: "test"
description: "description"
paths:
/works:
post:
description: "Working version - defines content body directly"
summary: "working version"
operationId: "add_works"
tags:
- "test"
requestBody:
description: "directly-defined body"
required: true
content:
application/json:
schema:
type: "object"
properties:
data:
type: "string"
responses:
"200":
description: "Success"
/fails:
post:
description: "Failing version - defines content via reference to components/requestBodies/Body"
summary: "failing version"
operationId: "add_fails"
tags:
- "test"
requestBody:
$ref: "#/components/requestBodies/Body"
responses:
"200":
description: "Success"
components:
requestBodies:
Body:
required: true
content:
application/json:
schema:
type: "object"
properties:
data:
description: "data"
type: "string"
Here's a makefile to build and run the server and show the problem:
index.js: openapi.yaml
openapi-generator generate -i openapi.yaml -g nodejs-express-server
PHONY: server
server: index.js
PHONY: run
run: index.js
npm start
PHONY: test
test: index.js
@echo Test working version
@curl -X POST http://localhost:3000/works -H "accept: */*" -H "Content-Type: application/json" -d '{"data":"The data"}'
@echo
@echo Test failing version
@curl -X POST http://localhost:3000/fails -H "accept: */*" -H "Content-Type: application/json" -d '{"data":"The data"}'
Use:
make server
make run
And then, from another terminal session:
make test
Results (under Cygwin):
$ make test
Test working version
{}
Test failing version
Cannot read property 'application/json' of undefined
Hi - was this ever addressed?
I see the problem. Don't remember if I handled it back in the day. Will check later and update.
On Thu, May 13, 2021 at 8:33 AM Ralph Bragg @.***> wrote:
Hi - was this ever addressed?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OpenAPITools/openapi-generator/issues/6678#issuecomment-840313691, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGOOLMERXQZEDFIUBUEBHTTNNQCDANCNFSM4N6QI6WQ .
Yishai Landau
C: 972-54-979-2080 T: 972-8-6333-960 E: @.***
Bug Report Checklist
Description
The NodeJS Express Server generator controller.js does not process reference request bodies. Is there are a way to make it do so?
openapi-generator version
5
OpenAPI declaration file content or url
Command line used for generation
OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT openapi-generator-cli generate -i /TrustFramework.yaml -o ./output -g nodejs-express-server
Steps to reproduce
Related issues/PRs
Suggest a fix
Can reference request bodies be handled