Generate swagger-api with existing vert.x project - web-services

I have an existing vert.x project which became too heavyweight and intransparent.*
To replace it I am checking for several options, one of those being swagger.
Does anyone know an opensource lib which can create a swagger-api from vert.x?

I'm not aware of something like that. The only vertx-swagger integration does exactly the opposite: generates Vertx router based on Swagger configuration:
https://github.com/phiz71/vertx-swagger
What you can do is generate all routes using this solution: List all registered routes in Vertx
Then add them manually to Swagger Editor, and finally generate your new APIs with Swagger Codegen
Do mind that rewriting you application into another language or framework probably won't solve your problems. NodeJS is not as typesafe as Vertx, and SpringBoot is not as concurrent as Vertx. But if you don't need typesafety or concurrency, both are viable options, of course.

Here's an open source project (for the JVM) that generates a Swagger/OpenAPI specification from your existing Vert.x router:
https://github.com/outofcoffee/vertx-oas
(Disclosure: It's my open source project)
Example usage:
// your normal Vert.x Web Router with paths etc.
Router router = Router.router(vertx);
router.post("/users").handler( routingContext -> { /* etc... */ });
router.get("/users/:userId").handler( routingContext -> { /* etc... */ });
// publish the Swagger/OpenAPI specification to a URL
RouterSpecGenerator.publishApiDocs(router, "/api/spec");
You can obtain YAML or JSON versions of the specification by adding the appropriate file extension.
For example, fetching /api/spec.yaml would produce:
openapi: "3.0.1"
info:
title: "Vert.x APIs"
description: "This specification was generated from a Vert.x Web Router."
paths:
/users:
post:
parameters: []
/users/{userId}:
get:
parameters:
- name: "userId"
required: true
allowEmptyValue: false

Related

How to configure Swashbuckle.AspNetCore.CLI like I can configure Swashbuckle.AspNetCore.Swagger in startup.cs

I need to configure Swashbuckle CLI to generate an Swagger spec in the OpenAPI 2.0 version. I do this in startup.cs with the following code:
public void Configure(IApplicationBuilder application, IWebHostEnvironment environment)
{
application.UseSwagger(c =>
{
c.SerializeAsV2 = true;
});
application.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/edgezones.json", "EdgeZoneRP Swagger");
});
}
...
}
but startup.cs seems to have no effect on Swashbuckle CLI's Swagger generation, as swagger tofile generates a Swagger spec in the OpenAPI 3.0 version (the default)
Turns out that reading the manual page can help!
Usage: dotnet swagger tofile [options] [startupassembly] [swaggerdoc]
startupassembly:
relative path to the application's startup assembly
swaggerdoc:
name of the swagger doc you want to retrieve, as configured in your startup class
options:
--output: relative path where the Swagger will be output, defaults to stdout
--host: a specific host to include in the Swagger output
--basepath: a specific basePath to include in the Swagger output
--serializeasv2: output Swagger in the V2 format rather than V3
--yaml: exports swagger in a yaml format

How to Add Resource with form-data Parameters in WSO2 API Manager?

I Have a REST API Which Takes two Parameters Like the Image Below:
And as You See This is form-data Parameters.
How can I Add This to API Manager?
In API Manager, from a UI perspective, we can only configure whether that particular API Resource requires a Body or Header. But, we can make use of the Swagger Editor to specify other fields.
I believe that your requirement is to show the mentioned two parameters as multipart/form-data properties in the Swagger UI. If so, make the following changes to the Swagger definition to display them (in Devportal). Assuming that you are using API Manager 3.x series, I have provided the Swagger snippet related to the OpenAPI definition
openapi: 3.0.1
...
paths:
/*:
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
param1:
type: string
param2:
type: object
format: binary
...
Hope this helps you to achieve your requirement.

Error Unable to setup base domain mappings for serverless custom domain

In serverless.yml, under custom, I have the following code (with dummy values here):
customDomain:
domainName: myhost.mydomain.com
basePath: ''
stage: ${self:provider:stage}
createRouteS3Record: true
endpointType: 'edge'
securityPolicy: tls_1_2
certificateArn: 'arn:aws:acm:.................'
hostZoneId: 'P4OCK4S1PSTZK'
when I execute serverless deploy, everything goes smooth. the Api get generated properly for my function.
(Under functions i have events: http)
However after the API getting generated lambda getting deployed, I get the following error:
Error: Error: Unable to setup base domain mappings for myhost.mydomain.com
i do not get much info other than https://forum.serverless.com/t/error-unable-to-setup-base-domain-mappings/11395
Do not know how to include api versions in serverless if that is the solution.
Well small things can cause big problems and are very hard to figure out at times.
I found that stage: ${self:provider:stage} was wrong, it should have been stage: ${self:provider.stage}. The colon after provider was the culprit.
I got this error after having a domain mapping, then removing it, then trying to add it again: it looks like Serverless doesn't completely remove a domain mapping.
I had to go to Custom domain names -> my domain -> API mappings -> Configure API mappings and manually delete the domain mapping before redeploying.
Had the same issue. In my serverless.yml file in events inside functions I was having 'httpApi'. Changing it to 'http' fixed my issue
functions:
getWebHooks:
handler: src/path
events:
- httpApi:
path: /
to
functions:
getWebHooks:
handler: src/path
events:
- http:
path: /
I was getting that error message because I (somehow) got the same api duplicated. so I went to
API Gateway -> Custom domain name -> {name_of_my_domain} -> API Mappings -> Configure API Mappings
Then I changed the API to use the correct API (holding the routes I was having in my app, and I could differentiate between both using their ID). Redeploying with Serverless succeeded

How to setup development environment for Ember.js + Express

I'm in the process of splitting into two different projects an Ember.js app and its Express REST API counterpart. I assumed that things would be cleaner this way.
Until then, my Express app was both serving REST endpoints and all static files like index.html and app.js. But now, ember-cli is in charge of serving the static files and the Express app handles authentication + REST.
The last issue I'm having is that I now have two different ports: ember-cli uses http://localhost:4200 and express uses http://localhost:3333. When I get the session cookie from Express upon authentication, it's never being sent on subsequent request because of same origin policy (see: How do I send an AJAX request on a different port with jQuery?).
Now if I understand correctly I have two solutions:
Setup Express to support JSONP and make sure Ember uses it too
Install a local Nginx or Apache and setup a proxy pass
The first solution is not ok because after deployment both apps will use the same domain/port. The second solution would probably work but it seems a bit ridiculous to ask developers to install a local web server to simply run an app.
I'm sure many of you have encountered that issue before. What would you suggest to make development easy?
Thanks!
Hmm. Seems like I found another solution:
Following instructions found there: http://discuss.emberjs.com/t/ember-data-and-cors/3690/2
export default DS.RESTAdapter.extend({
host: 'http://localhost:3333',
namespace: 'api',
ajax: function(url, method, hash) {
hash = hash || {}; // hash may be undefined
hash.crossDomain = true;
hash.xhrFields = { withCredentials: true };
return this._super(url, method, hash);
})
});
You will also need to add the following headers in the Express app:
// Add support for cross-origin resource sharing (localhost only)
app.all('*', function(req, res, next) {
if (app.get('env') === 'development') {
res.header('Access-Control-Allow-Origin', 'http://localhost:4200');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
}
next();
});
That's it! Last step is to make sure that Ember uses CORS only in the dev environment.
UPDATE
Ember-cli now has an integrated proxy feature that makes all the above obsolete.
From documentation: "Use --proxy flag to proxy all ajax requests to the given address. For example ember server --proxy http://127.0.0.1:8080 will proxy all your apps XHR to your server running at port 8080."

How can I use Play Framework's FakeApplication to stub out calls to web services via play's WS object?

I'm writing some functional tests in play, however I want to test my stack isolated from other http endpoints.
Is there a mechanism for me to say "Direct WS calls to this set of canned responses" or some other way of stubbing out calls to http endpoints that won't be available for automated tests?
Alternatively, how does fakeApplication config get presented to the rest of the application so I can just set the URL to some localhost server which I'll build myself to provide canned responses
You could create a structural type that mimics the WS signature and use that in your code.
type WSLike = {
def url(url: String): WSRequestHolder
}
Then you can inject your own version of a WSLike class. In combination with a mock library I guess you could do about anything you want.
As for the second question. You could call it like this:
val url = Play.current.configuration
.getString("my.webservice.url")
.getOrElse(throw new PlayException(
"Configuration error",
"Could not find my.webservice.url in settings"))
WS.url(url)
Then in your application.conf add the correct url. You can supply a different one using the FakeApplication.
FakeApplication(additionalConfiguration =
Map("my.webservice.url" -> "http://localhost/service"))