Skip to content

Commit

Permalink
openapi: make it run for file:// protocol #806
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Mar 16, 2024
1 parent 567b930 commit b18bca9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions layouts/partials/shortcodes/openapi.html
Expand Up @@ -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 }}
<div class="sc-openapi-wrapper is-loading helper-loading-container">
<div
class="sc-openapi-container"
id="R-openapi-{{ $id }}"
data-openapi-url="{{ $src }}"
data-openapi-spec="{{ $spec | safeHTMLAttr }}"
></div>
</div>
{{- .Store.Set "hasOpenApi" true }}
Expand Down
12 changes: 9 additions & 3 deletions static/js/theme.js
Expand Up @@ -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',
Expand All @@ -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 () {
Expand Down

0 comments on commit b18bca9

Please sign in to comment.