-
Notifications
You must be signed in to change notification settings - Fork 172
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
issues with rel=empty #169
Comments
Perhaps we should leave the existing one for backwards-compatibility, but add Or perhaps this just illustrates that we are stretching the meaning of rel a bit too much and we should consider using a different attribute/mechanism here? |
@geemus +1 man. I personally feel like we're pushing I almost feel like something like I think that we could even punt on |
@brandur yeah, rel create as one of those makes sense. The difficulty comes in generating examples, ie what should a curl create example show as the response code? Similarly, what should arbitrary actions show? Maybe we should go back toward just using the defined rels (instance/instances/etc) and lean more heavily on targetSchema? I guess I'm not exactly sure how to define an empty schema either though. Perhaps we should just be explicit in a way akin to excon, ie on different actions we could enumerate expected response codes. 200 is perhaps then just implied, but you can override with other possibilities. I guess if you have a list though you return to the problem of which to choose for usage in examples though. |
@geemus Ah, I see! +1 on an Excon-style method to specify response status codes for links. I think we should always make sure to keep it optional (and have consuming libraries be generous about what they allow if no status is specified) because it's not really part of any particular spec, but I feel like this would be useful in a number of different situations including this one.
An empty schema is easy, but it corresponds to a "{}" rather than a "". We may need something like 'no-content' in addition to that. |
Maybe empty is simply the absence of a target schema then? |
The other option might be |
@geemus Ah, interesting. I'm not sure I could speak to validity one way or On Thu, Oct 9, 2014 at 12:54 PM, Wesley Beary notifications@github.com
|
Good point. I think we are trying to add too much meaning to things that already have meaning. Separating out status (and probably eventually headers) seems more like what we need. Unfortunately I don't see much precedent for us there, so we may have to trail blaze a bit. |
@brandur @geemus I think the right option would be I sent a Pull Request for schematics today to rely on It actually aligns schematic's library more with documentation generated by prmd. You can find some details here ernesto-jimenez/schematic@3b605c5 |
@ernesto-jimenez Ah, good call! And OMG, +1 million that Schematic pull request! Thanks! With regards to |
@brandur relying on e.g: In Schematic unmarshals content into structs and the TargetSchema property would be nil when the property is null and when it is undefined. If we don't rely on |
@ernesto-jimenez Ah right. I just meant to say that What about something like |
@brandur, I would interpret that as replying with an empty string serialized in JSON. e.g:
Rather than:
I understand that |
@ernesto-jimenez That's what it is though isn't it? The response body is always a string, even if its |
@brandur In my opinion, when I define a targetSchema, I'm defining the schema of the returned JSON. In your examples, that's equivalent to `"" If the target schema were In my opinion, I would be more surprised by having to define an empty response with a type string + conditions than with a type null. I understand we are twisting semantics in both cases, but I personally find the string+condition more strange. If we are willing to assume |
@brandur btw, I just sent an email to the spec authors in case they want to comment about this and asking what's the status of the spec, since we are obviously discussing a hacky workaround and it would be better to have a nicer solution in the spec. |
@ernesto-jimenez Ah, when I said Let us know what you find out from the spec authors though! |
Hi people. :) Sorry for the slow (and long) response. I'm afraid I'm missing some context about the kind of situation for which you're returning The JSON (Hyper-)Schema standard as it stands doesn't describe HTTP status codes, HTTP headers, et cetera. It describes documents (and their hypermedia environment) when they are provided, so it doesn't really have anything to say when you don't have a document at all. In the absence of such status-code or header information, I'd expect clients to be on their toes, ready to handle any reasonable response. As your rather excellent API design manifesto describes, the set of expected successful response codes is pretty limited for a given HTTP verb, so much of the dynamic behaviour will be error-handling. (Although I did notice when reading your design guide that We could (or you could, and push it back - the standard is deliberately extensible) add an extension to the Link Description Objects that listed expected JSON responses. However, describing all the known error states is possibly not appropriate for every interaction - plus clients should at least keep breathing after encountering a Something like Another angle could be to think about The one that looks best to me, though is @ernesto-jimenez's suggestion TL;DR: the best suggestion from my POV is |
@geraintluff thanks for your reply! Here's some context about when this would be important: Generating libraries
Some API's return empty responses in certain endpoints (e.g: when deleting a resource). However, when generating the code to access those endpoints, we are missing being able to specify in JSON Schema that those endpoints never return a resource. Without that information, we would always define methods like these in those situations: // resource would allways be empty, so returning it is just noise
func (s *Service) DeleteResource(id string) resource, error My work around was to using // no resource returned by the method, since the endpoint doesn't return a resource
func (s *Service) DeleteResource(id string) error Generating documentation
The documentation includes examples of API request and responses using We need a way in JSON schema to define those endpoints would respond with an empty body and render the appropriate TL;DR: the issue is when generating code or documentation, since we need to specify in JSON-Schema that link would not return any resource in order to generate the appropriate code/docs. |
@geraintluff thanks for weighing in and glad you like the guide! A lot of the questions posed here have to do with those cases which do not match with the guide (for better or worse). ie non-greenfield stuff and/or exceptional cases. We tried to design the guide such that it did not have such exceptions (because it is more useful when broadly applicable). I still think that in many cases the right solution may be to NOT use a 204, especially when it is just for a single resource where others are non-204, but sometimes this is hard. At the end of the day, the biggest place this has become apparent is in documentation generation, as @ernesto-jimenez mentions. Although clients should, where possible, be resilient in what they accept/allow (made harder when clients are being generated), having a solid/accurate example is pretty valuable and it seems like being able to generate them from the schema should be sufficient (and it usually is). As you allude to, I suspect we are pushing at the limits of what json-schema specifies, so an extension of some sort may better serve our purposes than trying to overload existing things. |
Also for context: I think that many supporting libraries that bring JSON Schema and HTTP together are going to run into similar problems. For example, we're looking at finding a good path for this to get interagent/committee#58 resolved as well. Cool! The @ernesto-jimenez Thanks for helping shepherd this through! |
nudging @geraintluff about @brandur's comment back in December :) |
What I meant with My belief is just that clients should be flexible. If a client is expecting So yeah, I don't see an issue here. |
Sorry if this is a dumb idea - but ... is there a way to override the response status code currently? If not - would it be possible to add this to the schema, and then we could imply an empty response from it? E.g.
In which case an empty |
There isn't a direct means within json schema to specify anything about status codes (or headers) for that matter. I think it would be really helpful if this were not the case (and json-schema is extensible). I've had a sense that trying to define ways to specify this stuff more formally would be really valuable, but I keep not-quite managing to get it done. By leaning on a small set of codes as best-practice we are able to mostly avoid the issue, but obviously there end up being some outliers (such as this). |
This problem hit me. I was really expecting rel: empty # 202 Accepted (backwards compatibility, Maybe(deprecated))
rel: no-content # 204 No content
rel: asynchronous # 202 Accepted (encouraged to use) I am up for creating a PR for that. WDYT @geemus ? |
@waterlink I like the proposal, would be great to have control like this over the status code. |
Sounds reasonable. That said, I wonder if we should stop burying this inside rel (ie maybe we should just add some attribute that lists the expected status code or codes). What do you think? |
status:
- 201
- 404 Something along these lines? |
That is almost the same thing, that @michaelsauter proposed in his comment: #169 (comment) |
Yeah, probably. My concern just becomes, how do you know which value makes sense to use in examples? Maybe just by convention (the first one) or maybe some other attribute to make it explicit. What do you think? |
We can live it as simple as possible and just pick the first one. Other way would be trying to guess which one is successful, e.g.:
Other way would be to be explicit about it. If you provide more than one value, then you have to specify which would be used for an example: http_status: 200
# Ok, example will show `200 OK` http_status:
- 200
- 201
- 404
# Schema validation will fail, requiring you to provide `default_http_status` http_status:
- 200
- 201
- 404
default_http_status: 201
# Ok, example will show `201 Created` Or, make http_status:
items:
- 200
- 201
- 404
default: 201
# Ok, example will show `201 Created` @geemus WDYT? Which would you prefer? |
I think convention (first one) is good enough. All other suggestions are more verbose/complicated, and do not offer more flexibility ... |
Yeah, I think an array, assuming the first one is default, would be good enough. Thanks for discussing! |
Hi! We are facing a problem that seems kinda related with this one. We wanted to return a
But if we do that we always end up in this line:
JSON.pretty_generate( .
Are we approaching this the proper way? Or is there a better way to do it? Sorry if it doesn't exactly belongs here, but it looked like. |
@agonzalezro unfortunately, JSON Hyper Schema only pertains to the JSON representation of REST sources and the links where to fetch or act on those resources. It's missing any information regarding the HTTP transport, such as Authentication or HTTP Status codes.
|
thanks for the response @ernesto-jimenez, then is this #169 (comment) something that it's planned to be implemented in |
@Victorcoder, I don't maintain What I know is that the JSON Hyper-Schema spec doesn't cover that and has not been updated since 2013. Even if it's implemented, other JSON Hyper Schema tools will not support it. Depending on what you want to accomplish: generate docs for an existing API, generate docs and clients, define a new API... It might be enough to contribute/wait for some support from If you are working on designing a new API, you can also take a look at JSON-API, which does specify the transport. It's missing a way to define resources' and API schemas, but it can be extended, so you could leverage JSON Schema. Also, on Jan 1st Swagger contributed their Swagger 2.0 spec to the Open API Initiative as a starting point to standardise a spec under the umbrella of the Linux Foundation. I'm unaware whether they have a commitment to make the OAS (Open API Specification) backwards compatible. Finally, you can also check what Google did with their API Discovery Service to see how they defines their APIs with custom JSON format which leverages JSON Schema. They use id to generate docs and clients. |
Agreed, json-schema doesn't fully cover things. There are definitely some other formats that have varying levels of coverage/support as @ernesto-jimenez suggests. It's a pretty rapidly evolving/improving ecosystem, so definitely worth checking out whats going on and choosing the one that is the best fit. The changes to support status/headers we proposed in those comments would be our own extensions to json-schema, so it would just work in prmd (that may or may not be sufficient for you, depending on what you are up to). |
I realized today that we are probably using empty a bit innacurately. We use it to mean 202, when really (arguably) it would better describe 204. In fact, I suspect we might really want another value, something like
asynchronous
to better call out this kind of case. Thoughts?The text was updated successfully, but these errors were encountered: