@webpieces/openapi-generator 0.4.945 → 0.4.947
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/README.md +37 -1
- package/package.json +3 -3
- package/src/generate/DocLinkGuard.d.ts +13 -1
- package/src/generate/DocLinkGuard.js +22 -1
- package/src/generate/DocLinkGuard.js.map +1 -1
- package/src/generate/DocumentSelection.d.ts +12 -3
- package/src/generate/DocumentSelection.js +12 -3
- package/src/generate/DocumentSelection.js.map +1 -1
- package/src/generate/HiddenFieldGuard.d.ts +41 -0
- package/src/generate/HiddenFieldGuard.js +103 -0
- package/src/generate/HiddenFieldGuard.js.map +1 -0
- package/src/generate/OpenApiGenerator.d.ts +9 -6
- package/src/generate/OpenApiGenerator.js +27 -51
- package/src/generate/OpenApiGenerator.js.map +1 -1
- package/src/generate/SchemaRenderer.d.ts +19 -1
- package/src/generate/SchemaRenderer.js +18 -1
- package/src/generate/SchemaRenderer.js.map +1 -1
- package/src/generate/UnpublishedComponentsGuard.d.ts +15 -0
- package/src/generate/UnpublishedComponentsGuard.js +60 -0
- package/src/generate/UnpublishedComponentsGuard.js.map +1 -0
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ export abstract class StoreApi { ... }
|
|
|
17
17
|
| `@ApiType` value | file | contents |
|
|
18
18
|
|---|---|---|
|
|
19
19
|
| `SVC_TO_SVC` | `full-private-openapi.json` | every method, hidden ones included, plus an internal-use-only line in `info.description`. Nothing renders it for humans |
|
|
20
|
-
| `EXTERNAL_CUSTOMER` | `public-openapi.json` | the customer contract, minus every `{ hidden: true }` method |
|
|
20
|
+
| `EXTERNAL_CUSTOMER` | `public-openapi.json` | the customer contract, minus every `{ hidden: true }` method and every `@hidden` field |
|
|
21
21
|
| `MCP` | `mcp-openapi.json` | the same contracts with the `x-mcp-*` extensions an MCP generator reads |
|
|
22
22
|
|
|
23
23
|
**A document no contract declares is not written.** No `@ApiType` at all means `SVC_TO_SVC` only —
|
|
@@ -48,6 +48,42 @@ announcing that anything was withheld.
|
|
|
48
48
|
**Hiding is a documentation decision and never an access-control one.** The route is still served and
|
|
49
49
|
still demands whatever credential it declares.
|
|
50
50
|
|
|
51
|
+
## Hiding ONE field
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
export class OrderDto {
|
|
55
|
+
orderId!: string;
|
|
56
|
+
/**
|
|
57
|
+
* Estimated delivery time, ISO-8601.
|
|
58
|
+
* @hidden not announced yet; ships with the delivery-ETA launch
|
|
59
|
+
* @format date-time
|
|
60
|
+
*/
|
|
61
|
+
deliveryEta?: string;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The `@hidden` JSDoc tag withholds one field from `public-openapi.json` and its bundled sibling — its
|
|
66
|
+
property, its prose and its `required` entry — everywhere the schema is written: request and response
|
|
67
|
+
bodies, nested `$ref` targets, inherited fields, webhook payloads, inlined single-use wrappers. A type
|
|
68
|
+
reached ONLY through a hidden field is not in the customer document at all. The field stays in
|
|
69
|
+
`full-private-openapi.json`, and in the MCP output (`mcp-openapi.json` and the tool catalogs), exactly
|
|
70
|
+
like a `{ hidden: true }` method. The tag's text is the author's reason and is published nowhere.
|
|
71
|
+
`grep -rn "@hidden"` lists every withheld field.
|
|
72
|
+
|
|
73
|
+
Generation refuses:
|
|
74
|
+
|
|
75
|
+
- a hidden field that is REQUIRED — the customer document would omit a property the server insists on;
|
|
76
|
+
make it optional (`name?:`);
|
|
77
|
+
- a type whose EVERY field is hidden — hide the method or the field holding the type instead;
|
|
78
|
+
- a `{@link}` to a hidden field from prose the customer document carries;
|
|
79
|
+
- a hidden field on a type the split customer document `$ref`s into ANOTHER package's
|
|
80
|
+
`components.openapi.json` — that document serves every audience and cannot withhold it; declare the
|
|
81
|
+
type in the contract's own package.
|
|
82
|
+
|
|
83
|
+
**`@hidden` is for a field that was NEVER published.** Hiding a field a partner already reads is a
|
|
84
|
+
removal from their side, and the generator has no baseline to notice it. It is also documentation only:
|
|
85
|
+
the server still accepts and returns the field.
|
|
86
|
+
|
|
51
87
|
## The manifest
|
|
52
88
|
|
|
53
89
|
It carries exactly what is **not a property of the code**:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/openapi-generator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.947",
|
|
4
4
|
"description": "Render an ApiDocModel to OpenAPI 3.1.0 — the canonical internal document and the customer-published one, JSON and YAML, from one generation pass. Ships the wp-openapi bin.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webpieces/api-doc-model": "0.4.
|
|
27
|
-
"@webpieces/core-util": "0.4.
|
|
26
|
+
"@webpieces/api-doc-model": "0.4.947",
|
|
27
|
+
"@webpieces/core-util": "0.4.947",
|
|
28
28
|
"typescript": "5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
@@ -13,10 +13,22 @@ export declare class DocumentLinkNaming implements DocLinkNaming {
|
|
|
13
13
|
private readonly placement;
|
|
14
14
|
/** `Contract.method` -> operationId, for every operation the document publishes. */
|
|
15
15
|
private readonly operationIds;
|
|
16
|
+
/**
|
|
17
|
+
* The document omits `@hidden` fields (#1246) — so a link to one names nothing it publishes,
|
|
18
|
+
* and is refused like a link to a hidden method.
|
|
19
|
+
*/
|
|
20
|
+
private readonly dropsHiddenFields;
|
|
16
21
|
constructor(types: ReadonlyMap<string, DocumentedType>, schemas: SchemaRenderer, placement: SchemaPlacement,
|
|
17
22
|
/** `Contract.method` -> operationId, for every operation the document publishes. */
|
|
18
|
-
operationIds: ReadonlyMap<string, string
|
|
23
|
+
operationIds: ReadonlyMap<string, string>,
|
|
24
|
+
/**
|
|
25
|
+
* The document omits `@hidden` fields (#1246) — so a link to one names nothing it publishes,
|
|
26
|
+
* and is refused like a link to a hidden method.
|
|
27
|
+
*/
|
|
28
|
+
dropsHiddenFields: boolean);
|
|
19
29
|
publishedName(link: DocLink): string | undefined;
|
|
30
|
+
/** True when this document omits `owner`'s field `name` because it is `@hidden` (#1246). */
|
|
31
|
+
private isHiddenField;
|
|
20
32
|
}
|
|
21
33
|
/**
|
|
22
34
|
* Resolves every `{@link}` in a rendered document, and REFUSES the ones it cannot name (#1284).
|
|
@@ -14,22 +14,35 @@ class DocumentLinkNaming {
|
|
|
14
14
|
schemas;
|
|
15
15
|
placement;
|
|
16
16
|
operationIds;
|
|
17
|
+
dropsHiddenFields;
|
|
17
18
|
constructor(types, schemas, placement,
|
|
18
19
|
/** `Contract.method` -> operationId, for every operation the document publishes. */
|
|
19
|
-
operationIds
|
|
20
|
+
operationIds,
|
|
21
|
+
/**
|
|
22
|
+
* The document omits `@hidden` fields (#1246) — so a link to one names nothing it publishes,
|
|
23
|
+
* and is refused like a link to a hidden method.
|
|
24
|
+
*/
|
|
25
|
+
dropsHiddenFields) {
|
|
20
26
|
this.types = types;
|
|
21
27
|
this.schemas = schemas;
|
|
22
28
|
this.placement = placement;
|
|
23
29
|
this.operationIds = operationIds;
|
|
30
|
+
this.dropsHiddenFields = dropsHiddenFields;
|
|
24
31
|
}
|
|
25
32
|
publishedName(link) {
|
|
26
33
|
if (link.kind === api_doc_model_1.DocLinkKind.OPERATION) {
|
|
27
34
|
return this.operationIds.get(`${link.owner}.${link.ownerName}`);
|
|
28
35
|
}
|
|
36
|
+
if (link.kind === api_doc_model_1.DocLinkKind.MEMBER) {
|
|
37
|
+
return this.isHiddenField(link.owner, link.member) ? undefined : link.member;
|
|
38
|
+
}
|
|
29
39
|
const type = this.types.get(link.owner);
|
|
30
40
|
if (link.kind !== api_doc_model_1.DocLinkKind.TYPE || type === undefined) {
|
|
31
41
|
return undefined;
|
|
32
42
|
}
|
|
43
|
+
if (link.member !== '' && this.isHiddenField(link.owner, link.member.slice(1))) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
33
46
|
// A single-use request/response wrapper is defined INLINE at its operation (#1303), with its
|
|
34
47
|
// published name as the schema's `title` — so the link names that title. No schema page
|
|
35
48
|
// exists for it, which a docs site sees because `components.schemas` has no entry.
|
|
@@ -43,6 +56,14 @@ class DocumentLinkNaming {
|
|
|
43
56
|
// its own schema name, so the reference is still a real one.
|
|
44
57
|
return this.schemas.externalTypes().has(link.owner) ? type.schemaName : undefined;
|
|
45
58
|
}
|
|
59
|
+
/** True when this document omits `owner`'s field `name` because it is `@hidden` (#1246). */
|
|
60
|
+
isHiddenField(owner, name) {
|
|
61
|
+
if (!this.dropsHiddenFields) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const field = this.types.get(owner)?.fields.find((each) => each.name === name);
|
|
65
|
+
return field !== undefined && field.hidden;
|
|
66
|
+
}
|
|
46
67
|
}
|
|
47
68
|
exports.DocumentLinkNaming = DocumentLinkNaming;
|
|
48
69
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocLinkGuard.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocLinkGuard.ts"],"names":[],"mappings":";;;AAAA,4DAOkC;AAClC,mDAA2D;AAC3D,sEAAmE;AAInE;;;;GAIG;AACH,MAAa,kBAAkB;IAEN;IACA;IACA;IAEA;IALrB,YACqB,KAA0C,EAC1C,OAAuB,EACvB,SAA0B;IAC3C,oFAAoF;IACnE,YAAyC;QAJzC,UAAK,GAAL,KAAK,CAAqC;QAC1C,YAAO,GAAP,OAAO,CAAgB;QACvB,cAAS,GAAT,SAAS,CAAiB;QAE1B,iBAAY,GAAZ,YAAY,CAA6B;IAC3D,CAAC;IAEJ,aAAa,CAAC,IAAa;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,2BAAW,CAAC,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,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AC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;gBACnD,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC;QACD,IAAI,KAAK,YAAY,uBAAU,EAAE,CAAC;YAC9B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA9DD,oCA8DC","sourcesContent":["import {\n DocLink,\n DocLinkKind,\n DocLinkNaming,\n DocLinkProblem,\n DocLinkText,\n DocumentedType,\n} from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { SchemaPlacement } from './SchemaPlacement';\nimport { SchemaRenderer } from './SchemaRenderer';\n\n/**\n * How ONE rendered OpenAPI document names a `{@link}` target (#1284): a type by the name its schema\n * carries in THIS document — the stripped schema name, or a bundled document's qualified one — and a\n * contract method by its operationId. A target the document does not publish has no name here.\n */\nexport class DocumentLinkNaming implements DocLinkNaming {\n constructor(\n private readonly types: ReadonlyMap<string, DocumentedType>,\n private readonly schemas: SchemaRenderer,\n private readonly placement: SchemaPlacement,\n /** `Contract.method` -> operationId, for every operation the document publishes. */\n private readonly operationIds: ReadonlyMap<string, string>,\n ) {}\n\n publishedName(link: DocLink): string | undefined {\n if (link.kind === DocLinkKind.OPERATION) {\n return this.operationIds.get(`${link.owner}.${link.ownerName}`);\n }\n const type = this.types.get(link.owner);\n if (link.kind !== DocLinkKind.TYPE || type === undefined) {\n return undefined;\n }\n // A single-use request/response wrapper is defined INLINE at its operation (#1303), with its\n // published name as the schema's `title` — so the link names that title. No schema page\n // exists for it, which a docs site sees because `components.schemas` has no entry.\n if (this.schemas.inlinedTypes().has(link.owner)) {\n return type.schemaName;\n }\n if (this.schemas.reachedTypes().has(link.owner)) {\n return this.placement.localName(link.owner, type);\n }\n // A schema `$ref`d into another package's components document is published THERE, under\n // its own schema name, so the reference is still a real one.\n return this.schemas.externalTypes().has(link.owner) ? type.schemaName : undefined;\n }\n}\n\n/**\n * Resolves every `{@link}` in a rendered document, and REFUSES the ones it cannot name (#1284).\n *\n * A link is resolved AFTER the document is built, over every string in it, rather than at each place\n * a description is written: prose reaches a document through a dozen slots — operation and schema\n * descriptions, `@returns`, `@summary`, tag descriptions, `x-mcp-*` — and one walk cannot miss a slot\n * the next change adds.\n *\n * ## Why an unnameable link is a refusal\n *\n * A link the compiler cannot resolve, or one to a type or operation this document does not publish,\n * is the same silent leak #1284 was filed about: the prose names something a partner cannot find. So\n * generation fails, naming every offender with its `file:line` in ONE run across every document — the\n * same shape as the stacked-JSDoc and missing-`@returns` guards. A URL link is never one: it was\n * written out as a markdown link at extraction.\n */\nexport class DocLinkGuard {\n /** By `location written`, so one link refused in several documents is named once. */\n private readonly problems = new Map<string, DocLinkProblem>();\n\n /** Resolve every string in `document` in place. */\n resolve(document: JsonObject, naming: DocLinkNaming, fileName: string): void {\n const found: DocLinkProblem[] = [];\n this.walkObject(document, naming, `${fileName}.json`, found);\n for (const problem of found) {\n const key = `${problem.location} ${problem.written}`;\n if (!this.problems.has(key)) {\n this.problems.set(key, problem);\n }\n }\n }\n\n /** Refuse when any link of any document resolved so far could not be named. */\n refuse(manifestPath: string): void {\n if (this.problems.size === 0) {\n return;\n }\n throw new OpenApiGenerationError(\n `${this.problems.size} {@link} reference(s) name nothing the generated document publishes`,\n manifestPath,\n 'Point each {@link} at a type the document publishes or an @Endpoint method of a ' +\n 'contract it publishes, imported into the file the JSDoc is in — or write the name as ' +\n \"plain text. A link is published as the target's published name, so it must have one.\",\n Array.from(this.problems.values()).map((each: DocLinkProblem) => each.toString()),\n );\n }\n\n private walkObject(\n object: JsonObject,\n naming: DocLinkNaming,\n output: string,\n found: DocLinkProblem[],\n ): void {\n for (const key of object.keys()) {\n object.set(key, this.walk(object.get(key)!, naming, output, found));\n }\n }\n\n private walk(\n value: JsonValue,\n naming: DocLinkNaming,\n output: string,\n found: DocLinkProblem[],\n ): JsonValue {\n if (typeof value === 'string') {\n return DocLinkText.hasLinks(value)\n ? DocLinkText.resolve(value, naming, output, found)\n : value;\n }\n if (value instanceof JsonObject) {\n this.walkObject(value, naming, output, found);\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((each: JsonValue) => this.walk(each, naming, output, found));\n }\n return value;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DocLinkGuard.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocLinkGuard.ts"],"names":[],"mappings":";;;AAAA,4DAQkC;AAClC,mDAA2D;AAC3D,sEAAmE;AAInE;;;;GAIG;AACH,MAAa,kBAAkB;IAEN;IACA;IACA;IAEA;IAKA;IAVrB,YACqB,KAA0C,EAC1C,OAAuB,EACvB,SAA0B;IAC3C,oFAAoF;IACnE,YAAyC;IAC1D;;;OAGG;IACc,iBAA0B;QAT1B,UAAK,GAAL,KAAK,CAAqC;QAC1C,YAAO,GAAP,OAAO,CAAgB;QACvB,cAAS,GAAT,SAAS,CAAiB;QAE1B,iBAAY,GAAZ,YAAY,CAA6B;QAKzC,sBAAiB,GAAjB,iBAAiB,CAAS;IAC5C,CAAC;IAEJ,aAAa,CAAC,IAAa;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,2BAAW,CAAC,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACpE,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K,CAAC,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA9DD,oCA8DC","sourcesContent":["import {\n DocLink,\n DocLinkKind,\n DocLinkNaming,\n DocLinkProblem,\n DocLinkText,\n DocumentedField,\n DocumentedType,\n} from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { SchemaPlacement } from './SchemaPlacement';\nimport { SchemaRenderer } from './SchemaRenderer';\n\n/**\n * How ONE rendered OpenAPI document names a `{@link}` target (#1284): a type by the name its schema\n * carries in THIS document — the stripped schema name, or a bundled document's qualified one — and a\n * contract method by its operationId. A target the document does not publish has no name here.\n */\nexport class DocumentLinkNaming implements DocLinkNaming {\n constructor(\n private readonly types: ReadonlyMap<string, DocumentedType>,\n private readonly schemas: SchemaRenderer,\n private readonly placement: SchemaPlacement,\n /** `Contract.method` -> operationId, for every operation the document publishes. */\n private readonly operationIds: ReadonlyMap<string, string>,\n /**\n * The document omits `@hidden` fields (#1246) — so a link to one names nothing it publishes,\n * and is refused like a link to a hidden method.\n */\n private readonly dropsHiddenFields: boolean,\n ) {}\n\n publishedName(link: DocLink): string | undefined {\n if (link.kind === DocLinkKind.OPERATION) {\n return this.operationIds.get(`${link.owner}.${link.ownerName}`);\n }\n if (link.kind === DocLinkKind.MEMBER) {\n return this.isHiddenField(link.owner, link.member) ? undefined : link.member;\n }\n const type = this.types.get(link.owner);\n if (link.kind !== DocLinkKind.TYPE || type === undefined) {\n return undefined;\n }\n if (link.member !== '' && this.isHiddenField(link.owner, link.member.slice(1))) {\n return undefined;\n }\n // A single-use request/response wrapper is defined INLINE at its operation (#1303), with its\n // published name as the schema's `title` — so the link names that title. No schema page\n // exists for it, which a docs site sees because `components.schemas` has no entry.\n if (this.schemas.inlinedTypes().has(link.owner)) {\n return type.schemaName;\n }\n if (this.schemas.reachedTypes().has(link.owner)) {\n return this.placement.localName(link.owner, type);\n }\n // A schema `$ref`d into another package's components document is published THERE, under\n // its own schema name, so the reference is still a real one.\n return this.schemas.externalTypes().has(link.owner) ? type.schemaName : undefined;\n }\n\n /** True when this document omits `owner`'s field `name` because it is `@hidden` (#1246). */\n private isHiddenField(owner: string, name: string): boolean {\n if (!this.dropsHiddenFields) {\n return false;\n }\n const field = this.types.get(owner)?.fields.find((each: DocumentedField) => each.name === name);\n return field !== undefined && field.hidden;\n }\n}\n\n/**\n * Resolves every `{@link}` in a rendered document, and REFUSES the ones it cannot name (#1284).\n *\n * A link is resolved AFTER the document is built, over every string in it, rather than at each place\n * a description is written: prose reaches a document through a dozen slots — operation and schema\n * descriptions, `@returns`, `@summary`, tag descriptions, `x-mcp-*` — and one walk cannot miss a slot\n * the next change adds.\n *\n * ## Why an unnameable link is a refusal\n *\n * A link the compiler cannot resolve, or one to a type or operation this document does not publish,\n * is the same silent leak #1284 was filed about: the prose names something a partner cannot find. So\n * generation fails, naming every offender with its `file:line` in ONE run across every document — the\n * same shape as the stacked-JSDoc and missing-`@returns` guards. A URL link is never one: it was\n * written out as a markdown link at extraction.\n */\nexport class DocLinkGuard {\n /** By `location written`, so one link refused in several documents is named once. */\n private readonly problems = new Map<string, DocLinkProblem>();\n\n /** Resolve every string in `document` in place. */\n resolve(document: JsonObject, naming: DocLinkNaming, fileName: string): void {\n const found: DocLinkProblem[] = [];\n this.walkObject(document, naming, `${fileName}.json`, found);\n for (const problem of found) {\n const key = `${problem.location} ${problem.written}`;\n if (!this.problems.has(key)) {\n this.problems.set(key, problem);\n }\n }\n }\n\n /** Refuse when any link of any document resolved so far could not be named. */\n refuse(manifestPath: string): void {\n if (this.problems.size === 0) {\n return;\n }\n throw new OpenApiGenerationError(\n `${this.problems.size} {@link} reference(s) name nothing the generated document publishes`,\n manifestPath,\n 'Point each {@link} at a type the document publishes or an @Endpoint method of a ' +\n 'contract it publishes, imported into the file the JSDoc is in — or write the name as ' +\n \"plain text. A link is published as the target's published name, so it must have one.\",\n Array.from(this.problems.values()).map((each: DocLinkProblem) => each.toString()),\n );\n }\n\n private walkObject(\n object: JsonObject,\n naming: DocLinkNaming,\n output: string,\n found: DocLinkProblem[],\n ): void {\n for (const key of object.keys()) {\n object.set(key, this.walk(object.get(key)!, naming, output, found));\n }\n }\n\n private walk(\n value: JsonValue,\n naming: DocLinkNaming,\n output: string,\n found: DocLinkProblem[],\n ): JsonValue {\n if (typeof value === 'string') {\n return DocLinkText.hasLinks(value)\n ? DocLinkText.resolve(value, naming, output, found)\n : value;\n }\n if (value instanceof JsonObject) {\n this.walkObject(value, naming, output, found);\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((each: JsonValue) => this.walk(each, naming, output, found));\n }\n return value;\n }\n}\n"]}
|
|
@@ -26,8 +26,13 @@ export declare const OPERATION_SEMANTICS: string;
|
|
|
26
26
|
* - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It
|
|
27
27
|
* stays in the private document, and in the MCP document when it is a tool.
|
|
28
28
|
*
|
|
29
|
+
* - `@hidden` in ONE field's JSDoc subtracts that field from the CUSTOMER document only (#1246),
|
|
30
|
+
* with exactly the audience of `{ hidden: true }`: kept in the private document, and in the MCP
|
|
31
|
+
* document and tool catalogs.
|
|
32
|
+
*
|
|
29
33
|
* The per-method case is real and cannot be said at class level: a NEW endpoint on an
|
|
30
|
-
* already-published API, built on main before it is announced. The per-
|
|
34
|
+
* already-published API, built on main before it is announced. The per-field case is the same thing
|
|
35
|
+
* one level down: a new field on an already-published DTO. The per-contract case is the one that
|
|
31
36
|
* must not default to permissive, and at class level naming it costs one token per contract.
|
|
32
37
|
*
|
|
33
38
|
* ## Select, then render — never render, then filter
|
|
@@ -59,7 +64,11 @@ export declare class DocumentSelection {
|
|
|
59
64
|
readonly fileName: string;
|
|
60
65
|
/** The `@ApiType` a contract must declare to appear in this document. */
|
|
61
66
|
readonly apiType: ApiTypeKind;
|
|
62
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Drop methods marked `{ hidden: true }` AND fields marked `@hidden` (#1246). True for the
|
|
69
|
+
* customer document alone — one flag, because the two are one audience decision at two
|
|
70
|
+
* levels, and a second flag could only ever disagree with the first.
|
|
71
|
+
*/
|
|
63
72
|
readonly dropHidden: boolean;
|
|
64
73
|
/** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */
|
|
65
74
|
readonly includeMcpExtensions: boolean;
|
|
@@ -97,7 +106,7 @@ export declare class DocumentSelection {
|
|
|
97
106
|
/** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */
|
|
98
107
|
static customer(): DocumentSelection;
|
|
99
108
|
/**
|
|
100
|
-
* Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent
|
|
109
|
+
* Every contract declaring `MCP`. A HIDDEN method is kept, and so is a `@hidden` field (#1246) — an internal endpoint that is an agent
|
|
101
110
|
* tool is still a tool, and requiring it to be published to customers in order to be one would be
|
|
102
111
|
* exactly the wrong coupling.
|
|
103
112
|
*/
|
|
@@ -38,8 +38,13 @@ exports.OPERATION_SEMANTICS = [
|
|
|
38
38
|
* - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It
|
|
39
39
|
* stays in the private document, and in the MCP document when it is a tool.
|
|
40
40
|
*
|
|
41
|
+
* - `@hidden` in ONE field's JSDoc subtracts that field from the CUSTOMER document only (#1246),
|
|
42
|
+
* with exactly the audience of `{ hidden: true }`: kept in the private document, and in the MCP
|
|
43
|
+
* document and tool catalogs.
|
|
44
|
+
*
|
|
41
45
|
* The per-method case is real and cannot be said at class level: a NEW endpoint on an
|
|
42
|
-
* already-published API, built on main before it is announced. The per-
|
|
46
|
+
* already-published API, built on main before it is announced. The per-field case is the same thing
|
|
47
|
+
* one level down: a new field on an already-published DTO. The per-contract case is the one that
|
|
43
48
|
* must not default to permissive, and at class level naming it costs one token per contract.
|
|
44
49
|
*
|
|
45
50
|
* ## Select, then render — never render, then filter
|
|
@@ -80,7 +85,11 @@ class DocumentSelection {
|
|
|
80
85
|
fileName,
|
|
81
86
|
/** The `@ApiType` a contract must declare to appear in this document. */
|
|
82
87
|
apiType,
|
|
83
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Drop methods marked `{ hidden: true }` AND fields marked `@hidden` (#1246). True for the
|
|
90
|
+
* customer document alone — one flag, because the two are one audience decision at two
|
|
91
|
+
* levels, and a second flag could only ever disagree with the first.
|
|
92
|
+
*/
|
|
84
93
|
dropHidden,
|
|
85
94
|
/** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */
|
|
86
95
|
includeMcpExtensions,
|
|
@@ -132,7 +141,7 @@ class DocumentSelection {
|
|
|
132
141
|
return new DocumentSelection('public-openapi', core_util_1.EXTERNAL_CUSTOMER, true, false, false, false, true, false);
|
|
133
142
|
}
|
|
134
143
|
/**
|
|
135
|
-
* Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent
|
|
144
|
+
* Every contract declaring `MCP`. A HIDDEN method is kept, and so is a `@hidden` field (#1246) — an internal endpoint that is an agent
|
|
136
145
|
* tool is still a tool, and requiring it to be published to customers in order to be one would be
|
|
137
146
|
* exactly the wrong coupling.
|
|
138
147
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentSelection.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocumentSelection.ts"],"names":[],"mappings":";;;AACA,oDAK8B;AAE9B,iGAAiG;AACpF,QAAA,kBAAkB,GAC3B,+MAA+M,CAAC;AAEpN;;;;;;;;;;GAUG;AACU,QAAA,mBAAmB,GAAG;IAC/B,2FAA2F;IAC3F,2FAA2F;IAC3F,uEAAuE;IACvE,EAAE;IACF,+DAA+D;IAC/D,mBAAmB;IACnB,2BAA2B;IAC3B,uCAAuC;IACvC,2BAA2B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;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,CAAC,GAAG;QACN,OAAO;YACH,iBAAiB,CAAC,QAAQ,EAAE;YAC5B,iBAAiB,CAAC,QAAQ,EAAE;YAC5B,iBAAiB,CAAC,GAAG,EAAE;SAC1B,CAAC;IACN,CAAC;IAED,eAAe,CAAC,KAAkB;QAC9B,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;OAQG;IACH,eAAe,CAAC,QAA4B;QACxC,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,mBAAuC,EAAE,SAAkB;QACnE,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,SAAS,EAAE,CAAC;YACZ,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;CACJ;AAjID,8CAiIC","sourcesContent":["import { ApiDocModel, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport {\n ApiTypeKind,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n} from '@webpieces/core-util';\n\n/** The one line that says a document is not the customer contract. It appears in exactly one. */\nexport const INTERNAL_ONLY_LINE =\n 'INTERNAL — service-to-service use only. This document lists every endpoint these services serve, including ones no customer is meant to see. It is not the customer contract and must never be handed to one.';\n\n/**\n * The retry contract, published ONCE per document rather than as booleans stamped on every operation.\n *\n * Each route's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. Webhooks are excluded (#1302): the sentence\n * tells a CALLER whether to repeat a call, and a webhook's caller is us — so a document holding only\n * webhooks states no table at all (see {@link DocumentSelection.description}). Three vendor-extension booleans per\n * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`\n * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn\n * the day the mapping changed.\n */\nexport const OPERATION_SEMANTICS = [\n \"Every route under `paths` states whether it is safe to retry, derived from the endpoint's\",\n 'declared side-effect contract. It covers routes only: a webhook is a call we send, and we',\n 'retry its delivery ourselves, so a webhook carries no retry sentence.',\n '',\n '| declared operation | read-only | destructive | idempotent |',\n '|---|---|---|---|',\n '| read | yes | no | yes |',\n '| write-idempotent | no | yes | yes |',\n '| write | no | yes | no |',\n].join('\\n');\n\n/**\n * WHICH contracts and operations a document contains, and what prose it stamps. The ONLY thing that\n * differs between the three generated documents.\n *\n * ## Two orthogonal decisions, at two levels\n *\n * - `@ApiType(SVC_TO_SVC, EXTERNAL_CUSTOMER)` on the CONTRACT selects which FILES it feeds. A document\n * is written at all only when some contract declares its type, so no contract declaring `MCP` means\n * no `mcp-openapi.json` — there is no second emptiness rule to keep in step with that one.\n * - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It\n * stays in the private document, and in the MCP document when it is a tool.\n *\n * The per-method case is real and cannot be said at class level: a NEW endpoint on an\n * already-published API, built on main before it is announced. The per-contract case is the one that\n * must not default to permissive, and at class level naming it costs one token per contract.\n *\n * ## Select, then render — never render, then filter\n *\n * One render function takes one of these and is called once per document. It builds\n * `components.schemas` by walking OUTWARD from the operations this selection accepted, so an\n * unselected operation's DTOs are never constructed at all.\n *\n * That asymmetry is about what a BUG does. Build-then-filter puts an unreleased feature's full\n * request and response schemas into the document and then relies on a removal pass to take them out\n * again — so a defect in the visibility logic SHIPS them, named and fully shaped, with only the URL\n * missing, to customers who were told the feature was withheld. Select-then-render cannot do that:\n * no code path can emit a schema that was never built.\n *\n * The usual objection to rendering more than once — that the passes drift in how each renders the\n * same endpoint — applies to separate code paths. This is ONE function, so same code, same input,\n * same output.\n *\n * ## The thing that bites: map ordering\n *\n * Collecting schemas during a walk makes the key order of `components.schemas` depend on which\n * operations were walked, so two documents would list identical schemas in different orders and the\n * goldens would churn on unrelated changes. The renderer SORTS the schema keys before emitting.\n * Orders that carry MEANING are left alone and said so where they are built: `apis[]` order is the\n * published sidebar, and the security-scheme order is the order the credentials are declared in.\n */\nexport class DocumentSelection {\n private constructor(\n /** The file name this document is written to, and the name a failure uses for it. */\n readonly fileName: string,\n /** The `@ApiType` a contract must declare to appear in this document. */\n readonly apiType: ApiTypeKind,\n /** Drop methods marked `{ hidden: true }`. True for the customer document alone. */\n readonly dropHidden: boolean,\n /** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */\n readonly includeMcpExtensions: boolean,\n /**\n * Prepend {@link INTERNAL_ONLY_LINE} to `info.description`, and say what TRIGGERS each\n * operation. Both are internal facts: a customer calls what they are given a url for, and\n * whether ours fires on a clock or off a queue is our business.\n */\n readonly internalNotice: boolean,\n /**\n * Define EVERY reached schema locally, whichever package declares it, and write no bundled\n * sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP\n * tooling reads, and MCP never requires a DTO library to publish a components document: an\n * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they\n * `$ref` every other package's schema, and fail closed when that package publishes none.\n */\n readonly inlinesEveryPackage: boolean,\n /**\n * Define a single-use request/response wrapper INLINE at its operation, with its published\n * name as `title`, rather than in `components.schemas` (#1303) — see `InlinedWrappers`. The\n * split documents and their bundled siblings do; the MCP projection keeps every wrapper a\n * component, unchanged.\n */\n readonly inlinesWrappers: boolean,\n /**\n * Stamp the `x-webpieces-*` operation extensions (`x-webpieces-authentication`,\n * `x-webpieces-webhook`). False for the PUBLIC document alone (#1303): they carry source\n * identifiers and internal tooling's facts, and everything a partner needs is already in the\n * standard `security` / `securitySchemes` and `webhooks:` keys.\n */\n readonly includeWebpiecesExtensions: boolean,\n ) {}\n\n /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site\n static internal(): DocumentSelection {\n return new DocumentSelection(\n 'full-private-openapi',\n SVC_TO_SVC,\n false,\n false,\n true,\n false,\n true,\n true,\n );\n }\n\n /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static customer(): DocumentSelection {\n return new DocumentSelection(\n 'public-openapi',\n EXTERNAL_CUSTOMER,\n true,\n false,\n false,\n false,\n true,\n false,\n );\n }\n\n /**\n * Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent\n * tool is still a tool, and requiring it to be published to customers in order to be one would be\n * exactly the wrong coupling.\n */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static mcp(): DocumentSelection {\n return new DocumentSelection('mcp-openapi', MCP, false, true, false, true, false, true);\n }\n\n /** Every document this generator knows how to write, in the order it writes them. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static all(): readonly DocumentSelection[] {\n return [\n DocumentSelection.internal(),\n DocumentSelection.customer(),\n DocumentSelection.mcp(),\n ];\n }\n\n acceptsContract(model: ApiDocModel): boolean {\n return model.apiTypes.includes(this.apiType);\n }\n\n /**\n * `{ hidden: true }` subtracts a method from the CUSTOMER document, and `@WpLocalOnly`\n * subtracts it from ALL of them.\n *\n * A local-only endpoint is not registered as a route at all once the process is deployed, so it\n * exists nowhere any reader of any of these documents could call it. Publishing it even in the\n * private one would document a route that does not exist in any deployed environment — worse\n * than omitting it, because a reader would reasonably try to call it.\n */\n acceptsEndpoint(endpoint: DocumentedEndpoint): boolean {\n if (endpoint.localOnly) {\n return false;\n }\n return !this.dropHidden || !endpoint.hidden;\n }\n\n /**\n * `info.description`: the manifest's prose, plus whatever this document adds to it.\n *\n * `hasRoutes` is false when every operation in the document is a webhook. The retry table then\n * describes a sentence no operation carries, so it is left out (#1302).\n */\n description(manifestDescription: string | undefined, hasRoutes: boolean): string | undefined {\n const parts: string[] = [];\n if (this.internalNotice) {\n parts.push(INTERNAL_ONLY_LINE);\n }\n if (manifestDescription !== undefined) {\n parts.push(manifestDescription);\n }\n if (hasRoutes) {\n parts.push(OPERATION_SEMANTICS);\n }\n return parts.length === 0 ? undefined : parts.join('\\n\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DocumentSelection.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocumentSelection.ts"],"names":[],"mappings":";;;AACA,oDAK8B;AAE9B,iGAAiG;AACpF,QAAA,kBAAkB,GAC3B,+MAA+M,CAAC;AAEpN;;;;;;;;;;GAUG;AACU,QAAA,mBAAmB,GAAG;IAC/B,2FAA2F;IAC3F,2FAA2F;IAC3F,uEAAuE;IACvE,EAAE;IACF,+DAA+D;IAC/D,mBAAmB;IACnB,2BAA2B;IAC3B,uCAAuC;IACvC,2BAA2B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAa,iBAAiB;IAGb;IAEA;IAMA;IAEA;IAMA;IAQA;IAOA;IAOA;IAxCb;IACI,qFAAqF;IAC5E,QAAgB;IACzB,yEAAyE;IAChE,OAAoB;IAC7B;;;;OAIG;IACM,UAAmB;IAC5B,wFAAwF;IAC/E,oBAA6B;IACtC;;;;OAIG;IACM,cAAuB;IAChC;;;;;;OAMG;IACM,mBAA4B;IACrC;;;;;OAKG;IACM,eAAwB;IACjC;;;;;OAKG;IACM,0BAAmC;QAtCnC,aAAQ,GAAR,QAAQ,CAAQ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AAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,mBAAuC,EAAE,SAAkB;QACnE,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,SAAS,EAAE,CAAC;YACZ,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;CACJ;AArID,8CAqIC","sourcesContent":["import { ApiDocModel, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport {\n ApiTypeKind,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n} from '@webpieces/core-util';\n\n/** The one line that says a document is not the customer contract. It appears in exactly one. */\nexport const INTERNAL_ONLY_LINE =\n 'INTERNAL — service-to-service use only. This document lists every endpoint these services serve, including ones no customer is meant to see. It is not the customer contract and must never be handed to one.';\n\n/**\n * The retry contract, published ONCE per document rather than as booleans stamped on every operation.\n *\n * Each route's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. Webhooks are excluded (#1302): the sentence\n * tells a CALLER whether to repeat a call, and a webhook's caller is us — so a document holding only\n * webhooks states no table at all (see {@link DocumentSelection.description}). Three vendor-extension booleans per\n * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`\n * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn\n * the day the mapping changed.\n */\nexport const OPERATION_SEMANTICS = [\n \"Every route under `paths` states whether it is safe to retry, derived from the endpoint's\",\n 'declared side-effect contract. It covers routes only: a webhook is a call we send, and we',\n 'retry its delivery ourselves, so a webhook carries no retry sentence.',\n '',\n '| declared operation | read-only | destructive | idempotent |',\n '|---|---|---|---|',\n '| read | yes | no | yes |',\n '| write-idempotent | no | yes | yes |',\n '| write | no | yes | no |',\n].join('\\n');\n\n/**\n * WHICH contracts and operations a document contains, and what prose it stamps. The ONLY thing that\n * differs between the three generated documents.\n *\n * ## Two orthogonal decisions, at two levels\n *\n * - `@ApiType(SVC_TO_SVC, EXTERNAL_CUSTOMER)` on the CONTRACT selects which FILES it feeds. A document\n * is written at all only when some contract declares its type, so no contract declaring `MCP` means\n * no `mcp-openapi.json` — there is no second emptiness rule to keep in step with that one.\n * - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It\n * stays in the private document, and in the MCP document when it is a tool.\n *\n * - `@hidden` in ONE field's JSDoc subtracts that field from the CUSTOMER document only (#1246),\n * with exactly the audience of `{ hidden: true }`: kept in the private document, and in the MCP\n * document and tool catalogs.\n *\n * The per-method case is real and cannot be said at class level: a NEW endpoint on an\n * already-published API, built on main before it is announced. The per-field case is the same thing\n * one level down: a new field on an already-published DTO. The per-contract case is the one that\n * must not default to permissive, and at class level naming it costs one token per contract.\n *\n * ## Select, then render — never render, then filter\n *\n * One render function takes one of these and is called once per document. It builds\n * `components.schemas` by walking OUTWARD from the operations this selection accepted, so an\n * unselected operation's DTOs are never constructed at all.\n *\n * That asymmetry is about what a BUG does. Build-then-filter puts an unreleased feature's full\n * request and response schemas into the document and then relies on a removal pass to take them out\n * again — so a defect in the visibility logic SHIPS them, named and fully shaped, with only the URL\n * missing, to customers who were told the feature was withheld. Select-then-render cannot do that:\n * no code path can emit a schema that was never built.\n *\n * The usual objection to rendering more than once — that the passes drift in how each renders the\n * same endpoint — applies to separate code paths. This is ONE function, so same code, same input,\n * same output.\n *\n * ## The thing that bites: map ordering\n *\n * Collecting schemas during a walk makes the key order of `components.schemas` depend on which\n * operations were walked, so two documents would list identical schemas in different orders and the\n * goldens would churn on unrelated changes. The renderer SORTS the schema keys before emitting.\n * Orders that carry MEANING are left alone and said so where they are built: `apis[]` order is the\n * published sidebar, and the security-scheme order is the order the credentials are declared in.\n */\nexport class DocumentSelection {\n private constructor(\n /** The file name this document is written to, and the name a failure uses for it. */\n readonly fileName: string,\n /** The `@ApiType` a contract must declare to appear in this document. */\n readonly apiType: ApiTypeKind,\n /**\n * Drop methods marked `{ hidden: true }` AND fields marked `@hidden` (#1246). True for the\n * customer document alone — one flag, because the two are one audience decision at two\n * levels, and a second flag could only ever disagree with the first.\n */\n readonly dropHidden: boolean,\n /** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */\n readonly includeMcpExtensions: boolean,\n /**\n * Prepend {@link INTERNAL_ONLY_LINE} to `info.description`, and say what TRIGGERS each\n * operation. Both are internal facts: a customer calls what they are given a url for, and\n * whether ours fires on a clock or off a queue is our business.\n */\n readonly internalNotice: boolean,\n /**\n * Define EVERY reached schema locally, whichever package declares it, and write no bundled\n * sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP\n * tooling reads, and MCP never requires a DTO library to publish a components document: an\n * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they\n * `$ref` every other package's schema, and fail closed when that package publishes none.\n */\n readonly inlinesEveryPackage: boolean,\n /**\n * Define a single-use request/response wrapper INLINE at its operation, with its published\n * name as `title`, rather than in `components.schemas` (#1303) — see `InlinedWrappers`. The\n * split documents and their bundled siblings do; the MCP projection keeps every wrapper a\n * component, unchanged.\n */\n readonly inlinesWrappers: boolean,\n /**\n * Stamp the `x-webpieces-*` operation extensions (`x-webpieces-authentication`,\n * `x-webpieces-webhook`). False for the PUBLIC document alone (#1303): they carry source\n * identifiers and internal tooling's facts, and everything a partner needs is already in the\n * standard `security` / `securitySchemes` and `webhooks:` keys.\n */\n readonly includeWebpiecesExtensions: boolean,\n ) {}\n\n /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site\n static internal(): DocumentSelection {\n return new DocumentSelection(\n 'full-private-openapi',\n SVC_TO_SVC,\n false,\n false,\n true,\n false,\n true,\n true,\n );\n }\n\n /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static customer(): DocumentSelection {\n return new DocumentSelection(\n 'public-openapi',\n EXTERNAL_CUSTOMER,\n true,\n false,\n false,\n false,\n true,\n false,\n );\n }\n\n /**\n * Every contract declaring `MCP`. A HIDDEN method is kept, and so is a `@hidden` field (#1246) — an internal endpoint that is an agent\n * tool is still a tool, and requiring it to be published to customers in order to be one would be\n * exactly the wrong coupling.\n */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static mcp(): DocumentSelection {\n return new DocumentSelection('mcp-openapi', MCP, false, true, false, true, false, true);\n }\n\n /** Every document this generator knows how to write, in the order it writes them. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static all(): readonly DocumentSelection[] {\n return [\n DocumentSelection.internal(),\n DocumentSelection.customer(),\n DocumentSelection.mcp(),\n ];\n }\n\n acceptsContract(model: ApiDocModel): boolean {\n return model.apiTypes.includes(this.apiType);\n }\n\n /**\n * `{ hidden: true }` subtracts a method from the CUSTOMER document, and `@WpLocalOnly`\n * subtracts it from ALL of them.\n *\n * A local-only endpoint is not registered as a route at all once the process is deployed, so it\n * exists nowhere any reader of any of these documents could call it. Publishing it even in the\n * private one would document a route that does not exist in any deployed environment — worse\n * than omitting it, because a reader would reasonably try to call it.\n */\n acceptsEndpoint(endpoint: DocumentedEndpoint): boolean {\n if (endpoint.localOnly) {\n return false;\n }\n return !this.dropHidden || !endpoint.hidden;\n }\n\n /**\n * `info.description`: the manifest's prose, plus whatever this document adds to it.\n *\n * `hasRoutes` is false when every operation in the document is a webhook. The retry table then\n * describes a sentence no operation carries, so it is left out (#1302).\n */\n description(manifestDescription: string | undefined, hasRoutes: boolean): string | undefined {\n const parts: string[] = [];\n if (this.internalNotice) {\n parts.push(INTERNAL_ONLY_LINE);\n }\n if (manifestDescription !== undefined) {\n parts.push(manifestDescription);\n }\n if (hasRoutes) {\n parts.push(OPERATION_SEMANTICS);\n }\n return parts.length === 0 ? undefined : parts.join('\\n\\n');\n }\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DocumentedType } from '@webpieces/api-doc-model';
|
|
2
|
+
/**
|
|
3
|
+
* The refusals for the field-level `@hidden` JSDoc tag (#1246).
|
|
4
|
+
*
|
|
5
|
+
* `@hidden` withholds ONE field of a DTO from the customer document (`public-openapi.json` and its
|
|
6
|
+
* bundled sibling), the way `@Endpoint(..., { hidden: true })` withholds a whole method. The customer
|
|
7
|
+
* document then describes a SUBSET of the wire shape, and that is honest only when the subset is
|
|
8
|
+
* itself a shape the server accepts and returns. Two declarations break that, and both are refused
|
|
9
|
+
* before anything is rendered, every offender named in one run, with no switch to turn them off:
|
|
10
|
+
*
|
|
11
|
+
* 1. **A hidden field that is REQUIRED.** The customer schema would omit a property the server
|
|
12
|
+
* insists on: every request a partner builds from the document is rejected, and every response we
|
|
13
|
+
* send carries a property the document says does not exist. Make it optional (`name?:`).
|
|
14
|
+
* 2. **A type whose EVERY field is hidden.** Its customer schema is an empty object that is still
|
|
15
|
+
* referenced — a published noun with nothing in it. Hide the method, or the field that holds the
|
|
16
|
+
* type, instead.
|
|
17
|
+
*
|
|
18
|
+
* A hidden field on a type only a hidden METHOD reaches needs nothing here: the method, and with it
|
|
19
|
+
* every schema only it reaches, is already absent from the customer document.
|
|
20
|
+
*
|
|
21
|
+
* A third refusal is per DOCUMENT rather than per type, and is {@link refuseExternal}: a split
|
|
22
|
+
* customer document `$ref`s another package's type into that package's components document, which
|
|
23
|
+
* every audience shares, so it cannot withhold a field there.
|
|
24
|
+
*/
|
|
25
|
+
export declare class HiddenFieldGuard {
|
|
26
|
+
/** Refuse every required hidden field and every all-hidden type among `types`. */
|
|
27
|
+
refuse(types: ReadonlyMap<string, DocumentedType>, where: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Refuse when a split customer document references, in another package's components document, a
|
|
30
|
+
* type that has a hidden field (#1246).
|
|
31
|
+
*
|
|
32
|
+
* A components document is ONE document for every audience — the private document and the
|
|
33
|
+
* customer document `$ref` the same schema — so it carries every field. Withholding the field
|
|
34
|
+
* from the customer document would mean defining that package's schema a second time, which the
|
|
35
|
+
* one-owner rule (#1058) forbids; publishing it would leak the field. Neither is acceptable, so
|
|
36
|
+
* the declaration is refused.
|
|
37
|
+
*/
|
|
38
|
+
refuseExternal(externalKeys: ReadonlySet<string>, types: ReadonlyMap<string, DocumentedType>, fileName: string, where: string): void;
|
|
39
|
+
private collect;
|
|
40
|
+
private record;
|
|
41
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HiddenFieldGuard = void 0;
|
|
4
|
+
const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
|
|
5
|
+
/**
|
|
6
|
+
* The refusals for the field-level `@hidden` JSDoc tag (#1246).
|
|
7
|
+
*
|
|
8
|
+
* `@hidden` withholds ONE field of a DTO from the customer document (`public-openapi.json` and its
|
|
9
|
+
* bundled sibling), the way `@Endpoint(..., { hidden: true })` withholds a whole method. The customer
|
|
10
|
+
* document then describes a SUBSET of the wire shape, and that is honest only when the subset is
|
|
11
|
+
* itself a shape the server accepts and returns. Two declarations break that, and both are refused
|
|
12
|
+
* before anything is rendered, every offender named in one run, with no switch to turn them off:
|
|
13
|
+
*
|
|
14
|
+
* 1. **A hidden field that is REQUIRED.** The customer schema would omit a property the server
|
|
15
|
+
* insists on: every request a partner builds from the document is rejected, and every response we
|
|
16
|
+
* send carries a property the document says does not exist. Make it optional (`name?:`).
|
|
17
|
+
* 2. **A type whose EVERY field is hidden.** Its customer schema is an empty object that is still
|
|
18
|
+
* referenced — a published noun with nothing in it. Hide the method, or the field that holds the
|
|
19
|
+
* type, instead.
|
|
20
|
+
*
|
|
21
|
+
* A hidden field on a type only a hidden METHOD reaches needs nothing here: the method, and with it
|
|
22
|
+
* every schema only it reaches, is already absent from the customer document.
|
|
23
|
+
*
|
|
24
|
+
* A third refusal is per DOCUMENT rather than per type, and is {@link refuseExternal}: a split
|
|
25
|
+
* customer document `$ref`s another package's type into that package's components document, which
|
|
26
|
+
* every audience shares, so it cannot withhold a field there.
|
|
27
|
+
*/
|
|
28
|
+
class HiddenFieldGuard {
|
|
29
|
+
/** Refuse every required hidden field and every all-hidden type among `types`. */
|
|
30
|
+
refuse(types, where) {
|
|
31
|
+
const required = new Map();
|
|
32
|
+
const allHidden = new Map();
|
|
33
|
+
for (const type of Array.from(types.values())) {
|
|
34
|
+
this.collect(type, required, allHidden);
|
|
35
|
+
}
|
|
36
|
+
if (required.size === 0 && allHidden.size === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// ONE refusal naming both kinds, so an author is handed every offender in a single run.
|
|
40
|
+
throw new OpenApiGenerationError_1.OpenApiGenerationError(`${required.size} @hidden field(s) are required, and ${allHidden.size} type(s) have every ` +
|
|
41
|
+
'field @hidden, so the customer document would describe a shape the server does not ' +
|
|
42
|
+
'accept or return', where, 'Make each REQUIRED hidden field optional (`name?: T`) — a hidden field must be one a ' +
|
|
43
|
+
'partner may leave out and may not receive — or remove its @hidden tag. For a type ' +
|
|
44
|
+
'with EVERY field hidden, hide the method that reaches it (`@Endpoint(..., { hidden: ' +
|
|
45
|
+
'true })`) or mark the FIELD that holds it @hidden instead.', [
|
|
46
|
+
...Array.from(required.values()).map((each) => `required: ${each}`),
|
|
47
|
+
...Array.from(allHidden.values()).map((each) => `every field hidden: ${each}`),
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Refuse when a split customer document references, in another package's components document, a
|
|
52
|
+
* type that has a hidden field (#1246).
|
|
53
|
+
*
|
|
54
|
+
* A components document is ONE document for every audience — the private document and the
|
|
55
|
+
* customer document `$ref` the same schema — so it carries every field. Withholding the field
|
|
56
|
+
* from the customer document would mean defining that package's schema a second time, which the
|
|
57
|
+
* one-owner rule (#1058) forbids; publishing it would leak the field. Neither is acceptable, so
|
|
58
|
+
* the declaration is refused.
|
|
59
|
+
*/
|
|
60
|
+
refuseExternal(externalKeys, types, fileName, where) {
|
|
61
|
+
const offenders = [];
|
|
62
|
+
for (const key of Array.from(externalKeys).sort()) {
|
|
63
|
+
const type = types.get(key);
|
|
64
|
+
if (type === undefined) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const field of type.fields) {
|
|
68
|
+
if (field.hidden) {
|
|
69
|
+
offenders.push(`${type.name}.${field.name} — declared in ${type.packageName ?? 'no package'} (${field.location})`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (offenders.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
throw new OpenApiGenerationError_1.OpenApiGenerationError(`${offenders.length} @hidden field(s) are on types ${fileName} references in another ` +
|
|
77
|
+
"package's components document, which every audience shares, so the field cannot be " +
|
|
78
|
+
'withheld from the customer document', where, "Declare the type in the contract's own package, so the customer document defines its " +
|
|
79
|
+
'schema and can omit the field — or remove the @hidden tag if the field may be published.', offenders);
|
|
80
|
+
}
|
|
81
|
+
collect(type, required, allHidden) {
|
|
82
|
+
let hiddenCount = 0;
|
|
83
|
+
for (const field of type.fields) {
|
|
84
|
+
if (!field.hidden) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
hiddenCount += 1;
|
|
88
|
+
if (!field.optional) {
|
|
89
|
+
this.record(required, field, `${type.name}.${field.name} (${field.location})`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (hiddenCount > 0 && hiddenCount === type.fields.length) {
|
|
93
|
+
allHidden.set(type.location, `${type.name} (${type.location})`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
record(into, field, text) {
|
|
97
|
+
if (!into.has(field.location)) {
|
|
98
|
+
into.set(field.location, text);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.HiddenFieldGuard = HiddenFieldGuard;
|
|
103
|
+
//# sourceMappingURL=HiddenFieldGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HiddenFieldGuard.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/HiddenFieldGuard.ts"],"names":[],"mappings":";;;AACA,sEAAmE;AAEnE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,gBAAgB;IACzB,kFAAkF;IAClF,MAAM,CAAC,KAA0C,EAAE,KAAa;QAC5D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC5C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC9C,OAAO;QACX,CAAC;QACD,wFAAwF;QACxF,MAAM,IAAI,+CAAsB,CAC5B,GAAG,QAAQ,CAAC,IAAI,uCAAuC,SAAS,CAAC,IAAI,sBAAsB;YACvF,qFAAqF;YACrF,kBAAkB,EACtB,KAAK,EACL,uFAAuF;YACnF,oFAAoF;YACpF,sFAAsF;YACtF,4DAA4D,EAChE;YACI,GAAG,KAAK,CAAC,IAAI,CA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8B;QAE9B,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC9B,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBAChB,SAAS;YACb,CAAC;YACD,WAAW,IAAI,CAAC,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAClB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;YACnF,CAAC;QACL,CAAC;QACD,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACxD,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QACpE,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,IAAyB,EAAE,KAAsB,EAAE,IAAY;QAC1E,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;CACJ;AAnGD,4CAmGC","sourcesContent":["import { DocumentedField, DocumentedType } from '@webpieces/api-doc-model';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\n/**\n * The refusals for the field-level `@hidden` JSDoc tag (#1246).\n *\n * `@hidden` withholds ONE field of a DTO from the customer document (`public-openapi.json` and its\n * bundled sibling), the way `@Endpoint(..., { hidden: true })` withholds a whole method. The customer\n * document then describes a SUBSET of the wire shape, and that is honest only when the subset is\n * itself a shape the server accepts and returns. Two declarations break that, and both are refused\n * before anything is rendered, every offender named in one run, with no switch to turn them off:\n *\n * 1. **A hidden field that is REQUIRED.** The customer schema would omit a property the server\n * insists on: every request a partner builds from the document is rejected, and every response we\n * send carries a property the document says does not exist. Make it optional (`name?:`).\n * 2. **A type whose EVERY field is hidden.** Its customer schema is an empty object that is still\n * referenced — a published noun with nothing in it. Hide the method, or the field that holds the\n * type, instead.\n *\n * A hidden field on a type only a hidden METHOD reaches needs nothing here: the method, and with it\n * every schema only it reaches, is already absent from the customer document.\n *\n * A third refusal is per DOCUMENT rather than per type, and is {@link refuseExternal}: a split\n * customer document `$ref`s another package's type into that package's components document, which\n * every audience shares, so it cannot withhold a field there.\n */\nexport class HiddenFieldGuard {\n /** Refuse every required hidden field and every all-hidden type among `types`. */\n refuse(types: ReadonlyMap<string, DocumentedType>, where: string): void {\n const required = new Map<string, string>();\n const allHidden = new Map<string, string>();\n for (const type of Array.from(types.values())) {\n this.collect(type, required, allHidden);\n }\n if (required.size === 0 && allHidden.size === 0) {\n return;\n }\n // ONE refusal naming both kinds, so an author is handed every offender in a single run.\n throw new OpenApiGenerationError(\n `${required.size} @hidden field(s) are required, and ${allHidden.size} type(s) have every ` +\n 'field @hidden, so the customer document would describe a shape the server does not ' +\n 'accept or return',\n where,\n 'Make each REQUIRED hidden field optional (`name?: T`) — a hidden field must be one a ' +\n 'partner may leave out and may not receive — or remove its @hidden tag. For a type ' +\n 'with EVERY field hidden, hide the method that reaches it (`@Endpoint(..., { hidden: ' +\n 'true })`) or mark the FIELD that holds it @hidden instead.',\n [\n ...Array.from(required.values()).map((each: string) => `required: ${each}`),\n ...Array.from(allHidden.values()).map(\n (each: string) => `every field hidden: ${each}`,\n ),\n ],\n );\n }\n\n /**\n * Refuse when a split customer document references, in another package's components document, a\n * type that has a hidden field (#1246).\n *\n * A components document is ONE document for every audience — the private document and the\n * customer document `$ref` the same schema — so it carries every field. Withholding the field\n * from the customer document would mean defining that package's schema a second time, which the\n * one-owner rule (#1058) forbids; publishing it would leak the field. Neither is acceptable, so\n * the declaration is refused.\n */\n refuseExternal(\n externalKeys: ReadonlySet<string>,\n types: ReadonlyMap<string, DocumentedType>,\n fileName: string,\n where: string,\n ): void {\n const offenders: string[] = [];\n for (const key of Array.from(externalKeys).sort()) {\n const type = types.get(key);\n if (type === undefined) {\n continue;\n }\n for (const field of type.fields) {\n if (field.hidden) {\n offenders.push(\n `${type.name}.${field.name} — declared in ${type.packageName ?? 'no package'} (${field.location})`,\n );\n }\n }\n }\n if (offenders.length === 0) {\n return;\n }\n throw new OpenApiGenerationError(\n `${offenders.length} @hidden field(s) are on types ${fileName} references in another ` +\n \"package's components document, which every audience shares, so the field cannot be \" +\n 'withheld from the customer document',\n where,\n \"Declare the type in the contract's own package, so the customer document defines its \" +\n 'schema and can omit the field — or remove the @hidden tag if the field may be published.',\n offenders,\n );\n }\n\n private collect(\n type: DocumentedType,\n required: Map<string, string>,\n allHidden: Map<string, string>,\n ): void {\n let hiddenCount = 0;\n for (const field of type.fields) {\n if (!field.hidden) {\n continue;\n }\n hiddenCount += 1;\n if (!field.optional) {\n this.record(required, field, `${type.name}.${field.name} (${field.location})`);\n }\n }\n if (hiddenCount > 0 && hiddenCount === type.fields.length) {\n allHidden.set(type.location, `${type.name} (${type.location})`);\n }\n }\n\n private record(into: Map<string, string>, field: DocumentedField, text: string): void {\n if (!into.has(field.location)) {\n into.set(field.location, text);\n }\n }\n}\n"]}
|
|
@@ -36,7 +36,9 @@ import { ComponentsInputs, GeneratedDocument, GeneratedDocuments, GenerationInpu
|
|
|
36
36
|
* one run (#1292). Likewise an operation with no valid `@summary` ({@link SummaryGuard}) and an MCP
|
|
37
37
|
* tool whose name the Claude Connectors Directory would refuse ({@link McpToolNameGuard}) (#1296).
|
|
38
38
|
* And a JSDoc `{@link}` the document cannot publish under its target's published name
|
|
39
|
-
* ({@link DocLinkGuard}) (#1284).
|
|
39
|
+
* ({@link DocLinkGuard}) (#1284) — a `@hidden` field's included, in the customer document. And a
|
|
40
|
+
* `@hidden` field that is required, or a type whose every field is `@hidden` ({@link HiddenFieldGuard})
|
|
41
|
+
* (#1246).
|
|
40
42
|
*/
|
|
41
43
|
export declare class OpenApiGenerator {
|
|
42
44
|
private readonly security;
|
|
@@ -45,6 +47,8 @@ export declare class OpenApiGenerator {
|
|
|
45
47
|
private readonly summaries;
|
|
46
48
|
private readonly toolNames;
|
|
47
49
|
private readonly tagOwnership;
|
|
50
|
+
private readonly hiddenFields;
|
|
51
|
+
private readonly unpublished;
|
|
48
52
|
/**
|
|
49
53
|
* ONE document per `@ApiType` some contract declares, and no others.
|
|
50
54
|
*
|
|
@@ -112,12 +116,11 @@ export declare class OpenApiGenerator {
|
|
|
112
116
|
/** `Contract.method` -> operationId, for every operation this document publishes. */
|
|
113
117
|
private publishedOperationIds;
|
|
114
118
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* exactly the duplication this replaces. A document that exists but lacks the schema is stale.
|
|
119
|
+
* A split document's references into other packages' components documents: each must be
|
|
120
|
+
* published there (#1058), and — in the customer document — none may carry a `@hidden` field,
|
|
121
|
+
* which a shared components document cannot withhold (#1246).
|
|
119
122
|
*/
|
|
120
|
-
private
|
|
123
|
+
private refuseExternalReferences;
|
|
121
124
|
/**
|
|
122
125
|
* A webhook is served by the PARTNER, so neither our failure envelope nor the header we stamp on
|
|
123
126
|
* our own responses is true of it. Publishing either would document their server, not ours.
|