Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get swagger ui html from io.swagger.models.Swagger?

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?

like image 609
HellishHeat Avatar asked Oct 27 '22 06:10

HellishHeat


2 Answers

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

like image 161
Smile Avatar answered Nov 15 '22 03:11

Smile


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.

like image 24
Artem Budnikov Avatar answered Nov 15 '22 03:11

Artem Budnikov