From 1e8223f777cc841986e37992ae3f58c2fed6cfcf Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 22 Jan 2025 18:11:03 -0500 Subject: [PATCH] Adding multiple versions os API docs at /api/next, and /api/latest . - Fixes #452 --- Dockerfile | 22 ++++++++++++++++++---- src/server/index.tsx | 23 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index be6c493..ac79d23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,9 +15,20 @@ COPY lemmy-docs ./lemmy-docs RUN ./mdbook build lemmy-docs -d ../docs # Build the typedoc lemmy-js-client docs, and swagger.json -FROM node:20-alpine AS api +FROM node:20-alpine AS api_latest WORKDIR /app -COPY lemmy-js-client lemmy-js-client +COPY lemmy-js-client-latest lemmy-js-client +WORKDIR /app/lemmy-js-client +RUN corepack enable pnpm +RUN pnpm i +RUN pnpm run docs +# TODO OpenAPI isn't currently working for the latest docs. This can be changed after the next release. +# RUN pnpm tsoa + +# Do the same for the api docs, but next +FROM node:20-alpine AS api_next +WORKDIR /app +COPY lemmy-js-client-next lemmy-js-client WORKDIR /app/lemmy-js-client RUN corepack enable pnpm RUN pnpm i @@ -51,8 +62,11 @@ COPY src src # Copy the rust docs, lemmy-js-client docs, and OpenAPI docs. COPY --from=docs /app/docs ./src/assets/docs -COPY --from=api /app/lemmy-js-client/docs ./src/assets/lemmy-js-client-docs -COPY --from=api /app/lemmy-js-client/redoc-static.html ./src/assets/api.html +COPY --from=api_latest /app/lemmy-js-client/docs ./src/assets/lemmy-js-client-latest-docs +# TODO OpenAPI isn't currently working for the latest docs. This can be changed after the next release. +# COPY --from=api_latest /app/lemmy-js-client/redoc-static.html ./src/assets/api_latest.html +COPY --from=api_next /app/lemmy-js-client/docs ./src/assets/lemmy-js-client-next-docs +COPY --from=api_next /app/lemmy-js-client/redoc-static.html ./src/assets/api_next.html RUN pnpm i RUN pnpm prebuild:prod diff --git a/src/server/index.tsx b/src/server/index.tsx index 5ccfdde..1bf2a75 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -26,10 +26,27 @@ server.use(express.json() as RequestHandler); server.use(express.urlencoded({ extended: false }) as RequestHandler); server.use("/static", express.static(path.resolve("./dist"))); server.use("/docs", express.static(path.resolve("./dist/assets/docs"))); -server.use("/api", express.static(path.resolve("./dist/assets/api.html"))); + +// The latest release docs +// TODO OpenAPI isn't currently working for the latest docs. This can be changed after the next release. +// server.use("/api/latest", express.static(path.resolve("./dist/assets/api_latest.html"))); server.use( - "/lemmy-js-client-docs", - express.static(path.resolve("./dist/assets/lemmy-js-client-docs")), + "/api/latest", + express.static(path.resolve("./dist/assets/lemmy-js-client-latest-docs")), +); +server.use( + "/lemmy-js-client-docs/latest", + express.static(path.resolve("./dist/assets/lemmy-js-client-latest-docs")), +); + +// The Next release docs +server.use( + "/api/next", + express.static(path.resolve("./dist/assets/api_next.html")), +); +server.use( + "/lemmy-js-client-docs/next", + express.static(path.resolve("./dist/assets/lemmy-js-client-next-docs")), ); server.use( "/context.json",