openfire-restAPI-plugin icon indicating copy to clipboard operation
openfire-restAPI-plugin copied to clipboard

(Auto)generate documentation

Open guusdk opened this issue 3 years ago • 13 comments

The documentation that's provided with this plugin seems to be generated from the code. We should document how this is done. Ideally, it's automatically re-generated when the plugin is build (mvn clean package).

guusdk avatar Dec 18 '21 11:12 guusdk

Hi what's the URL to get the Swagger Documentation?

ruicaramalho avatar Apr 11 '22 14:04 ruicaramalho

Based on the AuthFilter, looks to be at /plugins/restapi/v1/openapi.yaml

Fishbowler avatar Apr 11 '22 14:04 Fishbowler

Im missing something.. If I try to open it in the browser it will treat .yaml as a file and download it.

PS -It does work if I open the index file:///C:/Program%20Files/Openfire/plugins/restapi/web/docs/index.html

ruicaramalho avatar Apr 11 '22 15:04 ruicaramalho

You're right.

I've just had a quick test on my local docker environment. After installation, there's a link in the settings. image That links to /plugins/restapi/docs/index.html which opens the view you're looking for.

Fishbowler avatar Apr 11 '22 15:04 Fishbowler

Thanks @Fishbowler .

The only thing that could be improved is that the swagger URL by default is `http://localhost:9090/plugins/restapi/v1/openapi.yaml'

image

It should have gotten the current location and port, in Javascript window.location.origin in my case:

image

ruicaramalho avatar Apr 11 '22 15:04 ruicaramalho

FWIW, a relative URL may well work, e.g. /plugins/restapi/v1/openapi.yaml (or even ../v1/openapi.yaml) (not tried either - but based on experience in other Swagger APIs

GregDThomas avatar Apr 11 '22 15:04 GregDThomas

Thanks @GregDThomas but it does not work, it suggests downloading the file

ruicaramalho avatar Apr 11 '22 15:04 ruicaramalho

The only thing that could be improved is that the swagger URL by default is `http://localhost:9090/plugins/restapi/v1/openapi.yaml'

The location linked to from the settings page?

If so, I'll raise an issue.

(btw, you blanked your domain from the address bar, but not from your image, but these posts are editable if you care about keeping it unknown)

Fishbowler avatar Apr 11 '22 15:04 Fishbowler

Solution:

Edit the index file and change to:

.......
<script>
    window.onload = function() {
        // Begin Swagger UI call region
        const ui = SwaggerUIBundle({
            url: window.location.origin+"/plugins/restapi/v1/openapi.yaml",
            dom_id: '#swagger-ui',
            deepLinking: true,
            presets: [
                SwaggerUIBundle.presets.apis,
                SwaggerUIStandalonePreset
            ],
            plugins: [
                SwaggerUIBundle.plugins.DownloadUrl
            ],
            layout: "StandaloneLayout"
        });
        // End Swagger UI call region

        window.ui = ui;
    };
</script>
......

Originaly it was:

........
<script>
    window.onload = function() {
        // Begin Swagger UI call region
        const ui = SwaggerUIBundle({
            url: "http://localhost:9090/plugins/restapi/v1/openapi.yaml",
            dom_id: '#swagger-ui',
            deepLinking: true,
            presets: [
                SwaggerUIBundle.presets.apis,
                SwaggerUIStandalonePreset
            ],
            plugins: [
                SwaggerUIBundle.plugins.DownloadUrl
            ],
            layout: "StandaloneLayout"
        });
        // End Swagger UI call region

        window.ui = ui;
    };
</script>
........

ruicaramalho avatar Apr 11 '22 15:04 ruicaramalho

Ah yep. Got it.

https://github.com/igniterealtime/openfire-restAPI-plugin/blob/dfaa49ffa928ee641aca636c2911dcd9be722468/src/web/docs/index.html#L44

Fishbowler avatar Apr 11 '22 15:04 Fishbowler

Thanks... it's fixed then :)

ruicaramalho avatar Apr 11 '22 15:04 ruicaramalho

Hi Does this means, that this feature will be corrected in future versions?

PS -Sorry but I don't know how the GitHub works.

ruicaramalho avatar Apr 12 '22 18:04 ruicaramalho

Hi @guusdk.

what I mean is if the index.html is going to be corrected. https://github.com/igniterealtime/openfire-restAPI-plugin/blob/dfaa49ffa928ee641aca636c2911dcd9be722468/src/web/docs/index.html#L44

To: url: window.location.origin+"/plugins/restapi/v1/openapi.yaml",

ruicaramalho avatar Apr 13 '22 14:04 ruicaramalho