procurement-ingest/lambdas/api/docs.html
Adam Moussa 8156b275a9
Some checks are pending
Deploy / deploy (push) Waiting to run
feat(api): stock Swagger UI for /docs (vendored offline) (#128)
* feat(api): use stock Swagger UI for the /docs page

Replaces the custom renderer with vendored stock Swagger UI
(swagger-ui-dist 5.17.14, Apache-2.0), kept offline (no CDN) and inlined
server-side into the single token-gated /docs response alongside the spec.
BaseLayout (topbar hidden); try-it-out disabled since data routes need SigV4
(use Postman for live calls). Breakout guards on the inlined css/js/spec.
Bundle-consistency + spec-drift + handler tests updated for the two vendored
assets. cdk diff = Lambda code asset only (no IAM/API/policy change).

* fix(api): render Swagger UI with the canonical StandaloneLayout recipe

The BaseLayout-only init (apis preset, no standalone preset) rendered
incorrectly. Switch to the canonical swagger-ui-dist recipe: vendor
swagger-ui-standalone-preset.js and init with
presets:[apis, SwaggerUIStandalonePreset] + layout:"StandaloneLayout"
(topbar hidden, try-it-out disabled). Verified via headless Chrome against
the live deployed page: all 9 endpoints + 4 webhooks + models render.
Tests/bundling updated for the third vendored asset.

* fix(api): declutter the Swagger UI docs page

The page rendered (stock Swagger UI, StandaloneLayout) but looked cramped:
a dense info.description wall of inline-code chips collided across Swagger
UI's tight default line-height, and the Servers box showed a SEE-STACK-OUTPUT
placeholder.

- Trim info.description to a few concise lines (detail lives in README + the
  webhook contract doc).
- Inject the live invoke URL into servers[0].url per request (from the API
  Gateway request context; committed literal is the fallback), so the Servers
  box shows the real endpoint and drops the server-variables section.
- CSS: loosen description line-height + inline-code padding so chips never
  overlap; tidy the scheme container spacing.
- Handler: cache the heavy CSS/JS/preset shell once; splice the (server-
  injected) spec per request.

Verified via headless Chrome against the live deployed page.
2026-07-23 20:19:47 -04:00

54 lines
2.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Procurement Ingest API</title>
<!--
Stock Swagger UI (swagger-ui-dist, Apache-2.0), vendored offline and inlined
server-side so /docs is a single token-gated request with no CDN or
follow-up asset fetch. The CSS, swagger-ui-bundle.js, the standalone preset,
and the OpenAPI spec are substituted for the placeholders below by
lambdas/api/handler.py::_load_docs_html. The initializer is the canonical
swagger-ui-dist recipe (StandaloneLayout + both presets); the topbar's
spec-URL bar is hidden since the spec is fixed and inlined.
-->
<style>__SWAGGER_UI_CSS__</style>
<style>
html { box-sizing: border-box; overflow-y: scroll; }
*, *:before, *:after { box-sizing: inherit; }
body { margin: 0; background: #fafafa; }
.swagger-ui .topbar { display: none; }
/* Give the description prose room: Swagger UI's default markdown line-height
is tight, so inline code chips (background + padding) visually collide
across lines. Loosen line-height and keep chips from wrapping. */
.swagger-ui .info { margin: 30px 0 20px; }
.swagger-ui .info .markdown p,
.swagger-ui .info .renderedMarkdown p { line-height: 1.75; margin: 0 0 12px; }
.swagger-ui .info code,
.swagger-ui .renderedMarkdown code { padding: 1px 5px; line-height: 1.6; white-space: nowrap; }
.swagger-ui .scheme-container { margin: 0 0 20px; padding: 20px 0; }
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script>__SWAGGER_UI_JS__</script>
<script>__SWAGGER_UI_STANDALONE_PRESET_JS__</script>
<script>
window.ui = SwaggerUIBundle({
spec: __OPENAPI_SPEC_JSON__,
dom_id: "#swagger-ui",
deepLinking: true,
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
layout: "StandaloneLayout",
docExpansion: "list",
defaultModelsExpandDepth: 1,
// Try-it-out is disabled: data routes require AWS SigV4, which a browser
// can't sign. Use Postman (Authorization type "AWS Signature") against the
// same spec for live calls.
supportedSubmitMethods: []
});
</script>
</body>
</html>