OpenAPITools / OpenAPITools/openapi-generator

[C++][Pistache-Server] Creation of weird #include statements from oneOf-statement

Open
#2,477 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: C++
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

If I use a schema definition as shown in the yaml-snippet below, I get a file Error.h that contains the following #include statement:
#include OneOfErrInternalErrorErrInvalidIdErrCurrentlyNotAllowedErrApplicationNotLoadableErrApplicationNotAvailableErrItemDoesNotExist.h"
that will never compile because such a file does not exist.
It also contains the following method-declrarations:
OneOfErrInternalErrorErrInvalidIdErrCurrentlyNotAllowedErrApplicationNotLoadableErrApplicationNotAvailableErrItemDoesNotExist getCode() const;
void setCode(OneOfErrInternalErrorErrInvalidIdErrCurrentlyNotAllowedErrApplicationNotLoadableErrApplicationNotAvailableErrItemDoesNotExist const& value);

Neither while validating the yaml that contains this schema does issue an error message nor does the creation process.

openapi-generator version

4.0.0-beta2

OpenAPI declaration file content or url

'''yaml
components:
schemas:
Error:
type: object
required:
- code
- message
properties:
code:
oneOf:
- $ref: '#/components/schemas/ErrInternalError'
- $ref: '#/components/schemas/ErrInvalidId'
- $ref: '#/components/schemas/ErrCurrentlyNotAllowed'
- $ref: '#/components/schemas/ErrApplicationNotLoadable'
- $ref: '#/components/schemas/ErrApplicationNotAvailable'
- $ref: '#/components/schemas/ErrItemDoesNotExist'
message:
type: string
'''

Command line used for generation

java -ea -Xms512M -Xmx1024M -server -jar /home/fili/alpine/gernjo/openAPI/openapi-generator-cli-4.0.0-beta2.jar generate -i ./ontrestapi_device/ore_device.yaml -g cpp-pistache-server -o ./generated_server

Suggest a fix
  • Create one include-statement for each of the items listed under oneOf
  • Create one specific setter/getter method for each of the items listed under oneOf

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

Reproduce the issue with the supplied YAML schema and the cpp-pistache-server generation command, then inspect the generated Error.h. Trace how the oneOf entries become the include and accessor type names; done means each referenced schema has valid includes and distinct getter/setter declarations, with generation completing without invalid output.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.