I'm developing a grails 4 plugin to display Swagger documentation. Starting the plugin locally works without problem, and the Swagger interface is loaded as expected.
I want to test my plugin locally, so I run the gradle task publishToMavenLocal and then declare this as a depencency in my test application using implementation "swagger.grails4:swagger-grails4:0.1.2". So far so good.
When i go to the correct endpoint in my test application, the Swagger interface is however not loaded. When I open the DevTools, I can see that it doesn't load the JavaScript files correctly from my plugin:
The .gsp view also seem to lack references to my plugin assets when loaded in my test application:
This view is implemented like this in my plugin code:
<%@ page import="swagger.grails4.SwaggerController" %>
<asset:javascript src="swagger-grails4/swagger-ui-bundle.js" charset="UTF-8"/>
<asset:javascript src="swagger-grails4/swagger-ui-standalone-preset.js" charset="UTF-8"/>
<asset:stylesheet src="swagger-grails4/swagger-ui.css"/>
<asset:image src="swagger-grails4/favicon-16x16.png"/>
<asset:image src="swagger-grails4/favicon-32x32.png"/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body
{
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "${createLink(controller: 'swagger', action: 'openApiDocument')}",
dom_id: '#swagger-ui',
deepLinking: true,
validatorUrl: 'none',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
// End Swagger UI call region
window.ui = ui;
};
</script>
</body>
</html>
In my plugin I have placed all the assets in the /assets directory under a "namespace" folder, as recommended by the asset-plugin documentation:
As I said, none of this is a problem if I just run my plugin as a standalone application.


