Skip to content

Commit cede766

Browse files
committed
feat: add quotes to yaml output
1 parent 35d27ad commit cede766

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@
3636
"@remix-run/headers": "^0.16.0",
3737
"decompress": "^4.0.0",
3838
"hono": "^4.10.6",
39+
"js-yaml": "^4.1.1",
3940
"zod": "^4.0.0"
4041
},
4142
"devDependencies": {
4243
"@types/decompress": "^4.0.0",
44+
"@types/js-yaml": "^4.0.9",
4345
"@types/node": "^22.0.0",
4446
"@typescript/native-preview": "^7.0.0-dev.20251024.1",
4547
"@vitest/coverage-v8": "^3.2.4",
4648
"glob": "^10.0.0",
47-
"js-yaml": "^4.1.1",
4849
"oxlint": "^1.24.0",
4950
"oxlint-tsgolint": "^0.3.0",
5051
"prettier": "^3.6.2",

packages/core/scripts/gen-openapi-spec-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function generateOpenApiSpecFiles(
1212
const outputYAMLFilepath = "./dist/openapi.yaml";
1313

1414
const specJSONContent = JSON.stringify(spec, null, 2);
15-
const specYAMLContent = YAML.dump(spec);
15+
const specYAMLContent = YAML.dump(spec, { forceQuotes: true });
1616

1717
await Promise.allSettled([
1818
writeFile(outputJSONFilepath, specJSONContent, { encoding: "utf8" }),

packages/core/scripts/post-build.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ import { updateDenoJsonToMatchPkgJson } from "../../../scripts/jsr-utils.ts";
44
import { generateOpenApiSpecFiles } from "./gen-openapi-spec-files.ts";
55

66
export async function postBuildSuccess(config: ResolvedOptions): Promise<void> {
7-
const { appRouter } = await import("../dist/router.js");
8-
const { SERVICE_NAME } = await import("../dist/index.js");
9-
const pkgJson = await import("../package.json", { with: { type: "json" } });
10-
7+
const { appRouter, openapiConfig } = await import("../dist/router.js");
118
await generateOpenApiSpecFiles(
129
config,
13-
(appRouter as OpenAPIHono).getOpenAPI31Document({
14-
info: { title: SERVICE_NAME, version: pkgJson.default.version },
15-
openapi: "3.1.0",
16-
}),
10+
(appRouter as OpenAPIHono).getOpenAPI31Document(openapiConfig),
1711
);
1812

1913
await updateDenoJsonToMatchPkgJson(config);

packages/core/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { OpenAPIHono } from "@hono/zod-openapi";
22
import { SuperHeaders } from "@remix-run/headers";
33
import { logger as loggerMiddleware } from "hono/logger";
4-
import pkgJson from "../package.json" with { type: "json" };
54
import type { AuthAdapter, StoryBookerUser } from "./adapters";
65
import { handlePurge, type HandlePurge } from "./handlers/handle-purge";
76
import { appRouter } from "./routers/_app-router";
@@ -10,7 +9,7 @@ import type {
109
RequestHandler,
1110
RequestHandlerOptions,
1211
} from "./types";
13-
import { DEFAULT_LOCALE, SERVICE_NAME } from "./utils/constants";
12+
import { DEFAULT_LOCALE } from "./utils/constants";
1413
import { parseErrorMessage } from "./utils/error";
1514
import { localStore } from "./utils/store";
1615

@@ -37,10 +36,6 @@ export function createRequestHandler<User extends StoryBookerUser>(
3736
]);
3837

3938
const router = new OpenAPIHono({ strict: false })
40-
.doc31("/openapi.json", {
41-
openapi: "3.1.0",
42-
info: { version: pkgJson.version, title: SERVICE_NAME },
43-
})
4439
.use(loggerMiddleware(), ...(options.config?.middlewares || []))
4540
.route("/", appRouter);
4641

packages/core/src/routers/_app-router.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { swaggerUI } from "@hono/swagger-ui";
22
import { OpenAPIHono } from "@hono/zod-openapi";
3+
import YAML from "js-yaml";
4+
import pkgJson from "../../package.json" with { type: "json" };
5+
import { SERVICE_NAME } from "../utils/constants";
36
import { getStore } from "../utils/store";
47
import { createUIAdapterOptions } from "../utils/ui-utils";
58
import { accountRouter } from "./account-router";
@@ -9,15 +12,26 @@ import { rootRouter } from "./root-router";
912
import { tagsRouter } from "./tags-router";
1013
import { tasksRouter } from "./tasks-router";
1114

15+
export const openapiConfig = {
16+
openapi: "3.1.0",
17+
info: { version: pkgJson.version, title: SERVICE_NAME },
18+
};
19+
1220
export type AppRouter = typeof appRouter;
1321
export const appRouter = new OpenAPIHono({ strict: false })
22+
.doc31("/openapi.json", openapiConfig)
23+
.get("/openapi.yaml", (ctx) => {
24+
const spec = (appRouter as OpenAPIHono).getOpenAPI31Document(openapiConfig);
25+
const content: string = YAML.dump(spec, { forceQuotes: true });
26+
return ctx.body(content, 200, { "Content-Type": "application/yaml" });
27+
})
28+
.get("/openapi", swaggerUI({ url: "/openapi.json" }))
1429
.route("/", rootRouter)
1530
.route("/", projectsRouter)
1631
.route("/", buildsRouter)
1732
.route("/", tagsRouter)
1833
.route("/tasks", tasksRouter)
1934
.route("/account", accountRouter)
20-
.get("/openapi", swaggerUI({ url: "/openapi.json" }))
2135
.get("/:filepath{.+}", async (context) => {
2236
const { ui } = getStore();
2337
if (!ui?.handleUnhandledRoute) {

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7046,6 +7046,7 @@ __metadata:
70467046
"@hono/zod-openapi": "npm:^1.1.5"
70477047
"@remix-run/headers": "npm:^0.16.0"
70487048
"@types/decompress": "npm:^4.0.0"
7049+
"@types/js-yaml": "npm:^4.0.9"
70497050
"@types/node": "npm:^22.0.0"
70507051
"@typescript/native-preview": "npm:^7.0.0-dev.20251024.1"
70517052
"@vitest/coverage-v8": "npm:^3.2.4"
@@ -7885,6 +7886,13 @@ __metadata:
78857886
languageName: node
78867887
linkType: hard
78877888

7889+
"@types/js-yaml@npm:^4.0.9":
7890+
version: 4.0.9
7891+
resolution: "@types/js-yaml@npm:4.0.9"
7892+
checksum: 10c0/24de857aa8d61526bbfbbaa383aa538283ad17363fcd5bb5148e2c7f604547db36646440e739d78241ed008702a8920665d1add5618687b6743858fae00da211
7893+
languageName: node
7894+
linkType: hard
7895+
78887896
"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.15, @types/json-schema@npm:^7.0.8, @types/json-schema@npm:^7.0.9":
78897897
version: 7.0.15
78907898
resolution: "@types/json-schema@npm:7.0.15"

0 commit comments

Comments
 (0)