Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用swagger核心和swagger UI标准化RESTAPI_Java_Json_Rest_Swagger - Fatal编程技术网

Java 使用swagger核心和swagger UI标准化RESTAPI

Java 使用swagger核心和swagger UI标准化RESTAPI,java,json,rest,swagger,Java,Json,Rest,Swagger,我正在尝试标准化一个非常基本的REST服务,它使用jax rs将温度从摄氏度转换为华氏度,反之亦然。我试图标准化的类包含一个转换温度的简单代码。我试图合并Swagger Core来创建JSON文件,但创建的JSON文件不符合Swagger语法。原因是我使用的招摇过市注释不是创建JSON文件,而是由方法的return语句创建JSON。我尝试了几种方法,但都没有成功。使用的注释是否有问题,或者createjsonobject是否验证了招摇过市的部分 import org.json.JSONExcep

我正在尝试标准化一个非常基本的REST服务,它使用jax rs将温度从摄氏度转换为华氏度,反之亦然。我试图标准化的类包含一个转换温度的简单代码。我试图合并Swagger Core来创建JSON文件,但创建的JSON文件不符合Swagger语法。原因是我使用的招摇过市注释不是创建JSON文件,而是由方法的return语句创建JSON。我尝试了几种方法,但都没有成功。使用的注释是否有问题,或者createjsonobject是否验证了招摇过市的部分

import org.json.JSONException;
import org.json.JSONObject;
import io.swagger.annotations.*;

@Api
@SwaggerDefinition(
    info = @Info(
            description = "My API",
            version = "V1.2.3",
            title = "The only API you'll ever need to learn about me",
            termsOfService = "share and care",
            contact = @Contact(name = "Sponge-Bob", email = "sponge-bob@swagger.io", url = "http://swagger.io"),
            license = @License(name = "Apache 2.0", url = "http://www.apache.org")
            ),
    consumes = {"application/json" },
    produces = {"application/json" },
    schemes = {SwaggerDefinition.Scheme.HTTP,      SwaggerDefinition.Scheme.HTTPS},
    externalDocs = @ExternalDocs(value = "About me", url = "http://about.me/me"))

@Path("/ftocservice")



@Produces({"application/json"})

public class FtoCService {

@GET

  public Response convertFtoC() throws JSONException {

    JSONObject jsonObject = new JSONObject();
    Double fahrenheit = 98.24;
    Double celsius;
    celsius = (fahrenheit - 32)*5/9; 
    jsonObject.put("FtoC", celsius);
    String result = ""+jsonObject;
    return Response.status(200).entity(result).build();
  }