-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Different actions in the same resource should allow different parameters #40
Comments
Interesting. From my point of view it was just the way how Apiary renders it. You can already have a discussion of an URI (query) parameter on both resource and action level. This is also properly reflected in the parsed AST. So what a tool, such as Apiary, could already do is to display the information about the parameters only at the appropriate level. In the case of our Gists collection example it should be rendered in the documentation only for the List All Gists action. Also could you please be specific on what you mean by "and throws warnings for undefined parameters when using protagonist"? Now with all that it still might be good to have an explicit support for this in the format and your proposal might be the way to go. What I would love to see, however, is to come up with a format where you do not have to essentially declare a parameter in an URI Template and then later pick up on the declaration and define the rest. In other words I would love to completely skip the declarative part of it and build URI (or at least query) parameters by just specifying them in the Thoughts? |
In that case, should I open an issue on uservoice to address this?
Right, this is why I made the issue instead of assuming it was just an issue with Apiary. When I run tests with Dredd, I get these errors during the "runtime compilation" step.
This is from compiling the Gist Fox example above. I don't see these warnings when passing the blueprint to the snowcrash cli directly. So actually, this is just an issue with Dredd. It does some checks in Once again it seems I've made an issue on the wrong project!
Is there something that stops that being done right now? It seems like the format could easily support that:
It seems like that contains all the information needed to infer the parameters; so it should know that the two URIs are:
More complex examples seem like they would work as well:
which would generate:
Or am I missing something? I think that's a much better solution. It also stops you from documenting the parameters in different orders in different places. |
You can open it at http://support.apiary.io if you want to track it. However I will personally make sure this will get addressed in the new rendered documentation.
Yep the message looks like it comes from Dredd (cc: @netmilk). Many little projects. No worries.
Well you are pretty much right. The only thing that annoys me is there is still the need for an URI Templates (RFC 6570) in the case of So it would probably work for query parameters already. And maybe this is enough? But not sure how to do it completely without URI templates. One can surely nest consecutive parameters
But for the more complex examples e.g. |
I have just verified that new documentation rendered at Apiary from the following blueprint
will display parameters and its description only on the GET action. The logic is as follows (Cuke): Background:
Given a resource `R` with URI template parameter `X`
Given a resource `R` action `GET`
Given a resource `R` action `POST`
Scenario: Resource URI parameter desribed in resource
When I describe parameter `X` in the resource `R` section
I should see the parameter and description under action `GET` of resource `R`
And I should see the parameter and description under action `POST` of resource `R`
Scenario: Resource URI parameter desribed in one of resource actions
When I describe parameter `X` in the action `GET` section of resource `R`
I should see the parameter and description under action `GET` of resource `R`
And I should NOT see the parameter and description under action `POST` of resource `R`
When I describe parameter `X` in the action `POST` section of resource `R`
I should see the parameter and description under action `POST` of resource `R`
And I should NOT see the parameter and description under action `GET` of resource `R`
Scenario: Resource URI parameter not described at all
When I do NOT describe parameter `X` in ANY section of resource `R`
I should see the parameter and description under action `POST` of resource `R`
And I should see the parameter and description under action `GET` of resource `R` Please review this behavior and if OK close this issue (as not related to API Blueprint format but rather to its tooling). |
It looks like it doesn't display the parameter descriptions, but it does still display the parameters in the uri template: So it looks like those are options for a POST uri, when they're not...on the other hand, one could argue that this means that the POST uri is different and therefore needs a different URI Template without the query params at the end (which is what I'm currently doing). Also this needs to be updated in Dredd too, which will complain that the params don't have example values in the POST request. |
Sorry my bad I did make this clear: I was talking about upcoming (and long overdue) rendered documentation revamp (@Baggz is working on). The actual documentation won't be update and should be fully replaced by the new one soon.
Oh you are definitely right! I plan to elaborate on #21 API Blueprint Testing on Monday; Will post there our (in coop \w @netmilk) plans for complete API Blueprint testability including the preliminary scenarios support. But thinking about this maybe |
Ah, okay, gotcha. I'm interested in the testing plans. I had set aside some time today to write some basic before/after hooks for dredd tests, I might hold off on that to see what you guys have been thinking about. |
What's the status on this? Seems like it's been a while since the devs green-lit the concept, but attempting to implement it in API Blueprint doesn't seem to work. Is there an ETA on release? |
@jmrboosties Revamp on the product is rolling out (you can switch it on in Apiary's settings) and should be ready soon. ...if you are asking about the original issue and not about #21 . Any particular example of your use-case? ;) |
Hey @Almad, thanks for the help earlier on SO. The use-case I'm describing is one where we have a user resource which you can create, update, or get. They all share a resource model (the responses for each are the same) so they should all be declared under the same ##User [URI template] header. While you can simply place the update/create parameters inside their respective sections, the editor will throw a warning if it is not laid out in the URI, even if it is a PUT or POST request. Maybe I'm doing something wrong, but it doesn't really make sense to me to include parameters you'd find in the body of the request entity in the URI. Ideally, the GET request would have a URI like base/users/uid, and the PUT and POST requests would look like base/users/ with their respective parameters listed below in the params table. Does that make sense? Let me know if anything is worth making a different issue about, I'm happy to help give feedback. |
Hi, glad to help. Can you please post here a snippet of how you think things should look like? I think I have an idea, but just to be sure. I do believe this will be case for #47 , but let's see. |
Here is an example of what I was doing. As you can see in the GET request, for organization i was breaking the parameters into 3 groups (this is based on the issue we discussed earlier on SO). As you know our usage is kind of complicated for the GET, but that's not really the issue here so let's just assume its a normal GET request. So in the GET, the parameters you would see in the actual URI (/user/uid?param1=true¶m2=value) as the path next to the grey GET box. For PUT however, you'd just want the main part of the URI, since there are no params following a ? symbol. Next to PUT should just be /user/uid, followed by all the expected params in the put body below (I threw in location in there as an example). Ideally this wouldn't throw any errors or warnings, right now including location (which will never be part of the path or a GET parameter) gives a "There is a semantic issue at line X" warning in the editor. Does this clarify? Thanks for helping. |
@jmrboosties Let me just jump in. Please try switching on New Documentation (Settings > Beta Area > New Documentation).—More details are in our blog post. |
This issue has already been addressed in Apiary. The logic conforms to the cuke from my previous comment. As there are no actions needed on the API Blueprint side I am closing this issue. Feel free to continue in this discussion here should you have a question. Please see this example: http://docs.queryparameters.apiary.io which is extended version of current Apiary default blueprint:
As you can see And not of the |
Hm yea, looks like it works in the Documentation section of the site, but not the preview section. Also, the editor still throws a warning when you declare a parameter not explicitly mentioned in the URI template. This isn't a huge deal, but it'd be nice if it were fixed in a future version. Thanks! |
Can you please elaborate on this? Why would you document an URI parameter that is not in the URI? |
Not a URI parameter, a parameter for the POST/PUT body. For instance, This is a put request for updating a user. The URI is showing all of the GET parameters, rather than what an actual PUT request would look like (in this example, https://bandsintownfan.apiary-mock.com/users/user_id). Here is the blueprint code:
In this example, all I want the PUT request to do is be able to change the user's location. I declared that parameter in the PUT section of the user resource, but not in the URI, because location will never be part of the URI. Does that make sense? Basically parameters inside the POST/PUT bodies of a request should be able to be declared as a required or optional parameter without having to be part of the URI. Also, in POST/PUT requests it would be nice if the URI didn't include GET style parameters. Someone suggested earlier being able to declare URIs per request type, so instead of having the URI next to the user resource, you could place it next to the [GET] [POST] requests and so on. This would allow your GET requests to contain all the parameters it would require, and just have the necessary path for others. |
A parameter needs to be present in URI template in order to be discussed later. Further more I believe your template is not written correctly and it should be (with or without
Now question is which (query) parameter belongs to what action. Let's break it down:
|
(rant on RFC6570): I find the URI template RFC very complex and thus error-prone; if anyone have a better idea I am willing to hear it! |
@zdne I don't like the way of declaring all query parameters for the resource and then only using some of them, like you posted above:
How about just to declare uri and then re-declare query parameters for each action like this (or some similar syntax):
|
Well I would rather draft away from RFC6570 more or less. Adding parts of this RFC here and there would IMO make the blueprint confusing even for those who understands it. What we could do is to omit query parameters completely from URI template and assume that when a parameter that is not in the template is discussed then it is a query parameter specific to the point of discussion. Picking on @jmrboosties example:
However I am not sure if this would add clarity or not. Thoughts? |
@zdne Definitely not. Maybe by making all sections separate.
Also can I track this bug somewhere?
|
Good question! Currently we do not have anything else but the "ideas" board |
Sorry, I'm in California so I'm always missing out on these conversations while they're happening. I understand that the current system has you declare all parameters in the URI, and then explain them under the request type (GET, POST, etc) where they will be used. The issue I'm raising is this: going back to our user example I posted earlier, the "correct" way of doing it is this:
Even though location will only be used in the PUT, you declare it as part of the URI. That alone is fine I guess, but the problem arises when you view the documentation and it looks like this: Even though auth, mobile and template are the only parameters you will use in a GET, location shows up there as well. It'd be nice for location NOT to appear there, since it will never be used in a GET request. In this example, having 1 extra unused parameter is something which can be overlooked, but at least for my case, the final implementation of the Users resource's PUT request has dozens of parameters which it can take, which would result in a really cluttered GET URL template. Also, in the PUT request, all of the parameters are included in the sample URL template, even though you won't be using any after a ? at all: What I would like to see here is for the PUT URL template to just have:
If that goes against what you guys are hoping to achieve with the project I understand, just trying to clarify exactly what my suggestions are. Thanks for being responsive on this issue. |
No worries; we all scattered around the world so whenever you can chime in its fine.
I believe you mean:
Correct? Other than that what you suggest is the plan. As per my previous comment this is already possible in a simple example like the one from that comment. More complex situations (like the one from your example) will be supported. Also note that the spaces between variables are superfluous as per RFC6570 (again I do not like it on this one) thus:
Should really be:
Update: The question mark |
Yes, sorry about that issue with the ?. We were playing around with something and that was just a leftover typo from that.
For this part, I actually do mean just the following:
In this basic example, location is a parameter, but it is a PUT parameter and is going to be included as part of the request body (in a JSON object) rather than in the URI itself. So even though Also, I tried moving some parameter declarations around in the editor to mimic what you were doing in the comment you referenced. When I move parameters from the resource section (##) to the request section (###), they still all appear in all of the URIs for both GET and PUT. I'll provide the code and screens below:
Here is what I get in the GET section of the documentation: My screen isn't big enough to show all the rows in the Parameters section, but I can just tell you that it accurately includes just Any thoughts? |
Ah understand now. I can see where is the confusion here - the I am actually working on a dedicated syntax for discussing payload fields as part of this milestone here: #25 As for your other remark (on problems when shuffling parameters around) – this is a bug in Apiary and should be fixed there. |
Its October now and this still doesn't seem to work (in the beta doc feature). If i specify On any actions specified I include a parameters section the entire set of parameters is included in the resource uri. So if i just have:
The uri of the action is shown as Interestingly for my POST which specifies no parameters the url is printed as This would be my biggest (only?) gripe with this tool. It basically means the docs output are just wrong |
Sorry for the troubles! I'm working on it as we speak; we should be able to deploy a fix by the end |
Cheers mate, appreciate it |
The fix has been deployed. Could you please give it a try and let me know if everything works as expected? Thanks a lot! |
@Baggz Hello and thank you! I'm having the same issue, not sure if it's because I have a free account right now and maybe that fix didn't get there. |
@esbanarango Hello, we'll be sunsetting this version of documentation, the new one (http://blog.apiary.io/2014/03/21/Re-API-Design-for-Humans/) already solves this issue. The way how to switch the new version on is at the end of the blog post. |
Consider the example from the Gist API:
Since the POST description is under the collection
/gists{?since}
, it implies that there is a parameter for the post request that doesn't actually exist. This is parsed weirdly on apiary:, and throws warnings for undefined parameters when using protagonist.
I think a simple solution would be to simply allow overriding the URI further down the tree. Something like this:
The text was updated successfully, but these errors were encountered: