Return an empty list when no matching result found instead of hiding "results" field
Currently, when there are no matching results, we only have the generationtime_ms field:
This is a problem as I can’t make the difference between “parsing error” (due to missing results field) and “no location matched your query”.
results should be hidden only when an error happened, and not when no matching locations were found. In that case, it should be an empty list (not a null value, which would be the same as no results field).
Thank you!
I'm not familiar with Swift, but I tried reading a bit the code.
It looks like results is initialized with an empty list, and not with a null value:
https://github.com/open-meteo/geocoding-api/blob/c64553775c2f3f35bc66f57392e2ed8a39551ef6/Sources/App/api.pb.swift#L35
So I tried searching for an empty check that would replace the empty list with a null value, and I found this:
https://github.com/open-meteo/geocoding-api/blob/c64553775c2f3f35bc66f57392e2ed8a39551ef6/Sources/App/api.pb.swift#L207-L209
I'm not sure if it is related to our issue, as I don’t understand what it does.
Do you think you could have a look at it, in case there is an easy fix for this issue? Thanks!
Currently the geocoding API is using the JSON encoder from the Protobuf Swift library. This library skips attributes with empty arrays or null values. Technically it is not wrong, but I also do not like this behaviour. Unfortunately, I cannot change this behaviour and would have to replace the entire library.
I plan to ingrate Flatbuffers and a different JSON encoder, but there is no fixed timeline.