Skip to content

Commit 59bd9f4

Browse files
authored
improve(docker): bail out + provide helpful error if injection fails (via #5007)
* add `onFound` callback to schemas * add warning to method docs (for #4957) * implement Docker OAuth2 init block support * update docs * add OAUTH_SCOPE_SEPARATOR * drop OAuth env from Dockerfile and run script * don't indent the first oauth block line * drop unused `dedent` import * touch up warning message * add more test cases * return an empty block if no OAuth content is generated * fix broken doc line * allow legacy values to override base values * TEMPORARY (DROP THIS): use legacy HTML from Petstore * improve(docker): bail out + provide helpful error if injection fails * Revert "TEMPORARY (DROP THIS): use legacy HTML from Petstore" This reverts commit 10c18c333262c5411197d9bb085c6b95305beb19.
1 parent 02758b8 commit 59bd9f4

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

docker/configurator/index.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,34 @@ const startMarkerIndex = originalHtmlContent.indexOf(START_MARKER)
1616
const endMarkerIndex = originalHtmlContent.indexOf(END_MARKER)
1717

1818
const beforeStartMarkerContent = originalHtmlContent.slice(0, startMarkerIndex)
19-
const afterEndMarkerContent = originalHtmlContent.slice(endMarkerIndex + END_MARKER.length)
19+
const afterEndMarkerContent = originalHtmlContent.slice(
20+
endMarkerIndex + END_MARKER.length
21+
)
2022

21-
fs.writeFileSync(targetPath, `${beforeStartMarkerContent}
23+
if (startMarkerIndex < 0 || endMarkerIndex < 0) {
24+
console.error("ERROR: Swagger UI was unable to inject Docker configuration data!")
25+
console.error("! This can happen when you provide custom HTML to Swagger UI.")
26+
console.error("! ")
27+
console.error("! In order to solve this, add the `Begin Swagger UI call region`")
28+
console.error("! and `End Swagger UI call region` markers to your HTML.")
29+
console.error("! See the repository for an example:")
30+
console.error("! https://github.com/swagger-api/swagger-ui/blob/02758b8125dbf38763cfd5d4f91c7c803e9bd0ad/dist/index.html#L40-L54")
31+
console.error("! ")
32+
console.error("! If you're seeing this message and aren't using custom HTML,")
33+
console.error("! this message may be a bug. Please file an issue:")
34+
console.error("! https://github.com/swagger-api/swagger-ui/issues/new/choose")
35+
process.exit(0)
36+
}
37+
38+
fs.writeFileSync(
39+
targetPath,
40+
`${beforeStartMarkerContent}
2241
${START_MARKER}
2342
const ui = SwaggerUIBundle({
2443
${indent(translator(process.env, { injectBaseConfig: true }), 8, 2)}
2544
})
2645
2746
${indent(oauthBlockBuilder(process.env), 6, 2)}
2847
${END_MARKER}
29-
${afterEndMarkerContent}`)
48+
${afterEndMarkerContent}`
49+
)

0 commit comments

Comments
 (0)