foojayio / discoapi

The foojay discovery api (discoapi) is made to discover java packages (jre/jdk) from different distributions.
GNU General Public License v2.0
111 stars 13 forks source link

Previously working APIs now return invalid JSON bodies #19

Closed marchof closed 3 years ago

marchof commented 3 years ago

For example:

geertjanw commented 3 years ago

Probably wait a little bit, a new version has just been released.

HanSolo commented 3 years ago

We had to make some changes. Could you try to add &latest=overall to the url?

marchof commented 3 years ago

@geertjanw Are you sure time will heal invalid JSON syntax? 🤔

geertjanw commented 3 years ago

Can you try Gerrit's suggestion above?

marchof commented 3 years ago

@HanSolo the extra parameter &latest=overall fixes some results. But in case there are no results the returned JSON has a syntax error (misplaces colon):

https://api.foojay.io/disco/v1.0/packages?version=8&distro=aojup&latest=overall

{
  "info":"No package found",

}
HanSolo commented 3 years ago

Ok, will take a look at it, thx for the heads up 👍🏻

marchof commented 3 years ago

Another remark: If my query does not result in a hit, I would expect an empty result set from the API. Not an object with a test message. The new behavior would force me to implement if/else for the API calls to handle the no-result case separately.

Any ETA when this case can be fixed? Currently my update jobs and the download page on javaalmanac.io is broken.

HanSolo commented 3 years ago

That was discussed in another round where more than one person decided it would be better to get at least a message that nothing was found instead of returning an empty array. I think we need to discuss that internally once more.

marchof commented 3 years ago

Please look at this from a client side. It really forces every client to introduce ugly type checks.

Alternatively you can have a message along the empty result (introducing a result wrapper object consisting of result an meta data).

marchof commented 3 years ago

And in any case it should be parseable Json...

HanSolo commented 3 years ago

It was suggested by clients, so no internal discussion but with clients

marchof commented 3 years ago

Ok...

HanSolo commented 3 years ago

And yes it should be parseable, that's right :)

marchof commented 3 years ago

@HanSolo Looks like the syntax is fixed.

So now what is the official contract to correctly process the empty result case? Should clients test for the string value of the info attribute?

{
    "info":"No package found"
}

Should clients test for the data type (array vs. object)? Maybe someone who was involved in the discussion about the new API can enlighten us here :)

geertjanw commented 3 years ago

Would you like to be involved, @marchof? We could set up a meeting where you and others who want to discuss the Disco API and provide input into it could get together to discuss?

marchof commented 3 years ago

Sure, at least from my javaalmanac.io perspective I could give feedback. Not sure whether meetings are the right format in the long run. Typically API changes are best tracked via issues and pull-requests.

geertjanw commented 3 years ago

You are welcome to provide issues and pull requests any time and they'll be warmly welcomed. :-)

marchof commented 3 years ago

Well, I meant the other way round: If there are API changes there should be a public discussion here on the tracker and a PR so interested parties can review and test before it is deployed.

geertjanw commented 3 years ago

Agreed. Also on the Foojay Slack channel, there's now a dedicated channel #disco for these discussions too.

HanSolo commented 3 years ago

Ok so what should we do now? I personal have no preference but I agree we need a working version. So the easiest way would be the one we had in the beginning: If nothing was found the API will return an empty json array "[]". I've just changed it because more than one person asked for having a meaningful response in case nothing was found. If you would ask me personally...an empty result is an empty result...means nothing was found, but if anyone has a different opinion, please let me know.

marchof commented 3 years ago

I would prefer a solution where the schema of the result is fixed and (technical) clients are not forced to create code to distinguish cases. If meta information is required a envelope object would be the best option and also allows addition of additional meta data in future. For example:

{
    "result": []
    "message": "No package found"
}

This should probably then consistently for all APIs (v2.0).

HanSolo commented 3 years ago

Yep that looks like a good approach and should serve all needs that came up so far...

HanSolo commented 3 years ago

I've implemented a first version and deployed it to my own server. I've sent you the coordinates in a direct msg on foojay slack.

marchof commented 3 years ago

@HanSolo Thanks! Looks like foojay slack has been limited to a few domains and I'm not able any more to access it any more. You might send it via Twitter to @marcandsweep

geertjanw commented 3 years ago

https://join.slack.com/t/foojay/shared_invite/zt-ni5afow2-FcF7sMZYBnkng~TXQ781Nw

marchof commented 3 years ago

I had a quick look at the test deplyoment:

HanSolo commented 3 years ago

Right it was a single object before but I first implemented it in that way but then thought why not having the same schema for all endpoints. So it will always return a json array for the result and a string for the message. In the case of the packageId endpoint the array only contains just one entry. I've made some tests by converting 3 other projects that use disco to the new response format and found that it's much easier if all responses are in the same format...so what do you think?

marchof commented 3 years ago

Both is ok for me. What is the behavior if the is no package with the given id? Empty array or 404?

HanSolo commented 3 years ago

It will return an empty array and the message will contain something like "pkg not found"

HanSolo commented 3 years ago

Should be fixed now

marchof commented 3 years ago

Confirmed, syntax is correct now. Thanks!