openfoodfacts / open-prices

An open database of prices 🧾💸💰🏷️🤑🍽️
https://prices.openfoodfacts.org
GNU Affero General Public License v3.0
41 stars 12 forks source link

OneOf is currently not handled by OpenAPI code generator #522

Open AdrienMDevMobile opened 1 month ago

AdrienMDevMobile commented 1 month ago

OneOf is correctly not handled by the generator. He should come for the 3rd version, but is currently on the roadmap : https://openapi-generator.tech/docs/roadmap/#short-term This is blocking for the different fields using OneOf to describe the possibility of beeing a value or null/empty.

raphodn commented 1 month ago

Which field/endpoint is concerned by this ?

I don't mind taking the time to improve the API specs, but I need more info :)

AdrienMDevMobile commented 1 month ago

Thank you !

There are 4 field using oneOf : price_per, currency, location_osm_type and source

Those field are seen multiple times price_per, currency, location_osm_type of of PriceCreate price_per, currency of PatchedPriceUpdate currency of PatchedProofUpdate price_per, currency, location_osm_type of PriceFull price_per and currency of PriceUpdate source of ProductFull location_osm_type and currency of Proof location_osm_type and currency of ProofFull currency of ProofUpdate location_osm_type and currency of ProofUpload

This lead to 4 incorrect files : PatchedPriceUpdateCurrency.kt PatchedPriceUpdatePricePer PriceCreateLocationOsmType.kt ProductFullSource.kt

Yes, PatchedPriceUpdateCurrency is used in the generated files in every places where currency is used (not just patchedproficeupdate)

AdrienMDevMobile commented 3 weeks ago

According to this stackoverflow user, empty string should rather be optional : https://stackoverflow.com/questions/73244706/spring-boot-openapi-swagger-enums-with-empty-strings-generates-empty-inste

Since null/empty is exactly why we are using oneOfs, this may be the solution.

AdrienMDevMobile commented 3 weeks ago

Is the oneOf that we can find like this : oneOf:

done to preemptively be compatible with v3.1 ?

If not, what is the purpouse when we already have nullable:true on all those fields ?

raphodn commented 2 weeks ago

There are 4 field using oneOf : price_per, currency, location_osm_type and source

In the Django code, these fields indeed have restricted "choices", but can also be null. For instance Price.price_per is null if the price is for a barcode product (but it will be filled if the price is for a category_tag)

raphodn commented 2 days ago

https://github.com/OpenAPITools/openapi-generator/issues/19258 oneOf + null / fixed & available in v7.9.0