OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Javascript] Required properties of composed models not included in constructor parameters

Open
#2,438 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: JavaScript/Node.js Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Model schemas which use allOf to compose other schemas produce constructors which do not have parameters for the required properties of their composed classes. This results in invalid code which produces ReferenceErrors.

Example which reproduces this error: https://github.com/kvsm/test-api

The bug is evident at https://github.com/kvsm/test-api/blob/b9c2f82b283a6c6bd199eb40655c441081dd0680/client/src/Model/DescribedThing.js#L30 where ReferenceError: name is not defined will be thrown.

openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url

https://github.com/kvsm/test-api/blob/master/TestAPI.json

Command line used for generation

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/TestAPI.json -g javascript -c /local/config-javascript.json -o /local/client

Steps to reproduce

See https://github.com/kvsm/test-api; or:

  1. Create an OpenAPI schema containing a model schema which composes one or more schemas having required properties.
  2. Generate javascript client with said schema.
  3. Execute npm install && npm run test in generated client project.
Expected output

Tests execute successfully.

Actual output

Tests fail with ReferenceError.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TestAPI.json and the generated client file DescribedThing.js at the referenced line. Run the provided Docker generation command, then npm install && npm run test in the generated client to reproduce the ReferenceError. Trace how the JavaScript generator handles allOf schemas with required properties; done means the generated constructor includes those properties and the tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.