Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- 이 PRμ—μ„œ 무엇이 λ°”λ€Œμ—ˆλŠ”μ§€ ν•œ 쀄 μš”μ•½ -->
Expand All @@ -42,10 +31,11 @@
-

## ⚠️ Impact
- [ ] No Breaking Changes
- [ ] Breaking Change
- [ ] Versioning 영ν–₯ 있음 (major / minor / patch)
- [ ] λ‚΄λΆ€ λ¦¬νŒ©ν† λ§λ§Œ 포함

- [ ] No Breaking Changes
- [ ] Breaking Change
- [ ] Versioning 영ν–₯ 있음 (major / minor / patch)
- [ ] λ‚΄λΆ€ λ¦¬νŒ©ν† λ§λ§Œ 포함

## βœ… Checklist

Expand Down
5 changes: 3 additions & 2 deletions packages/patchlogr-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
12 changes: 8 additions & 4 deletions packages/patchlogr-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from "commander";
import { runCanonicalize } from "./commands/runCanonicalize";

export function createCLI() {
const program = new Command();
Expand All @@ -10,25 +11,28 @@ 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("<api-docs>", "Path to the OpenAPI specification file")
.option("--canonicalize", "Canonicalize the OpenAPI specification")
.option(
"--skipValidation",
"Skip validation of the OpenAPI specification",
)
.option(
"-o, --output <file>",
"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;
}
});
Expand Down
24 changes: 21 additions & 3 deletions packages/patchlogr-cli/src/commands/runCanonicalize.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
}
3 changes: 2 additions & 1 deletion packages/patchlogr-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/patchlogr-oas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
},
"dependencies": {
"@apidevtools/swagger-parser": "^12.1.0",
"@patchlogr/types": "workspace:*"
"@patchlogr/types": "workspace:^"
}
}
8 changes: 4 additions & 4 deletions packages/patchlogr-oas/src/utils/toCanonicalSchema.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}
16 changes: 9 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -404,45 +404,47 @@ __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:
patchlogr: ./dist/index.js
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"
vitest: "npm:^4.0.16"
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"
vitest: "npm:^4.0.16"
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:
Expand Down
Loading