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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With