You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generated Lists default to empty List even when using nullable: true and containerDefaultToNull: true
We need to allow the end user to not pass a certain non-required list query param and recognize it as null, because we need to distinguish it from when they pass us an empty list -> it means semantically something else than when they do not pass anything, pass null as the query param. The containerDefaultToNull was supposed to affect this, but setting that property leads to exactly same generated code base. Adding nullable: true also doesn't help, as was suggested elsewhere to use.
openapi: 3.0.0info:
title: Simple APIversion: 1.0.0paths:
/your-endpoint:
get:
summary: Endpoint that accepts a list of strings as a query parameterparameters:
- name: itemsin: querydescription: A list of stringsrequired: falseschema:
type: arraynullable: trueitems:
type: stringresponses:
'200':
description: Successful response
and you can actually leave it out and compare what's generated and you'll see you get exactly the same code base, which points to the fact, that the parameter is completely ignored.
Steps to reproduce
Use the generator as above with the specified spec above
Do the same but with the configuration above used
Observe that there is no difference in codebase. Calling the endpoint without the query param will result in an empty list for the query param on the server code.
Related issues/PRs
This looks similar, but says the other way around -> that it no longer defaults to list but to null. I have the opposite experience. #15891 My comment there about this issue is: #15891 (comment)
Instead of returning empty list params based on those preconditions, the code should check for the presence of the containerDefaultToNull option being set to true and also should check if the field is required or nullable, etc.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
Generated Lists default to empty List even when using nullable: true and containerDefaultToNull: true
We need to allow the end user to not pass a certain non-required list query param and recognize it as null, because we need to distinguish it from when they pass us an empty list -> it means semantically something else than when they do not pass anything, pass null as the query param. The containerDefaultToNull was supposed to affect this, but setting that property leads to exactly same generated code base. Adding nullable: true also doesn't help, as was suggested elsewhere to use.
openapi-generator version
6.5, 7.1, latest docker image, assuming that's 8.0
OpenAPI declaration file content or url
Generation Details
openapi-generator generate -g java -i open/openapi.yaml -o open2 -c /tmp/config.json
config has only
and you can actually leave it out and compare what's generated and you'll see you get exactly the same code base, which points to the fact, that the parameter is completely ignored.
Steps to reproduce
Related issues/PRs
This looks similar, but says the other way around -> that it no longer defaults to list but to null. I have the opposite experience. #15891 My comment there about this issue is: #15891 (comment)
Suggest a fix
The generated ApiClient.java has this part there
Instead of returning empty list params based on those preconditions, the code should check for the presence of the containerDefaultToNull option being set to true and also should check if the field is required or nullable, etc.
The text was updated successfully, but these errors were encountered: