OK, I have a number of io.swagger.models.Swagger objects, I have merged these into one new, super Swagger. Now I want the super html. How can I get this? Note, in order to get each of my Swagger definitions, I used new SwaggerParser().read("pathToSwagger"). So, that's an example of getting a Swagger object from the Swagger source, now I need the opposite, namely, to produce Swagger source from a io.swagger.models.Swagger object. Can you help?
Asked
Active
Viewed 384 times
2 Answers
1
You can try following code. From JSONObject
, you will get the Swagger json, which can be further used in the HTML.
public JSONObject getSwaggerJson(Swagger swagger) throws ServiceApiException {
try {
// Re-parse as JsonObject to ensure ordering of definitions and paths.
// TODO: make this optional (see limberest.yaml comments in limberest-demo)
JsonObject swaggerJson = new JsonObject(Json.mapper().writeValueAsString(swagger));
if (swaggerJson.has("definitions"))
swaggerJson.put("definitions", new JsonObject(swaggerJson.getJSONObject("definitions").toString()));
if (swaggerJson.has("paths"))
swaggerJson.put("paths", new JsonObject(swaggerJson.getJSONObject("paths").toString()));
return swaggerJson;
}
catch (JsonProcessingException ex) {
throw new ServiceApiException(ex.getMessage(), ex);
}
}
Source : https://www.programcreek.com/java-api-examples/?api=io.swagger.models.Swagger

Smile
- 3,832
- 3
- 25
- 39
1
I know one interest open source project j2html. There, the formation of the html document is performed in interesting way. May be it'll help you to create one html from super swagger object.

Artem Budnikov
- 66
- 5