@wirecat/cli-base 0.114.0 → 0.115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,26 @@ Versions before 0.8.0 are in the [git tags](https://github.com/WireCatLabs/cli-b
8
8
  Every entry says what changed as a caller sees it, why, and what to watch for — the rules are
9
9
  [`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog).
10
10
 
11
+ ## 0.115.0 — 17.11.2026
12
+
13
+ ### Added
14
+
15
+ - **A GraphQL API generates its `api` group too.** `adaptGraphql` reads an introspection result into the model: one
16
+ operation per `Query` and `Mutation` field, with a new `graphql` binding (the field, its variables' GraphQL types and
17
+ a default selection), its arguments as body flags, a Relay connection paged as `cursor`, and `*Delete`/`*Archive`
18
+ mutations as deletes. `syncGraphql` and `readGraphql` keep the snapshot with its hash, `graphqlDocument` builds the
19
+ request, and `graphqlFake` is a strict fake for tests. Watch for: `Binding` has a third member, so code that reads
20
+ `binding.name` once a binding is not `http` must narrow to `rpc`; `bindingLabel` names any binding. See the
21
+ [reference](docs/REFERENCE.md). For the Linear pilot.
22
+
23
+ ### Fixed
24
+
25
+ - **`generate` with `auth` signs in an operation whose spec says `security: []`**, the same as one with no
26
+ `security`. Before, the empty list stayed, cli-core read it as "no sign-in", and the call went out without the key:
27
+ HubSpot's object specs mark 115 calls so, and each answered 401. An operation keeps its own `security` only when
28
+ it signs in by `auth`'s schemes. A CLI that drops an empty `security` from the generated manifest at runtime can
29
+ stop once it regenerates on this version.
30
+
11
31
  ## 0.114.0 — 17.11.2026
12
32
 
13
33
  ### Added
@@ -0,0 +1,55 @@
1
+ /**
2
+ * A strict fake of a GraphQL service, built from the files `generate` wrote, in the spirit of `fakeApi`: a `fetch` that
3
+ * takes only a POST of a document `graphqlDocument` builds for an operation the manifest has, refuses a selection
4
+ * field the type lacks, variables that break their schema and a missing sign-in, and answers `data.<field>` within
5
+ * the selection. A test writes only its scenarios; one that answers outside the schema or the selection throws.
6
+ */
7
+ import { type Selection } from "./graphql.js";
8
+ import type { ManifestOperation } from "./manifest.js";
9
+ import type { SchemaNode } from "./model.js";
10
+ type Definitions = Readonly<Record<string, SchemaNode>>;
11
+ export interface GraphqlFakeCall {
12
+ /** The matched operation's id; absent when the request matched none. */
13
+ operation?: string;
14
+ query: string;
15
+ selection?: Selection;
16
+ variables: Readonly<Record<string, unknown>>;
17
+ headers: Headers;
18
+ }
19
+ /** `data` is the field's answer; `errors` are sent as GraphQL's, with HTTP 200 unless `status` says otherwise. */
20
+ export interface GraphqlFakeAnswer {
21
+ status?: number;
22
+ data?: unknown;
23
+ errors?: readonly {
24
+ message: string;
25
+ extensions?: Readonly<Record<string, unknown>>;
26
+ }[];
27
+ headers?: Readonly<Record<string, string>>;
28
+ }
29
+ type Answering = (call: GraphqlFakeCall) => GraphqlFakeAnswer | Promise<GraphqlFakeAnswer>;
30
+ export interface GraphqlFakeOptions {
31
+ operations: readonly ManifestOperation[];
32
+ definitions: Definitions;
33
+ /** The endpoint: `https://api.linear.app/graphql`. */
34
+ url: string;
35
+ /** The header and value every call must carry: `{ header: "Authorization", value: "<key>" }`. */
36
+ auth?: {
37
+ header: string;
38
+ value: string;
39
+ };
40
+ /** Answers by operation id; one without an answer gets a sample of its selection. */
41
+ answers?: Readonly<Record<string, Answering>>;
42
+ }
43
+ export interface GraphqlFake {
44
+ fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
45
+ calls: GraphqlFakeCall[];
46
+ /** Why each refused call was refused; a test that expects none asserts this is empty. */
47
+ refusals: string[];
48
+ }
49
+ /**
50
+ * Every field the selection names that the type lacks, a leaf asked without a selection, or an object asked with one.
51
+ * On a union only `__typename` is selectable: its members' fields need fragments, which a selection here never has.
52
+ */
53
+ export declare const selectionProblems: (selection: Selection, node: SchemaNode, definitions: Definitions, where?: string) => string[];
54
+ export declare const graphqlFake: (options: GraphqlFakeOptions) => GraphqlFake;
55
+ export {};
@@ -0,0 +1,187 @@
1
+ /**
2
+ * A strict fake of a GraphQL service, built from the files `generate` wrote, in the spirit of `fakeApi`: a `fetch` that
3
+ * takes only a POST of a document `graphqlDocument` builds for an operation the manifest has, refuses a selection
4
+ * field the type lacks, variables that break their schema and a missing sign-in, and answers `data.<field>` within
5
+ * the selection. A test writes only its scenarios; one that answers outside the schema or the selection throws.
6
+ */
7
+ import { sampleOf, schemaProblems } from "./fake.js";
8
+ import { graphqlDocument, parseSelection } from "./graphql.js";
9
+ import { identifier } from "./names.js";
10
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
11
+ /** What a selection walks into, through references, lists and a nullable wrapper: an object, a union or a leaf. */
12
+ const shapeOf = (node, definitions, depth = 0) => {
13
+ if (depth > 20)
14
+ return { kind: "leaf" };
15
+ switch (node.type) {
16
+ case "ref": {
17
+ const target = definitions[identifier(node.ref)];
18
+ return target ? shapeOf(target, definitions, depth + 1) : { kind: "leaf" };
19
+ }
20
+ case "array":
21
+ return shapeOf(node.items, definitions, depth + 1);
22
+ case "allOf": {
23
+ const objects = node.of.flatMap((one) => {
24
+ const inner = shapeOf(one, definitions, depth + 1);
25
+ return inner.kind === "object" ? inner.objects : [];
26
+ });
27
+ return objects.length > 0 ? { kind: "object", objects } : { kind: "leaf" };
28
+ }
29
+ case "union":
30
+ return { kind: "union" };
31
+ case "object":
32
+ return { kind: "object", objects: [node] };
33
+ default:
34
+ return { kind: "leaf" };
35
+ }
36
+ };
37
+ /**
38
+ * Every field the selection names that the type lacks, a leaf asked without a selection, or an object asked with one.
39
+ * On a union only `__typename` is selectable: its members' fields need fragments, which a selection here never has.
40
+ */
41
+ export const selectionProblems = (selection, node, definitions, where = "selection") => {
42
+ const shape = shapeOf(node, definitions);
43
+ if (shape.kind === "leaf")
44
+ return [`${where}: a scalar has no fields to select`];
45
+ return Object.entries(selection).flatMap(([name, inner]) => {
46
+ if (name === "__typename")
47
+ return inner === true ? [] : [`${where}.__typename: a scalar has no fields to select`];
48
+ if (shape.kind === "union")
49
+ return [`${where}.${name}: a union takes only __typename`];
50
+ const property = shape.objects.map((one) => one.properties[name]).find(Boolean);
51
+ if (!property)
52
+ return [`${where}.${name}: no such field`];
53
+ const leaf = shapeOf(property, definitions).kind === "leaf";
54
+ if (inner === true)
55
+ return leaf ? [] : [`${where}.${name}: an object needs a selection`];
56
+ return selectionProblems(inner, property, definitions, `${where}.${name}`);
57
+ });
58
+ };
59
+ /** Every field of the answer outside the selection. */
60
+ const outside = (value, selection, where) => {
61
+ if (Array.isArray(value))
62
+ return value.flatMap((one, index) => outside(one, selection, `${where}[${index}]`));
63
+ if (!isObject(value))
64
+ return [];
65
+ return Object.entries(value).flatMap(([name, inner]) => {
66
+ const asked = selection[name];
67
+ if (asked === undefined)
68
+ return [`${where}.${name}: not selected`];
69
+ return asked === true ? [] : outside(inner, asked, `${where}.${name}`);
70
+ });
71
+ };
72
+ /** A value of the type with only the selected fields. */
73
+ const sampleWithin = (node, selection, definitions) => {
74
+ if (selection === true)
75
+ return sampleOf(node, definitions);
76
+ if (node.type === "ref") {
77
+ const target = definitions[identifier(node.ref)];
78
+ return target ? sampleWithin(target, selection, definitions) : null;
79
+ }
80
+ if (node.type === "array")
81
+ return [sampleWithin(node.items, selection, definitions)];
82
+ const shape = shapeOf(node, definitions);
83
+ const objects = shape.kind === "object" ? shape.objects : [];
84
+ return Object.fromEntries(Object.entries(selection).map(([name, inner]) => [
85
+ name,
86
+ name === "__typename"
87
+ ? "Object"
88
+ : sampleWithin(objects.map((one) => one.properties[name]).find(Boolean) ?? { type: "unknown" }, inner, definitions),
89
+ ]));
90
+ };
91
+ const json = (status, body, headers = {}) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json", ...headers } });
92
+ /** The selection inside a document built for `binding`, or `undefined` when it was not built so. */
93
+ const selectionIn = (binding, query) => {
94
+ const marker = "\u0000";
95
+ const [head = "", tail = ""] = graphqlDocument(binding, marker).split(marker);
96
+ if (query === graphqlDocument(binding, ""))
97
+ return "";
98
+ if (!query.startsWith(head) || !query.endsWith(tail) || query.length < head.length + tail.length)
99
+ return undefined;
100
+ return query.slice(head.length, query.length - tail.length);
101
+ };
102
+ export const graphqlFake = (options) => {
103
+ const calls = [];
104
+ const refusals = [];
105
+ const { definitions } = options;
106
+ const endpoint = new URL(options.url).href;
107
+ const refuse = (status, problems) => {
108
+ for (const problem of problems)
109
+ refusals.push(problem);
110
+ return json(status, { errors: problems.map((message) => ({ message, extensions: { code: "FAKE_REFUSED" } })) });
111
+ };
112
+ const graphql = options.operations.filter((one) => one.binding.kind === "graphql");
113
+ const fetch = async (input, init) => {
114
+ const request = new Request(input, init);
115
+ let body;
116
+ try {
117
+ body = JSON.parse(await request.text());
118
+ }
119
+ catch {
120
+ body = undefined;
121
+ }
122
+ const query = isObject(body) && typeof body.query === "string" ? body.query : "";
123
+ const variables = isObject(body) && isObject(body.variables) ? body.variables : {};
124
+ const call = { query, variables, headers: request.headers };
125
+ calls.push(call);
126
+ if (request.url !== endpoint)
127
+ return refuse(404, [`${request.url} is not ${endpoint}`]);
128
+ if (request.method !== "POST")
129
+ return refuse(405, [`a GraphQL call is a POST, not ${request.method}`]);
130
+ if (!query)
131
+ return refuse(400, ["the body is not JSON with a query"]);
132
+ if (options.auth && request.headers.get(options.auth.header) !== options.auth.value)
133
+ return refuse(401, [`no ${options.auth.header} header with the expected sign-in`]);
134
+ const found = graphql
135
+ .map((operation) => ({ operation, text: selectionIn(operation.binding, query) }))
136
+ .find((one) => one.text !== undefined);
137
+ if (!found)
138
+ return refuse(400, [`no operation of the manifest builds the document: ${query.slice(0, 120)}`]);
139
+ const { operation } = found;
140
+ call.operation = operation.id;
141
+ const response = operation.response?.schema ? definitions[operation.response.schema] : undefined;
142
+ let selection = {};
143
+ const parseProblems = [];
144
+ try {
145
+ selection = parseSelection(found.text ?? "");
146
+ call.selection = selection;
147
+ }
148
+ catch (error) {
149
+ parseProblems.push(`${operation.id}: ${error.message}`);
150
+ }
151
+ const variablesSchema = operation.request?.schema ? definitions[operation.request.schema] : undefined;
152
+ const problems = [
153
+ ...parseProblems,
154
+ ...(response && found.text ? selectionProblems(selection, response, definitions, operation.id) : []),
155
+ ...(response && !found.text && shapeOf(response, definitions).kind !== "leaf"
156
+ ? [`${operation.id}: an object needs a selection`]
157
+ : []),
158
+ ...(variablesSchema
159
+ ? schemaProblems(variables, variablesSchema, definitions, "variables")
160
+ : Object.keys(variables).map((name) => `${operation.id}: takes no argument "${name}"`)),
161
+ ];
162
+ if (problems.length > 0)
163
+ return refuse(400, problems);
164
+ const answering = options.answers?.[operation.id];
165
+ if (!answering) {
166
+ const data = response
167
+ ? found.text
168
+ ? sampleWithin(response, selection, definitions)
169
+ : sampleOf(response, definitions)
170
+ : null;
171
+ return json(200, { data: { [operation.binding.field]: data } });
172
+ }
173
+ const { status = 200, data, errors, headers } = await answering(call);
174
+ if (errors?.length)
175
+ return json(status, { data: null, errors }, headers);
176
+ if (status >= 200 && status < 300 && response && data !== undefined) {
177
+ const wrong = [
178
+ ...schemaProblems(data, response, definitions, "answer"),
179
+ ...(found.text ? outside(data, selection, "answer") : []),
180
+ ];
181
+ if (wrong.length > 0)
182
+ throw new Error(`the answer for ${operation.id} breaks its schema or selection: ${wrong.join("; ")}`);
183
+ }
184
+ return json(status, { data: { [operation.binding.field]: data ?? null } }, headers);
185
+ };
186
+ return { fetch, calls, refusals };
187
+ };
@@ -0,0 +1,53 @@
1
+ import type { ApiModel, GraphqlBinding, SchemaNode } from "./model.js";
2
+ export interface GraphqlOptions {
3
+ /** The endpoint every operation is sent to: `https://api.linear.app/graphql`. */
4
+ url: string;
5
+ /**
6
+ * The schema's own scalars, each as the JSON value it travels as: `{ DateTime: { type: "string" }, JSON: { type:
7
+ * "unknown" } }`. A scalar the schema uses that is not here stops generation: its shape is never guessed.
8
+ */
9
+ scalars?: Readonly<Record<string, SchemaNode>>;
10
+ /**
11
+ * Fields of `Query` or `Mutation` left out, each with the reason: by name, or as `query.<name>` or `mutation.<name>`
12
+ * when both roots have one of that name. One that matches no field stops generation.
13
+ */
14
+ exclude?: Readonly<Record<string, string>>;
15
+ sourceUrl?: string;
16
+ sourceRevision?: string;
17
+ }
18
+ export declare const GRAPHQL_DELETE_REASON = "a mutation whose name ends in Delete or Archive deletes";
19
+ /** Builds the one document an operation sends: every variable declared and passed, the selection inside. */
20
+ export declare const graphqlDocument: (binding: GraphqlBinding, selection?: string) => string;
21
+ /** A selection as a tree: a field's name → its own selection, or `true` for a leaf. */
22
+ export interface Selection {
23
+ readonly [field: string]: Selection | true;
24
+ }
25
+ /**
26
+ * `id title state { id type }` → its tree. Only names and braces: an argument, an alias, a fragment or a directive
27
+ * throws, since nothing here can check one.
28
+ */
29
+ export declare const parseSelection: (text: string) => Selection;
30
+ export declare const adaptGraphql: (introspection: unknown, options: GraphqlOptions) => ApiModel;
31
+ /** The standard introspection query, deep enough for `[[Type!]!]!`. */
32
+ export declare const INTROSPECTION_QUERY = "query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n types {\n kind name description\n fields(includeDeprecated: true) { name description isDeprecated args { ...InputValue } type { ...TypeRef } }\n inputFields { ...InputValue }\n enumValues(includeDeprecated: true) { name }\n possibleTypes { name }\n }\n }\n}\nfragment InputValue on __InputValue { name description defaultValue type { ...TypeRef } }\nfragment TypeRef on __Type {\n kind name\n ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }\n}";
33
+ export interface GraphqlProvenance {
34
+ source: string;
35
+ /** Of the committed file; `readGraphql` refuses a snapshot that no longer matches it. */
36
+ sha256: string;
37
+ retrieved_at: string;
38
+ normalization: string;
39
+ }
40
+ /**
41
+ * Asks `url` for its schema and writes `schema.json` and `provenance.json` to `dir`. Run by hand, then review the diff:
42
+ * the build never fetches. Types are sorted by name so a reordered answer is no diff. `headers` is for a service that
43
+ * answers introspection only when signed in; nothing of them is written.
44
+ */
45
+ export declare const syncGraphql: (options: {
46
+ url: string;
47
+ dir: string;
48
+ fetch?: typeof globalThis.fetch;
49
+ headers?: Readonly<Record<string, string>>;
50
+ now?: Date;
51
+ }) => Promise<GraphqlProvenance>;
52
+ /** The snapshot `syncGraphql` wrote, parsed. Throws if its hash changed. */
53
+ export declare const readGraphql: (dir: string) => unknown;
@@ -0,0 +1,379 @@
1
+ /**
2
+ * A GraphQL schema's introspection result, already parsed → the format-neutral `ApiModel`, plus the offline snapshot
3
+ * it comes from: `syncGraphql` asks the endpoint for its schema with the standard introspection query and records
4
+ * where it came from, and `readGraphql` loads it back only while its hash still matches.
5
+ *
6
+ * One field of `Query` or `Mutation` is one operation. Its arguments are the request body (the variables), each also a
7
+ * flag; its answer is `data.<field>`, typed by the field's type. A query reads; a mutation writes, and one whose name
8
+ * ends in `Delete` or `Archive` deletes. A Relay connection pages as a `cursor`: `after`, `pageInfo.endCursor`.
9
+ * SDL is not read: that needs graphql-js, and codegen adds no runtime dependency.
10
+ */
11
+ import { createHash } from "node:crypto";
12
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
13
+ import { join } from "node:path";
14
+ import { CodegenError } from "./pipeline.js";
15
+ const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
16
+ const BUILT_IN = {
17
+ String: { type: "string" },
18
+ ID: { type: "string" },
19
+ Int: { type: "integer", format: "int32" },
20
+ Float: { type: "number" },
21
+ Boolean: { type: "boolean" },
22
+ };
23
+ const DELETES = /(Delete|Archive)$/;
24
+ const UNDOES = /Unarchive$/;
25
+ export const GRAPHQL_DELETE_REASON = "a mutation whose name ends in Delete or Archive deletes";
26
+ /** `[ID!]!` from its introspection reference. */
27
+ const typeText = (ref) => ref.kind === "NON_NULL" && ref.ofType
28
+ ? `${typeText(ref.ofType)}!`
29
+ : ref.kind === "LIST" && ref.ofType
30
+ ? `[${typeText(ref.ofType)}]`
31
+ : String(ref.name);
32
+ const named = (ref) => (ref.ofType ? named(ref.ofType) : String(ref.name));
33
+ /** Builds the one document an operation sends: every variable declared and passed, the selection inside. */
34
+ export const graphqlDocument = (binding, selection = binding.selection) => {
35
+ const variables = Object.entries(binding.variables);
36
+ const declared = variables.length ? `(${variables.map(([name, type]) => `$${name}: ${type}`).join(", ")})` : "";
37
+ const passed = variables.length ? `(${variables.map(([name]) => `${name}: $${name}`).join(", ")})` : "";
38
+ const inner = selection.trim() ? ` { ${selection.trim()} }` : "";
39
+ return `${binding.operation} ${binding.field[0]?.toUpperCase()}${binding.field.slice(1)}${declared} { ${binding.field}${passed}${inner} }`;
40
+ };
41
+ /**
42
+ * `id title state { id type }` → its tree. Only names and braces: an argument, an alias, a fragment or a directive
43
+ * throws, since nothing here can check one.
44
+ */
45
+ export const parseSelection = (text) => {
46
+ const tokens = text.match(/[_A-Za-z][_0-9A-Za-z]*|[{}]|\S/g) ?? [];
47
+ let at = 0;
48
+ const level = (nested) => {
49
+ const fields = {};
50
+ while (at < tokens.length) {
51
+ const token = tokens[at];
52
+ if (token === "}") {
53
+ if (!nested)
54
+ throw new Error(`selection "${text}": an unmatched }`);
55
+ at += 1;
56
+ return fields;
57
+ }
58
+ if (!/^[_A-Za-z]/.test(token))
59
+ throw new Error(`selection "${text}": "${token}" — only field names and braces are supported`);
60
+ at += 1;
61
+ if (tokens[at] === "{") {
62
+ at += 1;
63
+ const inner = level(true);
64
+ if (Object.keys(inner).length === 0)
65
+ throw new Error(`selection "${text}": ${token} selects nothing`);
66
+ fields[token] = inner;
67
+ }
68
+ else
69
+ fields[token] = true;
70
+ }
71
+ if (nested)
72
+ throw new Error(`selection "${text}": a { is not closed`);
73
+ return fields;
74
+ };
75
+ return level(false);
76
+ };
77
+ const schemaOf = (raw) => {
78
+ const root = object(raw) && object(raw.data) ? raw.data : raw;
79
+ if (!object(root) || !object(root.__schema))
80
+ throw new CodegenError(["not a GraphQL introspection result: no __schema"]);
81
+ return root.__schema;
82
+ };
83
+ export const adaptGraphql = (introspection, options) => {
84
+ const schema = schemaOf(introspection);
85
+ const types = new Map();
86
+ for (const type of Array.isArray(schema.types) ? schema.types : [])
87
+ if (object(type) && typeof type.name === "string" && !type.name.startsWith("__"))
88
+ types.set(type.name, type);
89
+ const rootName = (key) => {
90
+ const root = schema[key];
91
+ return object(root) && typeof root.name === "string" ? root.name : undefined;
92
+ };
93
+ const scalars = { ...BUILT_IN, ...options.scalars };
94
+ const unknownScalars = [...types.values()]
95
+ .filter((type) => type.kind === "SCALAR" && !scalars[type.name])
96
+ .map((type) => `scalar ${type.name}: map it in scalars, as the JSON value it travels as`);
97
+ if (unknownScalars.length > 0)
98
+ throw new CodegenError(unknownScalars);
99
+ const described = (text) => (text ? { description: text } : {});
100
+ const reference = (ref, where) => {
101
+ if (ref.kind === "NON_NULL" && ref.ofType) {
102
+ const { nullable: _, ...inner } = reference(ref.ofType, where);
103
+ return inner;
104
+ }
105
+ if (ref.kind === "LIST" && ref.ofType)
106
+ return { type: "array", items: reference(ref.ofType, where), nullable: true };
107
+ const name = String(ref.name);
108
+ const type = types.get(name);
109
+ if (!type)
110
+ throw new CodegenError([`${where}: the schema has no type ${name}`]);
111
+ if (type.kind === "SCALAR")
112
+ return { ...scalars[name], nullable: true };
113
+ return { type: "ref", ref: name, nullable: true };
114
+ };
115
+ const schemas = [];
116
+ for (const type of types.values()) {
117
+ const where = `type ${type.name}`;
118
+ const common = described(type.description);
119
+ switch (type.kind) {
120
+ case "SCALAR":
121
+ break;
122
+ case "ENUM":
123
+ schemas.push({
124
+ id: type.name,
125
+ schema: { ...common, type: "string", enum: (type.enumValues ?? []).map((one) => one.name) },
126
+ });
127
+ break;
128
+ case "OBJECT":
129
+ case "INTERFACE":
130
+ // A selection asks for some of the fields, so none is required in an answer.
131
+ schemas.push({
132
+ id: type.name,
133
+ schema: {
134
+ ...common,
135
+ type: "object",
136
+ properties: Object.fromEntries((type.fields ?? []).map((field) => [
137
+ field.name,
138
+ { ...reference(field.type, `${where}.${field.name}`), ...described(field.description) },
139
+ ])),
140
+ required: [],
141
+ },
142
+ });
143
+ break;
144
+ case "UNION":
145
+ schemas.push({
146
+ id: type.name,
147
+ schema: {
148
+ ...common,
149
+ type: "union",
150
+ of: (type.possibleTypes ?? []).map((one) => ({ type: "ref", ref: one.name })),
151
+ },
152
+ });
153
+ break;
154
+ case "INPUT_OBJECT":
155
+ schemas.push({ id: type.name, schema: { ...common, ...inputObject(type.inputFields ?? [], where) } });
156
+ break;
157
+ default:
158
+ throw new CodegenError([`${where}: unsupported kind ${type.kind}`]);
159
+ }
160
+ }
161
+ function inputObject(values, where) {
162
+ return {
163
+ type: "object",
164
+ properties: Object.fromEntries(values.map((one) => [
165
+ one.name,
166
+ { ...reference(one.type, `${where}.${one.name}`), ...described(one.description) },
167
+ ])),
168
+ required: values.filter((one) => one.type.kind === "NON_NULL" && one.defaultValue == null).map((one) => one.name),
169
+ };
170
+ }
171
+ const fieldsOf = (name) => {
172
+ const type = types.get(name);
173
+ return type && (type.kind === "OBJECT" || type.kind === "INTERFACE") ? (type.fields ?? []) : undefined;
174
+ };
175
+ const selectable = (field) => !field.isDeprecated && !field.args.some((one) => one.type.kind === "NON_NULL" && one.defaultValue == null);
176
+ const isLeaf = (name) => {
177
+ const kind = types.get(name)?.kind;
178
+ return kind === "SCALAR" || kind === "ENUM";
179
+ };
180
+ /** Scalars, and `{ id }` of each object that has one; a type with neither gives `__typename`. */
181
+ const oneLevel = (name) => {
182
+ const parts = (fieldsOf(name) ?? []).filter(selectable).flatMap((field) => {
183
+ const inner = named(field.type);
184
+ if (isLeaf(inner))
185
+ return [field.name];
186
+ return fieldsOf(inner)?.some((one) => one.name === "id") ? [`${field.name} { id }`] : [];
187
+ });
188
+ return parts.length > 0 ? parts.join(" ") : "__typename";
189
+ };
190
+ /** A Relay connection: `nodes` of one type, and a `pageInfo` with `hasNextPage` and `endCursor`. */
191
+ const connectionOf = (name) => {
192
+ const fields = fieldsOf(name);
193
+ const nodes = fields?.find((one) => one.name === "nodes");
194
+ const pageInfo = fields?.find((one) => one.name === "pageInfo");
195
+ const info = pageInfo && fieldsOf(named(pageInfo.type));
196
+ if (!nodes || !info || !["hasNextPage", "endCursor"].every((key) => info.some((one) => one.name === key)))
197
+ return undefined;
198
+ return named(nodes.type);
199
+ };
200
+ const selectionOf = (name) => {
201
+ if (isLeaf(name))
202
+ return "";
203
+ if (types.get(name)?.kind === "UNION")
204
+ return "__typename";
205
+ const node = connectionOf(name);
206
+ return node ? `nodes { ${oneLevel(node)} } pageInfo { hasNextPage endCursor }` : oneLevel(name);
207
+ };
208
+ // An answer that is only a reference is named after its type, which would drop a nullable field's null: such an
209
+ // answer is wrapped, so it gets a name of its own that keeps it.
210
+ const answerOf = (node) => node.type === "ref" && node.nullable
211
+ ? { type: "allOf", of: [{ type: "ref", ref: node.ref }], nullable: true }
212
+ : node;
213
+ const exclude = options.exclude ?? {};
214
+ const excluded = new Set();
215
+ const operations = [];
216
+ for (const [key, operation] of [
217
+ ["queryType", "query"],
218
+ ["mutationType", "mutation"],
219
+ ]) {
220
+ const root = rootName(key);
221
+ if (!root)
222
+ continue;
223
+ for (const field of fieldsOf(root) ?? []) {
224
+ const scoped = `${operation}.${field.name}`;
225
+ const left = [scoped, field.name].find((name) => exclude[name] !== undefined);
226
+ if (left !== undefined) {
227
+ excluded.add(left);
228
+ continue;
229
+ }
230
+ const where = `${root}.${field.name}`;
231
+ const argument = (one) => ({
232
+ ...reference(one.type, `${where}(${one.name})`),
233
+ ...described(one.description),
234
+ });
235
+ const required = field.args.filter((one) => one.type.kind === "NON_NULL" && one.defaultValue == null);
236
+ const answer = named(field.type);
237
+ const binding = {
238
+ kind: "graphql",
239
+ operation,
240
+ field: field.name,
241
+ // A non-null argument with a default may be left out; declared non-null, its variable could not be.
242
+ variables: Object.fromEntries(field.args.map((one) => [
243
+ one.name,
244
+ one.defaultValue != null && one.type.kind === "NON_NULL" && one.type.ofType
245
+ ? typeText(one.type.ofType)
246
+ : typeText(one.type),
247
+ ])),
248
+ selection: selectionOf(answer),
249
+ };
250
+ const deletes = operation === "mutation" && DELETES.test(field.name) && !UNDOES.test(field.name);
251
+ const has = (name, type) => field.args.some((one) => one.name === name && one.type.kind !== "NON_NULL" && named(one.type) === type);
252
+ const pages = operation === "query" && field.type.kind !== "LIST" && connectionOf(answer) && has("after", "String");
253
+ const pagination = pages
254
+ ? {
255
+ style: "cursor",
256
+ cursor: { in: "body", name: "after" },
257
+ next: "pageInfo.endCursor",
258
+ items: "nodes",
259
+ hasMore: "pageInfo.hasNextPage",
260
+ ...(has("first", "Int") ? { limit: { in: "body", name: "first" } } : {}),
261
+ }
262
+ : undefined;
263
+ const summary = field.description?.split("\n")[0];
264
+ operations.push({
265
+ id: field.name,
266
+ binding,
267
+ ...(summary ? { summary } : {}),
268
+ ...described(field.description),
269
+ tags: [operation],
270
+ parameters: field.args.map((one) => ({
271
+ name: one.name,
272
+ in: "body",
273
+ required: required.includes(one),
274
+ ...described(one.description),
275
+ schema: argument(one),
276
+ })),
277
+ ...(field.args.length > 0
278
+ ? {
279
+ requestBody: {
280
+ confidence: "contract",
281
+ required: required.length > 0,
282
+ schema: inputObject(field.args, where),
283
+ },
284
+ }
285
+ : {}),
286
+ response: { confidence: "contract", required: false, schema: answerOf(reference(field.type, where)) },
287
+ effect: operation === "query" ? "read" : deletes ? "destructive" : "write",
288
+ ...(deletes ? { effectReason: GRAPHQL_DELETE_REASON } : {}),
289
+ ...(pagination ? { pagination, paginationSource: "detected" } : {}),
290
+ ...(field.isDeprecated ? { deprecated: true } : {}),
291
+ source: { location: where },
292
+ });
293
+ }
294
+ }
295
+ const stale = Object.keys(exclude).filter((name) => !excluded.has(name));
296
+ if (stale.length > 0)
297
+ throw new CodegenError(stale.map((name) => `exclusion "${name}" matches no field of Query or Mutation`));
298
+ return {
299
+ source: {
300
+ kind: "other",
301
+ sourceUrl: options.sourceUrl ?? options.url,
302
+ ...(options.sourceRevision !== undefined ? { sourceRevision: options.sourceRevision } : {}),
303
+ },
304
+ operations: operations.sort((a, b) => a.id.localeCompare(b.id)),
305
+ schemas,
306
+ servers: [{ url: options.url }],
307
+ };
308
+ };
309
+ /** The standard introspection query, deep enough for `[[Type!]!]!`. */
310
+ export const INTROSPECTION_QUERY = `query IntrospectionQuery {
311
+ __schema {
312
+ queryType { name }
313
+ mutationType { name }
314
+ types {
315
+ kind name description
316
+ fields(includeDeprecated: true) { name description isDeprecated args { ...InputValue } type { ...TypeRef } }
317
+ inputFields { ...InputValue }
318
+ enumValues(includeDeprecated: true) { name }
319
+ possibleTypes { name }
320
+ }
321
+ }
322
+ }
323
+ fragment InputValue on __InputValue { name description defaultValue type { ...TypeRef } }
324
+ fragment TypeRef on __Type {
325
+ kind name
326
+ ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }
327
+ }`;
328
+ const FILE = "schema.json";
329
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
330
+ const sortKeys = (value) => Array.isArray(value)
331
+ ? value.map(sortKeys)
332
+ : object(value)
333
+ ? Object.fromEntries(Object.keys(value)
334
+ .sort()
335
+ .map((key) => [key, sortKeys(value[key])]))
336
+ : value;
337
+ const byName = (list) => Array.isArray(list)
338
+ ? [...list].sort((a, b) => String(a?.name).localeCompare(String(b?.name)))
339
+ : list;
340
+ /**
341
+ * Asks `url` for its schema and writes `schema.json` and `provenance.json` to `dir`. Run by hand, then review the diff:
342
+ * the build never fetches. Types are sorted by name so a reordered answer is no diff. `headers` is for a service that
343
+ * answers introspection only when signed in; nothing of them is written.
344
+ */
345
+ export const syncGraphql = async (options) => {
346
+ const fetch = options.fetch ?? globalThis.fetch;
347
+ const response = await fetch(options.url, {
348
+ method: "POST",
349
+ headers: { "content-type": "application/json", ...options.headers },
350
+ body: JSON.stringify({ query: INTROSPECTION_QUERY }),
351
+ signal: AbortSignal.timeout(30_000),
352
+ redirect: "error",
353
+ });
354
+ if (!response.ok)
355
+ throw new Error(`GraphQL introspection failed: HTTP ${response.status}`);
356
+ const answer = await response.json();
357
+ if (object(answer) && Array.isArray(answer.errors) && answer.errors.length > 0)
358
+ throw new Error("GraphQL introspection failed: the service answered errors[]; it may need a sign-in");
359
+ const schema = schemaOf(answer);
360
+ const written = `${JSON.stringify(sortKeys({ __schema: { ...schema, types: byName(schema.types) } }), null, 2)}\n`;
361
+ const provenance = {
362
+ source: options.url,
363
+ sha256: sha256(written),
364
+ retrieved_at: (options.now ?? new Date()).toISOString(),
365
+ normalization: "types sorted by name, object keys sorted, 2-space JSON",
366
+ };
367
+ mkdirSync(options.dir, { recursive: true });
368
+ writeFileSync(join(options.dir, FILE), written);
369
+ writeFileSync(join(options.dir, "provenance.json"), `${JSON.stringify(provenance, null, 2)}\n`);
370
+ return provenance;
371
+ };
372
+ /** The snapshot `syncGraphql` wrote, parsed. Throws if its hash changed. */
373
+ export const readGraphql = (dir) => {
374
+ const provenance = JSON.parse(readFileSync(join(dir, "provenance.json"), "utf8"));
375
+ const raw = readFileSync(join(dir, FILE));
376
+ if (sha256(raw) !== provenance.sha256)
377
+ throw new CodegenError([`GraphQL schema hash mismatch: ${join(dir, FILE)}`]);
378
+ return JSON.parse(raw.toString("utf8"));
379
+ };
@@ -3,18 +3,20 @@
3
3
  * manifest and a coverage page. Build-time, apart from the small helpers a CLI reads the generated
4
4
  * files with (`identifier`, `requestSchema`), and format-neutral: it parses no file format and
5
5
  * adds no runtime dependency. `adaptOpenApi` reads an OpenAPI document and `adaptDiscovery` Google Discovery
6
- * documents the consumer has parsed; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
6
+ * documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
7
7
  * peer dependencies. `fakeApi` serves the generated manifest as a strict fake for a CLI's tests, and `signInRequirements` with
8
8
  * `signInPlace` say which sign-in a call needs and where its token goes. An adapter from
9
9
  * Postman or anything else lives in the consumer.
10
10
  */
11
11
  export { adaptDiscovery, type DiscoveryMetadata, type DiscoveryOptions, type DiscoveryProvenance, type DiscoveryResult, type DiscoveryService, readDiscovery, type SyncDiscoveryOptions, syncDiscovery, } from "./discovery.js";
12
12
  export { type FakeAnswer, type FakeApi, type FakeApiOptions, type FakeCall, fakeApi, sampleOf, schemaProblems, } from "./fake.js";
13
+ export { adaptGraphql, GRAPHQL_DELETE_REASON, type GraphqlOptions, type GraphqlProvenance, graphqlDocument, INTROSPECTION_QUERY, parseSelection, readGraphql, type Selection, syncGraphql, } from "./graphql.js";
14
+ export { type GraphqlFake, type GraphqlFakeAnswer, type GraphqlFakeCall, type GraphqlFakeOptions, graphqlFake, selectionProblems, } from "./graphql-fake.js";
13
15
  export { requestSchema } from "./json-schema.js";
14
16
  export { type CoverageOptions, coverageGenerator, definitionsGenerator, examplesGenerator, type ManifestOperation, manifestGenerator, } from "./manifest.js";
15
17
  export { type MergedSource, type MergeOptions, type MergeReport, mergeOpenApi, type SpecSource } from "./merge.js";
16
- export type { ApiBody, ApiModel, ApiOperation, ApiParameter, ApiSchema, ApiServer, Binding, CodeGenerator, Confidence, Discriminator, Effect, GeneratedArtifact, HttpBinding, HttpMethod, OAuthFlow, OperationPermission, Override, PageParameter, Pagination, RpcBinding, SchemaNode, SecurityRequirement, SecurityScheme, SourceInfo, SourceReference, } from "./model.js";
17
- export { identifier, kebab } from "./names.js";
18
+ export type { ApiBody, ApiModel, ApiOperation, ApiParameter, ApiSchema, ApiServer, Binding, CodeGenerator, Confidence, Discriminator, Effect, GeneratedArtifact, GraphqlBinding, HttpBinding, HttpMethod, OAuthFlow, OperationPermission, Override, PageParameter, Pagination, RpcBinding, SchemaNode, SecurityRequirement, SecurityScheme, SourceInfo, SourceReference, } from "./model.js";
19
+ export { bindingLabel, identifier, kebab } from "./names.js";
18
20
  export { adaptOpenApi, OpenApiError } from "./openapi.js";
19
21
  export { detectPagination } from "./pagination.js";
20
22
  export { type PatchedSpec, type PatchSpecOptions, patchSpec, type SpecPatch } from "./patch.js";
@@ -3,17 +3,19 @@
3
3
  * manifest and a coverage page. Build-time, apart from the small helpers a CLI reads the generated
4
4
  * files with (`identifier`, `requestSchema`), and format-neutral: it parses no file format and
5
5
  * adds no runtime dependency. `adaptOpenApi` reads an OpenAPI document and `adaptDiscovery` Google Discovery
6
- * documents the consumer has parsed; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
6
+ * documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
7
7
  * peer dependencies. `fakeApi` serves the generated manifest as a strict fake for a CLI's tests, and `signInRequirements` with
8
8
  * `signInPlace` say which sign-in a call needs and where its token goes. An adapter from
9
9
  * Postman or anything else lives in the consumer.
10
10
  */
11
11
  export { adaptDiscovery, readDiscovery, syncDiscovery, } from "./discovery.js";
12
12
  export { fakeApi, sampleOf, schemaProblems, } from "./fake.js";
13
+ export { adaptGraphql, GRAPHQL_DELETE_REASON, graphqlDocument, INTROSPECTION_QUERY, parseSelection, readGraphql, syncGraphql, } from "./graphql.js";
14
+ export { graphqlFake, selectionProblems, } from "./graphql-fake.js";
13
15
  export { requestSchema } from "./json-schema.js";
14
16
  export { coverageGenerator, definitionsGenerator, examplesGenerator, manifestGenerator, } from "./manifest.js";
15
17
  export { mergeOpenApi } from "./merge.js";
16
- export { identifier, kebab } from "./names.js";
18
+ export { bindingLabel, identifier, kebab } from "./names.js";
17
19
  export { adaptOpenApi, OpenApiError } from "./openapi.js";
18
20
  export { detectPagination } from "./pagination.js";
19
21
  export { patchSpec } from "./patch.js";
@@ -1,4 +1,4 @@
1
- import { kebab } from "./names.js";
1
+ import { bindingLabel, kebab } from "./names.js";
2
2
  import { isLossless } from "./runtime.js";
3
3
  import { SchemaTree } from "./tree.js";
4
4
  const withoutUndefined = (value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
@@ -119,7 +119,7 @@ export const coverageGenerator = (options) => (model) => {
119
119
  const tree = new SchemaTree(model);
120
120
  const rows = model.operations.map((operation) => {
121
121
  const entry = toManifest(operation, tree);
122
- const binding = entry.binding.kind === "http" ? `${entry.binding.method} ${entry.binding.path}` : entry.binding.name;
122
+ const binding = bindingLabel(entry.binding);
123
123
  const status = entry.deprecated ? "deprecated" : "generated";
124
124
  return `| \`${entry.id}\` | \`${binding}\` | \`${options.command(entry)}\` | ${entry.effect} | ${entry.request?.confidence ?? "—"} | ${status} | ${cell(entry.summary)} |`;
125
125
  });
@@ -22,7 +22,20 @@ export interface RpcBinding {
22
22
  kind: "rpc";
23
23
  name: string;
24
24
  }
25
- export type Binding = HttpBinding | RpcBinding;
25
+ /**
26
+ * One field of a GraphQL schema's `Query` or `Mutation`. The request is one document, built by `graphqlDocument` from
27
+ * the field, its variables' GraphQL types and a selection; the answer is `data.<field>`.
28
+ */
29
+ export interface GraphqlBinding {
30
+ kind: "graphql";
31
+ operation: "query" | "mutation";
32
+ field: string;
33
+ /** Each argument's GraphQL type as written in the schema: `{ id: "String!", filter: "IssueFilter" }`. */
34
+ variables: Readonly<Record<string, string>>;
35
+ /** The default selection: scalars, and `{ id }` of each object, one level deep; a connection's `nodes` and `pageInfo`. */
36
+ selection: string;
37
+ }
38
+ export type Binding = HttpBinding | RpcBinding | GraphqlBinding;
26
39
  interface SchemaCommon {
27
40
  sensitive?: boolean;
28
41
  description?: string;
@@ -1,3 +1,6 @@
1
+ import type { Binding } from "./model.js";
1
2
  export declare const identifier: (id: string) => string;
2
3
  /** `getMyInfo` → `get-my-info`. */
3
4
  export declare const kebab: (id: string) => string;
5
+ /** How a reader names the call: `GET /pages/{id}`, `sendMessage`, `query issues`. */
6
+ export declare const bindingLabel: (binding: Binding) => string;
@@ -43,3 +43,9 @@ export const kebab = (id) => id
43
43
  .replace(/[^A-Za-z0-9]+/g, "-")
44
44
  .replace(/^-|-$/g, "")
45
45
  .toLowerCase();
46
+ /** How a reader names the call: `GET /pages/{id}`, `sendMessage`, `query issues`. */
47
+ export const bindingLabel = (binding) => binding.kind === "http"
48
+ ? `${binding.method} ${binding.path}`
49
+ : binding.kind === "rpc"
50
+ ? binding.name
51
+ : `${binding.operation} ${binding.field}`;
@@ -1,7 +1,8 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { dirname, extname, join, posix } from "node:path";
3
- import { identifier, kebab } from "./names.js";
3
+ import { bindingLabel, identifier, kebab } from "./names.js";
4
4
  import { answerPaths, detectPagination, requestParameters } from "./pagination.js";
5
+ import { signInRequirements } from "./sign-in.js";
5
6
  export class CodegenError extends Error {
6
7
  problems;
7
8
  constructor(problems) {
@@ -198,15 +199,15 @@ const applyAuth = (model, auth) => {
198
199
  securitySchemes: auth.securitySchemes,
199
200
  security: auth.security,
200
201
  securityReason: auth.reason,
201
- // A requirement naming the source's own schemes is replaced; `[]`, "no sign-in", stays.
202
- operations: model.operations.map(({ security, ...operation }) => security?.every((requirement) => Object.keys(requirement).every((name) => names.has(name)))
202
+ // `[]` is replaced too: `auth` says the source's sign-in is wrong, and a key sent to a public call is ignored while
203
+ // a key left off a private one always fails.
204
+ operations: model.operations.map(({ security, ...operation }) => signInRequirements({ security }, undefined) &&
205
+ security?.every((requirement) => Object.keys(requirement).every((name) => names.has(name)))
203
206
  ? { ...operation, security }
204
207
  : operation),
205
208
  };
206
209
  };
207
- const bindingKey = (operation) => operation.binding.kind === "http"
208
- ? `${operation.binding.method} ${operation.binding.path}`
209
- : `rpc ${operation.binding.name}`;
210
+ const bindingKey = (operation) => operation.binding.kind === "rpc" ? `rpc ${operation.binding.name}` : bindingLabel(operation.binding);
210
211
  const duplicates = (values) => [...new Set(values.filter((value, index) => values.indexOf(value) !== index))].sort();
211
212
  const refsIn = (node, found = []) => {
212
213
  switch (node.type) {
@@ -1,5 +1,5 @@
1
1
  import { flatten } from "../commands/registry.js";
2
- import { kebab } from "./names.js";
2
+ import { bindingLabel, kebab } from "./names.js";
3
3
  import { CodegenError } from "./pipeline.js";
4
4
  export const API_SKILL_INDEX = "references/api.md";
5
5
  export const API_SKILL_GROUPS = "references/api";
@@ -38,7 +38,7 @@ const pages = (pagination) => {
38
38
  };
39
39
  const flagRow = (option) => `| ${code(option.flags, true)} | ${option.mandatory ? "yes" : "no"} | ${text(option.description)} |`;
40
40
  const section = (operation, command) => {
41
- const call = operation.binding.kind === "http" ? `${operation.binding.method} ${operation.binding.path}` : operation.binding.name;
41
+ const call = bindingLabel(operation.binding);
42
42
  const scopes = (operation.security ?? []).map((requirement) => Object.entries(requirement)
43
43
  .map(([scheme, list]) => (list.length > 0 ? `${scheme} (${list.join(", ")})` : scheme))
44
44
  .join(" and "));
@@ -47,6 +47,7 @@ what it cannot do yet.
47
47
  | Swagger 2.0 | `adaptOpenApi(await upgradeToOpenApi3(document))` |
48
48
  | Swagger 1.2 (Yandex Disk) | `upgradeToOpenApi3(listing, declarations)`: the resource listing, and each API declaration keyed by its `apis[].path`, fetched from the listing's `basePath` followed by that path |
49
49
  | Google Discovery | `adaptDiscovery(readDiscovery(dir))`, snapshots written by `syncDiscovery` |
50
+ | GraphQL (Linear) | `adaptGraphql(readGraphql(dir), { url, scalars })`, the introspection result written by `syncGraphql` |
50
51
 
51
52
  `upgradeToOpenApi3` converts with [swagger-converter](https://github.com/apigee-127/swagger-converter) (1.2 → 2.0) and
52
53
  [@scalar/openapi-upgrader](https://github.com/scalar/scalar/tree/main/packages/openapi-upgrader) (2.0 → 3.0). They are
@@ -87,8 +88,9 @@ From the source the generator reads:
87
88
  - **Effect**: GET and HEAD read, POST, PUT and PATCH write, DELETE is destructive.
88
89
  - **Servers and sign-in**: `servers` (each URL once, as written), `components/securitySchemes` and `security` go into
89
90
  the manifest as `servers`, `securitySchemes` and `security`, and an operation's own `security` (`[]` for one that
90
- needs no sign-in) onto that operation. A CLI then does not copy its base URL or OAuth endpoints by hand. They appear
91
- only when the source has them. A requirement naming a scheme the document lacks stops generation.
91
+ needs no sign-in, unless `auth` below replaces it) onto that operation. A CLI then does not copy its base URL or
92
+ OAuth endpoints by hand. They appear only when the source has them. A requirement naming a scheme the document lacks
93
+ stops generation.
92
94
 
93
95
  ### Corrections a CLI passes to `generate`
94
96
 
@@ -126,7 +128,9 @@ From the source the generator reads:
126
128
  parameter the operation does not take stops generation.
127
129
  - **`auth`**: `{ securitySchemes, security, reason }` replaces the source's sign-in, the operations' own requirements
128
130
  included. Yandex Disk's Swagger 1.2 has no scheme, and its header is `Authorization: OAuth <token>`:
129
- `{ oauth: { type: "http", scheme: "OAuth" } }`. HubSpot's spec has no private app token.
131
+ `{ oauth: { type: "http", scheme: "OAuth" } }`. HubSpot's spec has no private app token. An operation keeps its own
132
+ `security` only when it signs in by `auth`'s schemes. One the source marks as needing no sign-in (`[]`) gets `auth`
133
+ as well: HubSpot's object specs mark 115 calls that way, and each answered 401 without the key.
130
134
 
131
135
  ### A strict fake for tests
132
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-base",
3
- "version": "0.114.0",
3
+ "version": "0.115.0",
4
4
  "description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",