New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return JSON for all API routes #2850
Conversation
804c5e8
to
cf6f32f
Compare
cf6f32f
to
a63f3a0
Compare
So I filed the issue but I'm not 100% sure this is the 'right' fix. It kinda depends on the intent of the API. Is it mainly intended just to deliver the data, or is the YAML representation of the data important? If the YAML representation is important, this may not be the right fix, it may be more appropriate to either intentionally fail if asked for JSON (with an error text telling the client the data's only available as YAML) or simply return the YAML representation wrapped in JSON (a single-item JSON dict with the value as the entire YAML representation as a string, or something...) |
I thought about that, but that would mean that the output has a different meaning depending on the content-type, and I don't like that. IMHO, the result of an API call should always be the same, regardless if it is represented as YAML or JSON. If you want to get the exact YAML template, you need to set the Accept header to If we wrapped the YAML string in quotes for JSON, then we should also wrap it in a YAML string. |
Codecov Report
@@ Coverage Diff @@
## master #2850 +/- ##
==========================================
+ Coverage 93.07% 93.08% +<.01%
==========================================
Files 190 190
Lines 11890 11897 +7
==========================================
+ Hits 11067 11074 +7
Misses 823 823
Continue to review full report at Codecov.
|
With this change, from what I can see, you get the following:
So this is a breaking change because the default is not the same. And the meaning of the new default is very different - you can't post the JSON without information loss. The client changes also reflect that - you can choose from two formats, one of which we don't support.
The API gives you YAML by default right now. So that would unfortunately break things. If your goal is consistency with other routes which already return JSON the result should be JSON wrapping the verbatim YAML document, in both the single and multi case, if the request asks for JSON. And we consider the other one deprecated and stop recommending its use. |
Ok, @kalikiana and I talked about this, and decided that we'll go with his suggestion to deprecate the For backwards compatibility we still have to support it, so the new behaviour depending on the Accept header would be:
That means that all API clients should always request JSON from now on to get consistent results. There is one possibly breaking change necessary: OpenQA::Client always sends Since there is a new client in development, we probably are ok to do this change for the old one, and the new client will implement and document this from the beginning. |
Would it be ok in your opinion to just return a string with the encoded template, instead of a list or an object? |
a63f3a0
to
e67b02f
Compare
if a JSON validator says it's good, sounds fine to me :) |
e67b02f
to
c42ae22
Compare
please squash wip commits and rebase |
This commit changes the response of the job_templates_scheduling endpoint, if Accept: application/json was requested explicitly, it will return the job template YAML encoded in a JSON string. With an unspecific request header (or explicitly text/yaml) it will return YAML as before. OpenQA::UserAgent allows overriding the Accept header now. The command line client can deal with different combinations of response type and output options. Issue: https://progress.opensuse.org/issues/64496
30db155
to
c9bf515
Compare
squashed and rebased |
This commit changes the response of the
job_templates_scheduling
endpoint,if
Accept: application/json
was requested explicitly, it will return thejob template YAML encoded in a JSON string.
With an unspecific request header (or explicitly text/yaml) it will return
YAML as before.
OpenQA::UserAgent allows overriding the Accept header now.
The command line client can deal with different combinations of response type
and output options.
Issue: https://progress.opensuse.org/issues/64496
I did not add tests for the new
script/client
options. Any hints on how to test that appreciated.