My requirement is to generate a Swagger File for a given ReST API URL. I have invoked the URLs using POSTMAN client and it was working fine.
However, for this URL to use in Informatica cloud, it's required to have associated Swagger file either json or yaml format.
could you please guide how we can do this?
Related
I'm working on a project in which I'm required to add swagger annotations to endpoints in a postman collection in a JSON file on GitHub. I'm a beginner in API documentation and I've not sure how to go about this. Any suggestions?
I am currently using identityserver middleware in my project to implement an oauth service. I would like to use swagger to define some of the methods available in this middleware such as /Connect/Token which is used to acquire and access token.
Unfortunately since this is middleware I do not have implementations of controllers that handle the http requests - since the requests are handled in the middleware.
Is it possible to explicitly define upfront a swaggerdoc with all the endpoint information (such as url, params etc) if you are using a middleware that handles all http requests?
I was unable to find a method for dynamically generating swagger documentation for the identityserver endpoints.
However as a workaround I created a manual swagger.json file using the swagger editor. I was able to export a swagger.json file from the editor. I added the file to my application and was able generate the swagger ui with the following code.
// serve static files
app.UseStaticFiles();
// id server middleware
app.UseIdentityServer();
// points to my static swagger.json file
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger.json", "My API");
});
I am building out an OpenAPI support for my project but I need swagger.yaml file to be available only to authorized users.
Swagger UI and Swagger Editor both seem to expect the swagger.yaml file to be accessible publicly.
I've thought of various ways of getting around it. One could be using "signed" URLs, similar to how S3 does it -- this way only people with a link can access it.
What is a good practice ?
I figured it out. On the Swagger-UI github page there is a description of the authorizations parameter that can be set in index.html:
An authorization object to be passed to swagger-js. Setting it here will trigger inclusion of any authorization or custom signing logic when fetching the swagger description file. Note the object structure should be { key: AuthorizationObject }
What I've done was setup a Node.js server that protects Swagger-UI. If the token is not set in cookies, it directs the user through the OAuth 2.0 flow, sets the cookie, and only then directs to swagger-ui.
Swagger-ui in turn has authorizations parameter set as follows:
authorizations: {
"_auth": new SwaggerClient.ApiKeyAuthorization(
"Authorization", "Bearer "+ Cookies.get("MyAccessToken"),
"header")
}
The header is then passed to the the server when downloading swagger.yaml file.
I've developed a REST API anotated with Swagger annotations.
I've been able to show the api documentation on a swagger-ui application, very nice.
The problem:
I'm trying to generate clients acording this specification using the url provided by swagger acording my anotations.
The porblem is it seems to be imcompatible, or at least, I don't see how to do the swagger editor reads my url and from then on, generate clients. But swagger editor reports me about some errors...
It's possible to integrate my anotated swagger api with a swagger editor?
Thanks.
The question seems a bit confusing.
If you are trying to generate clients from your REST API Swagger spec, then you should take a look to Swagger-Codegen project.
Description of project:
swagger-codegen contains a template-driven engine to generate client code in different languages by parsing your Swagger Resource Declaration.
Link to repository: https://github.com/swagger-api/swagger-codegen/
Link to official page: http://swagger.io/swagger-codegen/
Not sure if I understand the question correctly. If you want to generate API clients online, you an use http://generator.swagger.io (besides http://editor.swagger.io). Here is an example to generate API client for Java:
curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/clients/java
Swagger editor is used only for editing a swagger spec in either json or yml format. It does not deal with swagger annotations in any way. However, some of the server skeletons that are generated on the swagger-editor website contain annotations. The annotations are a way of reverse engineering your API to generate a json file so that swagger UI can render a webpage based on the public url path to your swagger.json file.
If you are maintaining a swagger spec json file anyways, the annotations aren't really needed, you might as well just serve up the raw swagger.json itself, rather than the json that is generated by the annotations.
As to your question, "Is it possible to integrate your API with swagger editor?"... Anything is possible, but I'm not sure as to how or why you want to integrate them.
I have a Dropwizard application with Swagger annotated Java resource classes. I'm also creating programatic REST resources which, of course, don't end up in the generated Swagger JSON. Is it possible to programmatically add operations via the Java Swagger API such that they end up in the generated JSON along with the annotated resources?
I tried using DefaultJaxrsApiReader.appendOperation but it had no effect.
I'm using com.wordnik:swagger-jaxrs_2.10:1.3.12
EDIT
I ended up just writing a Servlet filter to update the Swagger JSON response. It would be great to get #fehguy's suggestions working somehow. I think that swagger-jaxrs_2.10:1.3.12 isn't new enough to support those POJOs.
as of swagger-core-1.5.1-M1, you can build a swagger POJO which simply needs to be returned by your web application. That means, you can programmatically create the Swagger object and serve it up as JSON from your web service.
For examples of how to build a swagger pojo you can look at the source or an example (test) of building one.
You can also mutate the generated swagger object in your application. That means you can dynamically generate / modify swagger at runtime. There is an example in the swagger-codegen project, where the online code generator (swagger-generator) will detect what languages are enabled in the code generation logic via SPI, and update the swagger spec accordingly with the options:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-generator/src/main/java/com/wordnik/swagger/generator/DynamicSwaggerConfig.java