OpenAPI Generator: Initialize List properties as null and not as empty Lists
Asked Answered
M

1

6

Problem: When I generate a class with the openAPI code generator properties with a List type are initialized right away as an empty ArrayList. I want to remove this initialization, so that this property can be null. How can I do this in the openAPI specification?

Use-Case: For my merge-patch operation, I need to distinguish between giving an empty list as parameter or not specifying the parameter at all. I would expect that I get an empty list when the parameter is given but contains an empty List and null if the parameter is not given.

Murguia answered 18/7, 2022 at 11:50 Comment(0)
B
6

The option containerDefaultToNull let you choose if null or empty (List, Map), see the doc.

But it seems the generated code/parser won't distinguish a null or empty input. I'm not sure about it, you should analyse the generated code for that.

Bis answered 26/4, 2023 at 8:15 Comment(1)
This solved my problem! Thx!Accrual

© 2022 - 2024 — McMap. All rights reserved.