简体   繁体   English

为vertx项目生成OpenAPI规范

[英]Generate OpenAPI spec for vertx project

I want to generate an OpenAPI spec for my vertx project. 我想为我的vertx项目生成一个OpenAPI规范。 So I have a simple vertx server as follows which just returns me a json object: 所以我有一个简单的vertx服务器如下,它只返回一个json对象:

package server;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;

public class Server extends AbstractVerticle {

  @Override
  public void start() throws Exception {
    HttpServer server = vertx.createHttpServer();
    Router router = Router.router(vertx);
    router.route("/v0.2.2/*").handler(this::responseSetUp);
    router.get("/v0.2.2/location").handler(this::getLocation);
    server.requestHandler(router::accept).listen(8004);
  }

  public void responseSetUp(RoutingContext context) {
    HttpServerResponse response = context.response();
    response.putHeader("Access-Control-Allow-Origin", "*")
        .putHeader("Access-Control-Allow-Methods", "GET, POST, PUT , DELETE, OPTIONS")
        .putHeader("Access-Control-Allow-Headers", "Content-Type,cache-control, x-requested-with")
        .putHeader("Access-Control-Max-Age", "86400");
    context.next();
  }

  public void getLocation(RoutingContext context) {
    JsonObject location = new JsonObject();
    location.put("city", "Bangalore");
    location.put("country", "India");
    location.put("pin", 560095);
    HttpServerResponse response = context.response();
    response.putHeader("content-type", "application/json");
    response.setChunked(true);
    response.write(location.toString());
    response.end();
  }
}

I just want to generate an OpenAPI spec for this route. 我只是想为这条路线生成一个OpenAPI规范。 I am new to Swagger and so far while googling, I could see tutorials for RestEasy, Mule, Jersey1,Jersey2, Spring but not for vertx. 我是Swagger的新手,到目前为止谷歌搜索时,我可以看到RestEasy,Mule,Jersey1,Jersey2,Spring的教程,但不是针对vertx。

Can anyone please help me out or any pointers? 任何人都可以帮我或任何指针?

Sorry, if the question is naive. 对不起,如果问题很幼稚。

With Vert.x 3.5.0 there's a new package called Vert.x Web API Contract that helps you generate the Router and the Validation handlers for your request. 使用Vert.x 3.5.0,有一个名为Vert.x Web API Contract的新软件包,可帮助您为请求生成路由器和验证处理程序。 You can also generate a skeleton of your project with slush-vertx , a command line tool that helps you scaffolding your project 您还可以使用slush-vertx生成项目的框架, slush-vertx是一个帮助您构建项目脚手架的命令行工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM