diff --git a/CHANGELOG.md b/CHANGELOG.md index efebd61..b49478d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ Every entry says what changed as a caller sees it, why, and what to watch for ## Unreleased +### Changed — may break callers + +- **`names: { fromPath: true }` names a GET of a path ending in `/me` as one item, `-get`, not `-list`.** Notion's + `GET /v1/users/me` was `users-me-list` and is now `users-me-get`; a CLI that regenerates on this version renames that + command. Watch for: a path whose last fixed word follows a parameter (`/pages/{id}/markdown`) is still named + `-list`, since the path alone cannot tell it from a real list (`/blocks/{id}/children`); name it in `commands`. + ### Added - **A GraphQL API generates its `api` group too.** `adaptGraphql` reads an introspection result into the model: one diff --git a/src/codegen/pipeline.ts b/src/codegen/pipeline.ts index 0a2c20b..03512c1 100644 --- a/src/codegen/pipeline.ts +++ b/src/codegen/pipeline.ts @@ -79,7 +79,7 @@ const commandFromPath = (operation: ApiOperation, all: readonly ApiOperation[], (other.binding.path.startsWith(`${path}/{`) && !other.binding.path.slice(path.length + 1).includes("/"))), ) const verb = { - GET: onItem ? "get" : "list", + GET: onItem || parts.at(-1) === "me" ? "get" : "list", HEAD: "head", DELETE: "delete", PATCH: "update", diff --git a/src/codegen/swagger.test.ts b/src/codegen/swagger.test.ts index 30ef41a..5d1dc23 100644 --- a/src/codegen/swagger.test.ts +++ b/src/codegen/swagger.test.ts @@ -153,6 +153,28 @@ describe("command names and spec patches", () => { expect(commands).toEqual(["deals-list", "deals-create", "deals-get", "deals-delete", "deals-archive-batch"]) }) + it("names a read of `/me` as one item, not a list", () => { + const notion = { + openapi: "3.1.0", + info: { version: "1" }, + paths: { + "/v1/users": { get: { operationId: "get-users" } }, + "/v1/users/me": { get: { operationId: "get-self" } }, + "/v1/blocks/{block_id}/children": { + parameters: [{ name: "block_id", in: "path", required: true, schema: { type: "string" } }], + get: { operationId: "get-block-children" }, + }, + }, + components: { schemas: {} }, + } + const [manifest] = generate(adaptOpenApi(notion), [manifestGenerator({ path: "manifest.ts" })], { + banner: [], + names: { fromPath: true }, + }) + const commands = [...(manifest?.content.matchAll(/"command": "([^"]+)"/g) ?? [])].map(([, command]) => command) + expect(commands).toEqual(["users-list", "users-me-get", "blocks-children-list"]) + }) + it("refuses a name for an unknown operation or one that is not kebab case", () => { const { document } = patchSpec(hubspot, { stubMissingSchemas: "missing" }) const run = (commands: Record) =>