Skip to content

Commit b403fd3

Browse files
committed
server /openapi.yaml
Dependent on the build system (e.g., esbuild) to be configured to import a .yaml file as a string. eg: for esbuild add loader: { '.yaml': 'text' }
1 parent 216fd57 commit b403fd3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/requestHandler.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ import {
5656
} from "./constants";
5757
import LocalRestApiPublicApi from "./api";
5858

59+
// Import openapi.yaml as a string
60+
import openapiYaml from "../docs/openapi.yaml";
61+
5962
export default class RequestHandler {
6063
app: App;
6164
api: express.Express;
@@ -255,10 +258,10 @@ export default class RequestHandler {
255258
certificateInfo:
256259
this.requestIsAuthenticated(req) && certificate
257260
? {
258-
validityDays: getCertificateValidityDays(certificate),
259-
regenerateRecommended:
260-
!getCertificateIsUptoStandards(certificate),
261-
}
261+
validityDays: getCertificateValidityDays(certificate),
262+
regenerateRecommended:
263+
!getCertificateIsUptoStandards(certificate),
264+
}
262265
: undefined,
263266
apiExtensions: this.requestIsAuthenticated(req)
264267
? this.apiExtensions.map(({ manifest }) => manifest)
@@ -1173,6 +1176,12 @@ export default class RequestHandler {
11731176
}
11741177

11751178
setupRouter() {
1179+
// Serve /openapi.yaml unauthenticated
1180+
this.api.get("/openapi.yaml", (req, res) => {
1181+
res.setHeader("Content-Type", "application/yaml; charset=utf-8");
1182+
res.status(200).send(openapiYaml);
1183+
});
1184+
11761185
this.api.use((req, res, next) => {
11771186
const originalSend = res.send;
11781187
res.send = function (body, ...args) {

0 commit comments

Comments
 (0)