I am using swagger(openapi) codegen to generate Rest Api Server Stub.
Is it possible to use the "spring" generator and somehow use Spring Rest converters ?
The problem is that before I had a simple
#GetMapping
public String (#RequestBody Locale locale)
Now with openapi codegen I have an ugly LocaleDto that has 50 fields and so on. And also I need to manually transform my object back to "Locale" with
LocaleUtils.from().
Relative docs:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen-maven-plugin/README.md
Any help is greatly appreciated.
Related
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
I know that we can have examples in the drop down menu for each parameter in the openapi spec. This requires to select each example for each parameter.
I was wondering if it is possible to have a drop down menu for the endpoint that we can select the example and that example has the values for all parameters in that endpoint.
This is not supported - neither by the OpenAPI Specification nor in Swagger UI. Here's an existing feature request in the OpenAPI Specification repository:
https://github.com/OAI/OpenAPI-Specification/issues/1673
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.
I tried swagger 3.2.2 by running a GET operation with few query params.
I find defaults values I set in REST API can't override in swagger UI. All the text boxes are read only, and drop-down of Boolean query param always sends 'false' though I select it to 'true'. It seems program default values are super hard-corded here. I was playing with swagger #ApiPram(..) to fix this but it didn't help me.
Did anyone ran in to the same issue I describe above with Swagger 3.x?
I start using Swagger UI 3.5.0 and fixed the issue
I know this question is been discussed many times but for me those solutions are not working. I want to return JSON data from my ASP.NET web API. I am hitting the end point using Firefox REST client plugin.
What I have tried:
I have specific accept header : Accept: application/json. Use accept header
Removed the XML formatter on Application_Start method
var formatters = GlobalConfiguration.Configuration.Formatters;
formatters.Remove(formatters.XmlFormatter);
This is how I return data at the end
return myModel.OrderBy(d => d.SortOrder);
Where myModel is just a class with few public property. I am not decorating this class or its property with any attribute.
But these two approach's are not working. I am still getting data in XML format :(
Please provide your suggestions.
I would like to introduce you to http://www.servicestack.net/
This is rest API framework that hooks up with .net.
It does everything what you require .
https://docs.google.com/presentation/d/16ey0MrpHOSz5N5sjctAliOgYWO3ZYeJe070fLZlPdrE/present#slide=id.i27
FROM COMMENT
Check that the application/json header is the first header and has a q=1 quality attribute: "application/json;q=1".
You can read more about quality attributes in the specs. Basically they are a way for a client of providing a preference system on the returned datatype.
To answer your other question (when I have explicitly removed the XML format in the code, why I was getting the data in XML format?), I can only guess what was going on: either the header was not setup correctly or the client was defaulting the other header to a different quality value.
Another guess could be that your way of removing the formatter is wrong: you can check this answer on SO or this article for alternative methods and see if they do the trick for you as well.