Cannot use REST comments in Swagger - rest

I have downloaded swagger ui and experimenting it locally. It works fine in scenarios like "path", "body" , and "query" . But most of my use cases use rest comments.
i.e /resourcePath/;tags
URI to retrieve the tags of a specific resource.
When I try this the the UI gets jumbled when adding the semi colon and malformed the sorted UI and cannot go beyond this.
So is this a known limitation ? Is there a workaround to accomplish this target ?
Appreciate any input to this..

Swagger is expecting you to specify path params in curly-brackets like {tags} and query params as comma-delimited, such as id=1,2,3,4. Some frameworks use semi-colons as delimiters but swagger likes commas.
Can you describe more what you're looking to do, with a more concrete example? Per design, comments on the api belong in the description and notes fields for operations, please see swagger-core wiki for details.
The Swagger codegen project has a validator which can be used to verify that your spec is properly formatted.

Related

authlib: some client_kwargs in config are not used

Love authlib overall. Question about client_kwargs described in
https://docs.authlib.org/en/latest/client/frameworks.html
and https://docs.authlib.org/en/latest/client/django.html
Problem statement: I tried to pass "scope" and "audience" key/value pairs in the client_kwargs dict, but only "scope" key/value is used for generating URI for authorization.
I need to pass "audience" for Atlassian OAuth2.0 https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/
Workaround found after some tinkering by passing "audience"="api.atlassian.com" to oauth.atlassian.authorize_redirect.
Question: Is client_kwargs in oauth.register/AUTHLIB_OAUTH_CLIENTS intended only for certain keyword arguments? If so, would be great to share it in the documentation; otherwise it would be convenient to set it in config together with everything else.
This behavior was found in 0.12.1 and 0.13.dev0.
Thanks!
Because OAuth 1.0 and OAuth 2.0 are different, this client_kwargs are designed to pass extra parameters to either OAuth1Client/OAuth1Session or OAuth2Client/OAuth2Session.
For your case, there is a authorize_params. You can put audience in your authorize_params:
oauth.register(
....
authorize_params={'audience': '...'},
....
)

SharePoint REST: Field or property does not exist

I'm using REST to get data from a SharePoint library to display using the DataTables jQuery API. Everything is working fine, but I've got one stubborn field in this library that REST isn't able to grab.
The name of the field is "For", but the internal name is _x0046_or1 (not sure why, I didn't create the library). I've double-checked that this is the correct internal name using REST and by checking the code for my library view in Designer.
So using my REST call:
/_api/Web/Lists/GetByTitle('SAS2')/items?$select=_x0046_or1&$top=5000
And I get back:
The field or property '_x0046_or1' does not exist.
Anybody have any suggestions for a different way to reference this field that the REST api might recognize?
I did as Rohit suggested in the comments, and made the REST call without the select. It turns out that the actual internal name of the For field was "OData__x0046_or1". No idea why.
Thanks for the helpful suggestion, Rohit!
In SharePoint 2013 if you name a field with 3 or less chars and then end it with a number, SP will rename the internal name.

Why does one HTTP GET request retrieve the required data and another retrieve []

I'm currently working on ng-admin.
I'm having a problem retrieving user data from my REST API (connected to a MongoDB) and displaying it.
I have identified the problem as the following:
When I enter http://localhost:3000/users into my browser, I get a list of all users in my database.
When I enter http://localhost:3000/users?_page=1&_perPage=30&_sortDir=DESC&_sortField=id,
I get [] as a result.
I am quite new to this, I used both my browser and the POSTMAN Chrome extension to test this and get the same result.
http://localhost:3000/users_end=30&_order=DESC&_sort=id&_start=0
This (/users_end) is a different request than /users.
It should be:
http://localhost:3000/users?end=30&_order=DESC&_sort=id&_start=0
Or, by looking at the other parameters:
http://localhost:3000/users?_end=30&_order=DESC&_sort=id&_start=0
with end or _end being the first parameter (mark the ?).
Update (it is ? and before the _, I have edited.):
If adding parameters to the request returns an empty list, try adding only one at a time to narrow down the problem (there's probably an error in the usage of those parameters - are you sure you need those underscores?).
Your REST API must have a way to handle pagination, sorting, and filtering. But ng-admin cannot determine exactly how, because REST is a style and not a standard. So ng-admin makes assumptions about how your API does that by default, that's why it adds these _end and _sort query parameters.
In order to transform these parameters into those that your API understands, you'll have to add an interceptor. This is all thoroughly explained in the ng-admin documentation: http://ng-admin-book.marmelab.com/doc/API-mapping.html

How can I get multiple %-encoded parameters into an apiary URI template?

The ApiaryIO spec—actually the RFC to which it points—indicates that you cannot use "." in a parameter name, you need to encode it to "%2E". That's fine, but there seems to be a bug where Apiary can only handle one such encoding. For example, the following
## Notes Collection [/notes{?foo%2Ebar}]
yields the following Code Example
request = Request('http://private-d1ee7-testingnewapiary.apiary-mock.com/notes?foo.bar=foo.bar')
which is correct. However, the following
## Notes Collection [/notes{?foo%2Ebar,baz%2Ebla}]
yields this Code Example:
request = Request('http://private-d1ee7-testingnewapiary.apiary-mock.com/notes?foo%252Ebar=foo%252Ebar&baz%252Ebla=baz%252Ebla')
Notice how in the first the Code Example you see it has "foo.bar" but in the second example it has "foo%252Ebar", which is incorrect.
The downstream effect here is that the incorrect URI is sent to the API server so the response is malformatted creating an error.
How do I encode many "."-containing parameters on the URI template and still get the proper code examples?
Will adding explicit example values for those parameters help?
For example:
## Notes Collection [/notes{?foo%2Ebar,baz%2Ebla}]
+ Parameters
+ foo%2Ebar (`42`)
+ baz%2Ebla (`24`)
Update
This seems to be a bug in the way the documentation / code samples are rendered. I have created the tracking issue here https://github.com/apiaryio/language-templates/issues/36.

Play Framework: How to bind a complex REST request to a Controller method

Working on a REST API with Play Framework.
I have a requirement to support a RESTful request containing the "order" with multiple "line items".
In terms of the "POST data", I see it like: (split into multi-lines for clarity)
OrderId=123&OrderType=regular&
ItemNum=1&ItemID=78&quantity=2&discount=20&
ItemNum=2&ItemID=70&quantity=1&
ItemNum=3&ItemID=75&quantity=1&discount=10
Note that I have an issue to require all the "line items" to come with a full set of data. In the example above, the 2nd item has no discount. Since I cannot "force" developers using the API to work with my own "wrapper", I want to leave some flexibility.
I would like to map it to something like:
method(int orderID, string orderType, Item[] items)
However, I failed to find something appropriate in the docs.
What's the right way?
Should I build my own parser of the HTTP request data?
Any alternative way to format the POST data - as long as it is ok with REST guidelines - is also acceptable.
Thanks
Max
To map an array of Pojo objects, then you need to put item. in front of the item object. Just like you map an object in a form. Then, you should specify that it is an array using the standard array syntax.
I would do something like the following
orderId=123&orderType=regular&
item[0].ItemNum=1&item[0].ItemID=78&item[0].quantity=2&item[0].discount=20&
item[1].ItemNum=2&item[1].ItemID=70&item[1].quantity=1&
item[2].ItemNum=3&item[2].ItemID=75&item[2].quantity=1&item[2].discount=10