OpenAPITools / OpenAPITools/openapi-generator
[BUG][C] Zero as integer in model
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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
I have a yaml file in swagger: "2.0" format that includes integer that can be zero (see below). If I set the resolution or the framerate to zero, to indicate the first options, this will result in the argument not being sent. The following check is added inside the stream.c file:
// stream->resolution
if(stream->resolution) {
if(cJSON_AddNumberToObject(item, "resolution", stream->resolution) == NULL) {
goto fail; //Numeric
}
}
If the resolution is set to zero, then if(stream->resolution) will return false and the zero is not added to the output.
openapi-generator version
openapitools/openapi-generator-cli@sha256:d2fee993745f8e003dfc5b79bbe03ae35a4a455540b084681c9a05deb601f7b0
OpenAPI declaration file content or url
stream:
type: "object"
properties:
resolution:
type: "integer"
format: "uint8"
description: "Resolution
0: 1920x1080\n
1: 1280x720\n
2: 960x544\n
3: 800x600\n
4: 800x480\n
5: 704x400\n
6: 640x480\n
7: 640x360\n
8: 320x240"
minimum: 0
maximum: 7
framerate:
type: "integer"
format: "uint8"
description: "Framerate.
0: 60 FPS\n
1: 50 FPS\n
2: 10 FPS\n
minimum: 0
maximum: 2
Generation Details
Steps to reproduce
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -i /local/restapi.yaml -g c -o /local/out/c
Related issues/PRs
Suggest a fix
I think something this line is fishy for integers.
https://github.com/OpenAPITools/openapi-generator/blob/04ebe9e1a0a9d51c04999659f3bdd169b7296a72/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache#L347
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache at the linked line, then reproduce with the provided Docker generation command and the YAML example. Verify the generated stream.c behavior for resolution or framerate set to zero; done means zero-valued integer arguments are included in the generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, docker, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100