I added OData to my .NET Web API. I only use it for querying data (HttpMethod GET).
When I run my application, and I look at Swagger I see the following:
As you can see, the OData endpoints use uppercase name for the resource set which I something I really dislike. It's important to note that the endpoints work fine even in lowercase.
How can I make it so that the OData endpoints use lowercase by default to create consistency in my swagger documentation?
Thanks in advance
Use:
services.AddRouting(options => options.LowercaseUrls = true);
In your startup.cs
Related
I set up a basic JHipster project and generated an entity that supports filtering with JDL.
The generator made a Swagger API which I use for querying the database.
The Swagger API doc shows me a list of parameters which can be used to build query.
The template query looks like this:
GET /api/client?name.equals=john&surname.equals=doe&country.in=uk&country.in=de
The request works fine but the parameters are chained like name==john OR surname==doe OR country==uk OR country==de so I get all johns, does, and everoyne from uk and de.
This is ok, but for some queries i need name==john AND surname==doe so not all Johns and Does but specifically John Doe. I searched here and on the swagger forum but couldn't find the answer.
My question is: how do I achieve changing the OR to AND in the query?
Does this swagger query support AND or do I have to make changes in the backend?
Your question is not about swagger, this is why you could not find anything in swagger forum.
It's about JHipster JPA entity filtering and the answer is no: you can't generate code that would use a OR.
You must code it yourself, look at the *QueryService classes and assemble your criteria with the logic you need.
While trying to access the above odatav4 link with $apply query it shows an error as
"The query parameter '$apply' begins with a system-reserved '$' character but is not recognized."
but works if (apply) used instead of ("$apply")
https://services.odata.org/V4/Northwind/Northwind.svc/Products/?$apply=groupby((UnitsInStock))&$count=true&$top=1000
service link
I can't find the reason why the $apply is not working, since it was working previously
That service is an older implementation of WCF Services that is only partially compliant with OData v4 query syntax and as such does not support $apply.
but works if (apply) used instead of ("$apply")
You will notice that although there is no error, the query is returning the same results as if you had not included the $apply query option at all.
Your query syntax should work on a properly compliant API though, for instance you can use the TripPin service:
this query itself is not very useful, but it demonstrates the syntax
https://services.odata.org/TripPinRESTierService/People?$apply=groupby((LastName))
I am using swagger (nswag) in my ASP.NET CORE API project. I have situations which I would like my api call to be something like /api/users/{userIds} aka /api/users/1,2,3 that returns a list of users with the ids 1, 2, or 3.
What I'm finding is that when I make the request using swagger, the Request URL is /api/users/1%2C2%2C3 and if I make the request /api/users/1,2,3 (not using swagger), the endpoint cannot be found.
How do I change my configurations to be able to use a comma separated parameter?
There was a change "3.2.10 Pruned: URI Literal suffixes for numeric types" in OData v4 specification. Now OData.Client for OData v4 sends double literals without these sfuffixes, but we need them for our proejct to work correctly. I can't find a legal way to turn back this OData v3 behaviour, except brancing OData.Client. Does anybody know a way to change this behaviour using the generated T4 client proxies or something?
It can't fallback to old numeric format (with suffix) . You may consider hooking up DataServiceContext's SendingRequest2 event, modify the request URL to meet the server side's expectation.
However, the server side should have numeric value's type information (either in model or in CLR types) just like client has for building the request, so theoretically, suffix is unnecessary.
I'd like to be able to change the extension of a url and recieve the model in a different format.
e.g. if
/products/list
returns a html page containing a list of products, then
/products/list.json
would return them in a json list.
Note: I like the simplicity of the ASP.NET MVC REST SDK, it only requires about 5 lines of code to hook it in, but the format is specified as a query string parameter i.e. /products/list?format=json which is not what I want, I could tweak this code if there are no other options, but I don't want to reinvent the wheel!
I wrote a blog post that shows one possible example. It's a tiny bit complicated, but might work for your needs.
http://haacked.com/archive/2009/01/06/handling-formats-based-on-url-extension.aspx
You should be able to just use routes in conjunction with the rest sdk
If you have the flexibility to drop Apache or something similar in front of your service, you can always use mod_rewrite to rewrite an external http://products/list.json into http://products/list?format=json which your framework can render more easily.
Instead of "list.json", you could choose "list/json" and use a route like
{controller}/{action}/{id}
Then ProductController.List would be called, with an ID parameter of "json". The .List() action then would decide whether or not to return an HTML view or JSON content.