diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6aae5fb..5671cd4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,25 +8,14 @@ - [ ] @patchlogr/core - [ ] @patchlogr/cli -- [ ] @patchlogr/inspector - [ ] @patchlogr/oas +- [ ] @patchlogr/inspector - [ ] @patchlogr/types - [ ] docs, examples - [ ] tests - [ ] ci / cd / infra - [ ] other (아래에 명시) -## 📦 Scope - - -- [ ] @patchlogr/core -- [ ] @patchlogr/cli -- [ ] @patchlogr/inspector -- [ ] docs, examples -- [ ] tests -- [ ] ci / infra -- [ ] other (아래에 명시) - ## 📌 Summary @@ -42,10 +31,11 @@ - ## ⚠️ Impact -- [ ] No Breaking Changes -- [ ] Breaking Change -- [ ] Versioning 영향 있음 (major / minor / patch) -- [ ] 내부 리팩토링만 포함 + +- [ ] No Breaking Changes +- [ ] Breaking Change +- [ ] Versioning 영향 있음 (major / minor / patch) +- [ ] 내부 리팩토링만 포함 ## ✅ Checklist diff --git a/packages/patchlogr-cli/package.json b/packages/patchlogr-cli/package.json index 2d2bbaf..63ca214 100644 --- a/packages/patchlogr-cli/package.json +++ b/packages/patchlogr-cli/package.json @@ -19,13 +19,14 @@ "lint:fix": "eslint . --fix" }, "dependencies": { - "@patchlogr/core": "workspace:*", - "@patchlogr/oas": "workspace:*", + "@patchlogr/core": "workspace:^", + "@patchlogr/oas": "workspace:^", "commander": "^14.0.2" }, "devDependencies": { "@types/node": "24", "esbuild": "^0.27.2", + "openapi-types": "^12.1.3", "typescript": "^5.9.3", "vitest": "^4.0.16" } diff --git a/packages/patchlogr-cli/src/cli.ts b/packages/patchlogr-cli/src/cli.ts index bbcb1f2..8bc66cf 100644 --- a/packages/patchlogr-cli/src/cli.ts +++ b/packages/patchlogr-cli/src/cli.ts @@ -1,4 +1,5 @@ import { Command } from "commander"; +import { runCanonicalize } from "./commands/runCanonicalize"; export function createCLI() { const program = new Command(); @@ -10,12 +11,14 @@ export function createCLI() { program .command("help") - .description("Display help information about patchlogr commands"); + .description("Display help information about patchlogr commands") + .action(() => { + program.outputHelp(); + }); program .command("canonicalize") .argument("", "Path to the OpenAPI specification file") - .option("--canonicalize", "Canonicalize the OpenAPI specification") .option( "--skipValidation", "Skip validation of the OpenAPI specification", @@ -23,12 +26,13 @@ export function createCLI() { .option( "-o, --output ", "Write result to file instead of stdout (default: stdout)", + "stdout", ) .action(async (apiDocs, options) => { try { - console.log("[patchlogr] Processing:", apiDocs, options); + await runCanonicalize(apiDocs, options); } catch (error) { - console.error("[patchlogr] Error:", (error as Error).message); + console.error(error); process.exitCode = 1; } }); diff --git a/packages/patchlogr-cli/src/commands/runCanonicalize.ts b/packages/patchlogr-cli/src/commands/runCanonicalize.ts index 863fad5..03a7461 100644 --- a/packages/patchlogr-cli/src/commands/runCanonicalize.ts +++ b/packages/patchlogr-cli/src/commands/runCanonicalize.ts @@ -1,11 +1,29 @@ import { preprocessOASDocument } from "@patchlogr/oas"; import { type OASStageOptions } from "@patchlogr/oas"; +import type { OpenAPI } from "openapi-types"; +import fs from "fs/promises"; -export type RunCanonicalizeOptions = OASStageOptions; +export type RunCanonicalizeOptions = OASStageOptions & { + output?: "stdout" | string; +}; export async function runCanonicalize( - apiDocs: any, + apiDocs: OpenAPI.Document, options: RunCanonicalizeOptions, ) { - preprocessOASDocument(apiDocs, { ...options }); + const output = await preprocessOASDocument(apiDocs, { + skipValidation: !!options.skipValidation, + }); + + if (options.output === "stdout" || options.output === undefined) { + console.log(JSON.stringify(output, null, 2)); + } else { + try { + await fs.writeFile(options.output, JSON.stringify(output, null, 2)); + } catch (error) { + throw new Error(`Failed to write to file ${options.output}:`, { + cause: error, + }); + } + } } diff --git a/packages/patchlogr-core/package.json b/packages/patchlogr-core/package.json index 32d8182..f3278a9 100644 --- a/packages/patchlogr-core/package.json +++ b/packages/patchlogr-core/package.json @@ -27,7 +27,8 @@ }, "dependencies": { "@apidevtools/swagger-parser": "^12.1.0", - "@patchlogr/oas": "workspace:*" + "@patchlogr/oas": "workspace:^", + "@patchlogr/types": "workspace:^" }, "devDependencies": { "esbuild": "^0.27.2", diff --git a/packages/patchlogr-oas/package.json b/packages/patchlogr-oas/package.json index fadbdcd..44092ba 100644 --- a/packages/patchlogr-oas/package.json +++ b/packages/patchlogr-oas/package.json @@ -28,6 +28,6 @@ }, "dependencies": { "@apidevtools/swagger-parser": "^12.1.0", - "@patchlogr/types": "workspace:*" + "@patchlogr/types": "workspace:^" } } diff --git a/packages/patchlogr-oas/src/utils/toCanonicalSchema.ts b/packages/patchlogr-oas/src/utils/toCanonicalSchema.ts index 2b554d2..5ce992a 100644 --- a/packages/patchlogr-oas/src/utils/toCanonicalSchema.ts +++ b/packages/patchlogr-oas/src/utils/toCanonicalSchema.ts @@ -1,5 +1,4 @@ import { type CanonicalSchema } from "@patchlogr/types"; -import type { OpenAPIV2, OpenAPIV3 } from "openapi-types"; import type { OpenAPISchemaObject } from "../guards/schemaGuards"; import { isSchemaObject, isOpenAPIV3Schema } from "../guards/schemaGuards"; import { toCanonicalSchemaV2 } from "./toCanonicalSchemaV2"; @@ -15,7 +14,8 @@ export function toCanonicalSchema( return schema || {}; } - if (isOpenAPIV3Schema(schema)) - return toCanonicalSchemaV3(schema as OpenAPIV3.SchemaObject); - return toCanonicalSchemaV2(schema as OpenAPIV2.SchemaObject); + if (isOpenAPIV3Schema(schema)) { + return toCanonicalSchemaV3(schema); + } + return toCanonicalSchemaV2(schema); } diff --git a/yarn.lock b/yarn.lock index 1770674..3f3c5a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -404,11 +404,12 @@ __metadata: version: 0.0.0-use.local resolution: "@patchlogr/cli@workspace:packages/patchlogr-cli" dependencies: - "@patchlogr/core": "workspace:*" - "@patchlogr/oas": "workspace:*" + "@patchlogr/core": "workspace:^" + "@patchlogr/oas": "workspace:^" "@types/node": "npm:24" commander: "npm:^14.0.2" esbuild: "npm:^0.27.2" + openapi-types: "npm:^12.1.3" typescript: "npm:^5.9.3" vitest: "npm:^4.0.16" bin: @@ -416,12 +417,13 @@ __metadata: languageName: unknown linkType: soft -"@patchlogr/core@workspace:*, @patchlogr/core@workspace:packages/patchlogr-core": +"@patchlogr/core@workspace:^, @patchlogr/core@workspace:packages/patchlogr-core": version: 0.0.0-use.local resolution: "@patchlogr/core@workspace:packages/patchlogr-core" dependencies: "@apidevtools/swagger-parser": "npm:^12.1.0" - "@patchlogr/oas": "workspace:*" + "@patchlogr/oas": "workspace:^" + "@patchlogr/types": "workspace:^" esbuild: "npm:^0.27.2" openapi-types: "npm:^12.1.3" typescript: "npm:^5.9.3" @@ -429,12 +431,12 @@ __metadata: languageName: unknown linkType: soft -"@patchlogr/oas@workspace:*, @patchlogr/oas@workspace:packages/patchlogr-oas": +"@patchlogr/oas@workspace:^, @patchlogr/oas@workspace:packages/patchlogr-oas": version: 0.0.0-use.local resolution: "@patchlogr/oas@workspace:packages/patchlogr-oas" dependencies: "@apidevtools/swagger-parser": "npm:^12.1.0" - "@patchlogr/types": "workspace:*" + "@patchlogr/types": "workspace:^" "@types/node": "npm:24" esbuild: "npm:^0.27.2" openapi-types: "npm:^12.1.3" @@ -442,7 +444,7 @@ __metadata: languageName: unknown linkType: soft -"@patchlogr/types@workspace:*, @patchlogr/types@workspace:packages/patchlogr-types": +"@patchlogr/types@workspace:^, @patchlogr/types@workspace:packages/patchlogr-types": version: 0.0.0-use.local resolution: "@patchlogr/types@workspace:packages/patchlogr-types" dependencies: