Summary
It would be very helpful if this action exposed a way to inject additional
SwaggerUIBundle({...}) configuration into the generated index.html.
Today, the template at resources/index.html hard-codes the bundle call to:
const ui = SwaggerUIBundle({
configUrl: "<swaggerConfig>",
dom_id: '#swagger-ui'
})
Users can already influence parts of the runtime config via swagger-config.json,
but that file is JSON and therefore cannot carry function-valued options such as
requestInterceptor, responseInterceptor, onComplete, plugins, etc. These
options can only live inside the inline SwaggerUIBundle({...}) call site, which
this action does not currently expose.
Motivating use case
In our team, we use Try It Out → Execute primarily to obtain the rendered
curl command for the request, since the spec's server URL is behind a VPN /
IP allow-list and the real call is made from a different environment. We do
not need to wait for a response.
However, Execute has no built-in request timeout, so the UI hangs until the
browser/network eventually aborts the request, which in our environment is on
the order of tens of seconds, even though we already have the information we
wanted.
A requestInterceptor that attaches an AbortSignal.timeout(...) fixes this:
requestInterceptor: function (req) {
req.signal = AbortSignal.timeout(3000);
return req;
}
Because this is a function, it cannot be expressed via swagger-config.json and
must be injected into the inline SwaggerUIBundle({...}) call.
Proposed solution
Add a new optional input — e.g. extra-config — whose value is a JS fragment
appended inside the SwaggerUIBundle({...}) object literal in the generated
index.html. Implementation-wise this can be a new <extraConfig> placeholder
in resources/index.html, populated by the existing sed-based templating in
createIndexHtml.
Template:
const ui = SwaggerUIBundle({
configUrl: "<swaggerConfig>",
dom_id: '#swagger-ui',
<extraConfig>
})
Example usage:
- uses: Legion2/swagger-ui-action@v1
with:
output: swagger-ui
spec-file: openapi.yaml
extra-config: |
requestInterceptor: function (req) {
req.signal = AbortSignal.timeout(3000);
return req;
}
Benefits:
- Solves the timeout use case above.
- Generalizes to other long-standing needs that require function values
(responseInterceptor, custom plugins, onComplete, etc.) without
adding a new input per option.
- Minimal change: one new optional input, one placeholder in the template,
no behavior change when the input is not set.
When the input is empty, the trailing comma in the template can be handled
either by emitting it conditionally from the action code or by relying on
JS's tolerance for trailing commas in object literals.
Alternative considered
A narrower input such as request-timeout: 3000 that only handles this one
case. It is simpler, but every future function-valued config option would
require yet another input, so the generalized extra-config approach feels
strictly better.
Current workaround
For now, we post-process the generated file in our workflow with sed:
- name: Add 3s timeout to Swagger UI Try It Out requests
run: |
sed -i "s/dom_id: '#swagger-ui'/dom_id: '#swagger-ui', requestInterceptor: function(req) { req.signal = AbortSignal.timeout(3000); return req; }/" docs/swagger-ui/index.html
This works but is fragile against future template changes in this action and
is not something we'd recommend other users copy.
Willingness to contribute
Happy to send a PR if the maintainers agree with the extra-config direction.
Please let me know which input name / shape you'd prefer before I start.
Summary
It would be very helpful if this action exposed a way to inject additional
SwaggerUIBundle({...})configuration into the generatedindex.html.Today, the template at
resources/index.htmlhard-codes the bundle call to:Users can already influence parts of the runtime config via
swagger-config.json,but that file is JSON and therefore cannot carry function-valued options such as
requestInterceptor,responseInterceptor,onComplete, plugins, etc. Theseoptions can only live inside the inline
SwaggerUIBundle({...})call site, whichthis action does not currently expose.
Motivating use case
In our team, we use Try It Out → Execute primarily to obtain the rendered
curlcommand for the request, since the spec's server URL is behind a VPN /IP allow-list and the real call is made from a different environment. We do
not need to wait for a response.
However, Execute has no built-in request timeout, so the UI hangs until the
browser/network eventually aborts the request, which in our environment is on
the order of tens of seconds, even though we already have the information we
wanted.
A
requestInterceptorthat attaches anAbortSignal.timeout(...)fixes this:Because this is a function, it cannot be expressed via
swagger-config.jsonandmust be injected into the inline
SwaggerUIBundle({...})call.Proposed solution
Add a new optional input — e.g.
extra-config— whose value is a JS fragmentappended inside the
SwaggerUIBundle({...})object literal in the generatedindex.html. Implementation-wise this can be a new<extraConfig>placeholderin
resources/index.html, populated by the existingsed-based templating increateIndexHtml.Template:
Example usage:
Benefits:
(
responseInterceptor, customplugins,onComplete, etc.) withoutadding a new input per option.
no behavior change when the input is not set.
When the input is empty, the trailing comma in the template can be handled
either by emitting it conditionally from the action code or by relying on
JS's tolerance for trailing commas in object literals.
Alternative considered
A narrower input such as
request-timeout: 3000that only handles this onecase. It is simpler, but every future function-valued config option would
require yet another input, so the generalized
extra-configapproach feelsstrictly better.
Current workaround
For now, we post-process the generated file in our workflow with
sed:This works but is fragile against future template changes in this action and
is not something we'd recommend other users copy.
Willingness to contribute
Happy to send a PR if the maintainers agree with the
extra-configdirection.Please let me know which input name / shape you'd prefer before I start.