diff --git a/layouts/partials/shortcodes/openapi.html b/layouts/partials/shortcodes/openapi.html
index 206452e38b..c62cf5bb29 100644
--- a/layouts/partials/shortcodes/openapi.html
+++ b/layouts/partials/shortcodes/openapi.html
@@ -4,18 +4,21 @@
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'openapi' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
{{- end }}
{{- $src := .src }}
+{{- $spec := "" }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
{{- with $page }}
-{{- with .Resources.Match $src }}
- {{- range . }}
- {{- $src = .RelPermalink }}
- {{- end }}
+{{- with or
+ (.Resources.Get $src)
+ (resources.Get $src)
+}}
+ {{- $spec = .Content }}
{{- end }}
{{- .Store.Set "hasOpenApi" true }}
diff --git a/static/js/theme.js b/static/js/theme.js
index 51b5a02025..865ca140a2 100644
--- a/static/js/theme.js
+++ b/static/js/theme.js
@@ -446,7 +446,7 @@ function initOpenapi( update, attrs ){
const openapiPromise = new Promise( function(resolve){ resolve() });
openapiPromise
.then( function(){
- SwaggerUIBundle({
+ var options = {
defaultModelsExpandDepth: 2,
defaultModelExpandDepth: 2,
docExpansion: isPrint || attrs.isPrintPreview ? 'full' : 'list',
@@ -470,9 +470,15 @@ function initOpenapi( update, attrs ){
activated: true,
theme: swagger_code_theme,
},
- url: oc.dataset.openapiUrl,
validatorUrl: 'none',
- });
+ };
+ if( oc.dataset.openapiSpec ){
+ Object.assign( options, { spec: JSON.parse( oc.dataset.openapiSpec ) });
+ }
+ else{
+ Object.assign( options, { url: oc.dataset.openapiUrl });
+ }
+ SwaggerUIBundle( options );
})
.then( function(){
let observerCallback = function () {