生成不完整的Json APIS未到来。有人可以检查一下

时间:2015-05-11 07:29:10

标签: json swagger

使用此代码:

@Path("/dbresource")
@Api(value = "Available_Connections", description = "List of available DB connections to generate the report", position = 1)
public class DbConnectionResource {

    private static final Logger log = Logger
            .getLogger(DbConnectionResource.class);
    public ConnectionProperties m_objConnProperties = new ConnectionProperties();
    private List<ConnectionProperties> m_listOfTempProperties = new ArrayList<ConnectionProperties>();
    private List<String> m_dbResources = new ArrayList();
    private JDBCConnectionFactory m_objConnFactory = new JDBCConnectionFactory();

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(
            value = "Available connection details.",
            notes = "List all Possible connections with the default one",
            position = 1,
            httpMethod = "GET",
            produces = "application/json"
            )
    @ApiResponses( value={
            @ApiResponse(code = 200, message = "Successfully retrieved."),
            @ApiResponse(code = 401, message = "Unable to generate Report due to incorrect mapping between DB and template")
    })
    private Response getAvailableDBResources() {
        try {

            JAXBContext jaxbContext = JAXBContext
                    .newInstance(JDBCConnectionFactory.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            m_objConnFactory = (JDBCConnectionFactory) jaxbUnmarshaller
                    .unmarshal(getClass().getClassLoader().getResourceAsStream(
                            "JdbcConnections.xml"));
            m_listOfTempProperties = m_objConnFactory.getConnections()
                    .getConnection();
            System.out.println(m_listOfTempProperties.size());
            for (ConnectionProperties cpt : m_listOfTempProperties) {
                m_dbResources.add(cpt.getConnectionname());
                System.out.println("all conn"+cpt.getConnectionname());
            }
        } catch (Exception e) {
            System.out.println("inside jaxb exp");
            log.debug("inside exception jaxb " + e.getMessage(), e);
            return Response.status(401).build();
        }
        Gson gson = new Gson();
        gson.toJson(m_dbResources);
        return Response.ok(gson).build();

    }
}

我从swagger-core获得以下输出:

{
  "apiVersion" : "1.1",
  "swaggerVersion" : "1.2",
  "basePath" : "http://localhost:8090/report-service",
  "resourcePath" : "/Avalable_Connections"
}

我的资源文档在哪里?

1 个答案:

答案 0 :(得分:1)

您似乎正在使用生成Swagger 1.2定义的旧版swagger-core。在这种情况下,输出实际上很好。

您将在/api-docs/Avalable_Connections下找到资源文档。这只是Swagger 1.2的结构。

如果您升级到最新的swagger-core,您将获得Swagger 2.0和整个定义在一个文件中。