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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions src/codegen/swagger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>) =>
Expand Down
Loading