The YAML files for the swagger component is in the AEM DAM in the folder /content/dam/yaml-files.
When I do it like this I get the correct url in the template
{url: '/content/dam/yaml-files/account-information-service-api-v2-of-fi.yaml', name: 'account-information-service-api-v2-of-fi'},
but AEM of course does not interprete is as an Asset ie. yaml file.
<sly data-sly-use.model="xxx.component.content.SwaggerModel"
data-sly-use.template="core/wcm/components/commons/v1/templates.html"
data-sly-use.clientlib="/libs/granite/sightly/templates/clientlib.html">
</sly>
<sly data-sly-call="${clientlib.all @ categories='xxxi.swagger-ui'}"/>
<sly data-sly-call="${template.placeholder @ isEmpty=!model.defined}"></sly>
<div data-sly-test="${model.defined}">
<h1 class="t-title">
${model.title}
</h1>
<p>
${model.swaggerYamlPath}
</p>
<sly data-sly-test="${model.defined}" data-sly-call="${swaggerScript @ path=model.path}"></sly>
<div id="swagger-ui"></div>
</div>
<template data-sly-template.swaggerScript="${ @ path}">
<script>
window.onload = function () {
//<editor-fold desc="Changeable Configuration Block">
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
urls: [
{url: '${path @ context='html'}', name: 'account-information-service-api-v2-of-fi'},
{url: '/yaml/consent-flow-api-v2-of-fi.yaml', name: 'consent-flow-api-v2-of-fi'},
{url: '/yaml/custody-services-api-v1-of-fi.yaml', name: 'custody-services-api-v1-of-fi'},
{url: '/yaml/payments-submission-service-api-v2-of-fi.yaml', name: 'payments-submission-service-api-v2-of-fi'},
],
url: 'http://localhost:8080/test.yaml',
dom_id: '#swagger-ui',
deepLinking: true,
filter: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: 'StandaloneLayout'
});
//</editor-fold>
};
</script>
</template>
Here is the model:
@Model(adaptables = SlingHttpServletRequest.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SwaggerModel extends AbstractComponentModel {
@ValueMapValue
private String swaggerTitle;
@ValueMapValue
private String swaggerYamlPath;
public boolean isDefined() {
return StringUtils.isNoneBlank(swaggerYamlPath);
}
public String getSwaggerYamlPath(){
return LinkUtil.getExternalLink(resource.getResourceResolver(), swaggerYamlPath);
}
public String getTitle() {
return swaggerTitle;
}
public String getPath() { return swaggerYamlPath;}
}