@webpieces/openapi-generator 0.4.828 → 0.4.830

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.
Files changed (38) hide show
  1. package/README.md +47 -1
  2. package/package.json +3 -3
  3. package/src/cli/OpenApiCli.d.ts +5 -0
  4. package/src/cli/OpenApiCli.js +27 -1
  5. package/src/cli/OpenApiCli.js.map +1 -1
  6. package/src/generate/DocumentSelection.d.ts +8 -0
  7. package/src/generate/DocumentSelection.js +14 -4
  8. package/src/generate/DocumentSelection.js.map +1 -1
  9. package/src/generate/GenerationInputs.d.ts +34 -3
  10. package/src/generate/GenerationInputs.js +33 -2
  11. package/src/generate/GenerationInputs.js.map +1 -1
  12. package/src/generate/OpenApiGenerator.d.ts +43 -4
  13. package/src/generate/OpenApiGenerator.js +142 -10
  14. package/src/generate/OpenApiGenerator.js.map +1 -1
  15. package/src/generate/SchemaPlacement.d.ts +82 -0
  16. package/src/generate/SchemaPlacement.js +126 -0
  17. package/src/generate/SchemaPlacement.js.map +1 -0
  18. package/src/generate/SchemaRenderer.d.ts +27 -2
  19. package/src/generate/SchemaRenderer.js +57 -11
  20. package/src/generate/SchemaRenderer.js.map +1 -1
  21. package/src/generate/UpstreamComponents.d.ts +43 -0
  22. package/src/generate/UpstreamComponents.js +68 -0
  23. package/src/generate/UpstreamComponents.js.map +1 -0
  24. package/src/index.d.ts +6 -2
  25. package/src/index.js +16 -1
  26. package/src/index.js.map +1 -1
  27. package/src/load/ComponentsLocator.d.ts +44 -0
  28. package/src/load/ComponentsLocator.js +127 -0
  29. package/src/load/ComponentsLocator.js.map +1 -0
  30. package/src/load/InputsLoader.d.ts +14 -1
  31. package/src/load/InputsLoader.js +79 -1
  32. package/src/load/InputsLoader.js.map +1 -1
  33. package/src/manifest/ManifestLoader.d.ts +10 -2
  34. package/src/manifest/ManifestLoader.js +53 -3
  35. package/src/manifest/ManifestLoader.js.map +1 -1
  36. package/src/manifest/OpenApiManifest.d.ts +17 -0
  37. package/src/manifest/OpenApiManifest.js +21 -1
  38. package/src/manifest/OpenApiManifest.js.map +1 -1
@@ -1,5 +1,6 @@
1
1
  import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';
2
2
  import { JsonObject } from '../json/JsonObject';
3
+ import { SchemaPlacement } from './SchemaPlacement';
3
4
  /** ONE field the renderer could not give a shape to, and WHERE in the document it would have sat. */
4
5
  export declare class UnmappedField {
5
6
  /** A JSON pointer into the document that would have been written. */
@@ -32,14 +33,28 @@ export declare class UnmappedField {
32
33
  * An unmapped type yields an EMPTY schema, which in JSON Schema means "anything". That is precisely
33
34
  * the green-build-publishes-a-shapeless-field defect the guard exists to stop, so every one is
34
35
  * recorded with the pointer it would have occupied and {@link OpenApiGenerator} refuses on the set.
36
+ *
37
+ * ## WHERE a schema is defined is the placement's answer, not this class's (#1058)
38
+ *
39
+ * The {@link SchemaPlacement} decides, per type, whether its schema is defined in THIS document's
40
+ * `components.schemas` (and under which name) or referenced in another package's components
41
+ * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —
42
+ * is written through it, so the split, the bundled and the MCP document are one renderer.
35
43
  */
36
44
  export declare class SchemaRenderer {
45
+ /** The model's named types, by key (`DocumentedType.keyOf`). */
37
46
  private readonly types;
47
+ private readonly placement;
38
48
  private readonly reached;
49
+ private readonly external;
39
50
  private readonly unmappedFields;
40
- constructor(types: ReadonlyMap<string, DocumentedType>);
41
- /** Named types this renderer has been asked for, directly or through another schema. */
51
+ constructor(
52
+ /** The model's named types, by key (`DocumentedType.keyOf`). */
53
+ types: ReadonlyMap<string, DocumentedType>, placement: SchemaPlacement);
54
+ /** Keys of the named types this document DEFINES, reached directly or through another schema. */
42
55
  reachedTypes(): ReadonlySet<string>;
56
+ /** Keys of the named types this document REFERENCES in another package's components document. */
57
+ externalTypes(): ReadonlySet<string>;
43
58
  /** Every field with no shape, with its pointer. Empty means the document is fully typed. */
44
59
  unmapped(): readonly UnmappedField[];
45
60
  /**
@@ -51,6 +66,11 @@ export declare class SchemaRenderer {
51
66
  * named type is registered once, so the worklist strictly shrinks.
52
67
  */
53
68
  components(): JsonObject;
69
+ /**
70
+ * Mark `key` as DEFINED by this document even when nothing in it refers to the type — the
71
+ * components document of a DTO library publishes every type the library exports (#1058).
72
+ */
73
+ define(key: string): void;
54
74
  /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */
55
75
  private namedType;
56
76
  /**
@@ -84,7 +104,12 @@ export declare class SchemaRenderer {
84
104
  */
85
105
  private namedUnion;
86
106
  private primitive;
107
+ /**
108
+ * A `$ref` to the type registered under `key`, recording whether this document defines it or
109
+ * references it in its declaring package's components document.
110
+ */
87
111
  private reference;
112
+ private pointerTo;
88
113
  /** Empty prose is ABSENT prose. An empty `description` key is noise in every rendered page. */
89
114
  private prose;
90
115
  }
@@ -36,18 +36,34 @@ exports.UnmappedField = UnmappedField;
36
36
  * An unmapped type yields an EMPTY schema, which in JSON Schema means "anything". That is precisely
37
37
  * the green-build-publishes-a-shapeless-field defect the guard exists to stop, so every one is
38
38
  * recorded with the pointer it would have occupied and {@link OpenApiGenerator} refuses on the set.
39
+ *
40
+ * ## WHERE a schema is defined is the placement's answer, not this class's (#1058)
41
+ *
42
+ * The {@link SchemaPlacement} decides, per type, whether its schema is defined in THIS document's
43
+ * `components.schemas` (and under which name) or referenced in another package's components
44
+ * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —
45
+ * is written through it, so the split, the bundled and the MCP document are one renderer.
39
46
  */
40
47
  class SchemaRenderer {
41
48
  types;
49
+ placement;
42
50
  reached = new Set();
51
+ external = new Set();
43
52
  unmappedFields = [];
44
- constructor(types) {
53
+ constructor(
54
+ /** The model's named types, by key (`DocumentedType.keyOf`). */
55
+ types, placement) {
45
56
  this.types = types;
57
+ this.placement = placement;
46
58
  }
47
- /** Named types this renderer has been asked for, directly or through another schema. */
59
+ /** Keys of the named types this document DEFINES, reached directly or through another schema. */
48
60
  reachedTypes() {
49
61
  return this.reached;
50
62
  }
63
+ /** Keys of the named types this document REFERENCES in another package's components document. */
64
+ externalTypes() {
65
+ return this.external;
66
+ }
51
67
  /** Every field with no shape, with its pointer. Empty means the document is fully typed. */
52
68
  unmapped() {
53
69
  return this.unmappedFields;
@@ -65,13 +81,14 @@ class SchemaRenderer {
65
81
  let grew = true;
66
82
  while (grew) {
67
83
  grew = false;
68
- for (const name of Array.from(this.reached)) {
84
+ for (const key of Array.from(this.reached)) {
85
+ const type = this.types.get(key);
86
+ const name = type === undefined ? key : this.placement.localName(key, type);
69
87
  if (rendered.has(name)) {
70
88
  continue;
71
89
  }
72
- const type = this.types.get(name);
73
90
  // Rendering it can add MORE names to `reached`, which is what the outer loop is for.
74
- rendered.set(name, type === undefined ? undefined : this.namedType(type));
91
+ rendered.set(name, type === undefined ? undefined : this.namedType(key, type));
75
92
  grew = true;
76
93
  }
77
94
  }
@@ -83,9 +100,19 @@ class SchemaRenderer {
83
100
  }
84
101
  return schemas;
85
102
  }
103
+ /**
104
+ * Mark `key` as DEFINED by this document even when nothing in it refers to the type — the
105
+ * components document of a DTO library publishes every type the library exports (#1058).
106
+ */
107
+ define(key) {
108
+ const type = this.types.get(key);
109
+ if (type !== undefined && this.placement.isLocal(key, type)) {
110
+ this.reached.add(key);
111
+ }
112
+ }
86
113
  /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */
87
- namedType(type) {
88
- const pointer = `#/components/schemas/${type.name}`;
114
+ namedType(key, type) {
115
+ const pointer = `#/components/schemas/${this.placement.localName(key, type)}`;
89
116
  if (type.enumValues.length > 0) {
90
117
  return new JsonObject_1.JsonObject()
91
118
  .set('type', 'string')
@@ -131,7 +158,7 @@ class SchemaRenderer {
131
158
  // entries pointing at one schema, which OpenAPI's mapping allows (#1023).
132
159
  for (const branch of type.unionRefNames) {
133
160
  for (const value of type.discriminator.branchValues.get(branch) ?? []) {
134
- mapping.set(value, `#/components/schemas/${branch}`);
161
+ mapping.set(value, this.pointerTo(branch));
135
162
  }
136
163
  }
137
164
  return schema.set('discriminator', new JsonObject_1.JsonObject()
@@ -225,9 +252,28 @@ class SchemaRenderer {
225
252
  }
226
253
  return new JsonObject_1.JsonObject().set('type', ref.integer ? 'integer' : ref.primitive);
227
254
  }
228
- reference(name) {
229
- this.reached.add(name);
230
- return new JsonObject_1.JsonObject().set('$ref', `#/components/schemas/${name}`);
255
+ /**
256
+ * A `$ref` to the type registered under `key`, recording whether this document defines it or
257
+ * references it in its declaring package's components document.
258
+ */
259
+ reference(key) {
260
+ return new JsonObject_1.JsonObject().set('$ref', this.pointerTo(key));
261
+ }
262
+ pointerTo(key) {
263
+ const type = this.types.get(key);
264
+ if (type === undefined) {
265
+ // Not in the model at all (a manifest naming an error type that does not exist): keep it
266
+ // local so `components()` writes the hole the guards then name.
267
+ this.reached.add(key);
268
+ return `#/components/schemas/${key}`;
269
+ }
270
+ if (this.placement.isLocal(key, type)) {
271
+ this.reached.add(key);
272
+ }
273
+ else {
274
+ this.external.add(key);
275
+ }
276
+ return this.placement.pointer(key, type);
231
277
  }
232
278
  /** Empty prose is ABSENT prose. An empty `description` key is noise in every rendered page. */
233
279
  prose(text) {
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SchemaRenderer.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAE3D,qGAAqG;AACrG,MAAa,aAAa;IAGT;IAEA;IAJb;IACI,qEAAqE;IAC5D,OAAe;IACxB,qFAAqF;IAC5E,QAAgB;QAFhB,YAAO,GAAP,OAAO,CAAQ;QAEf,aAAQ,GAAR,QAAQ,CAAQ;IAC1B,CAAC;CACP;AAPD,sCAOC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,cAAc;IAIM;IAHZ,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,cAAc,GAAoB,EAAE,CAAC;IAEtD,YAA6B,KAA0C;QAA1C,UAAK,GAAL,KAA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C,SAAS,CAAC,IAAI,CAAC,CAAC,CAChE,CAAC;IACN,CAAC;IAEO,SAAS,CAAC,GAAY;QAC1B,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAC9B,0FAA0F;YAC1F,mEAAmE;YACnE,OAAO,IAAI,uBAAU,EAAE,CAAC;QAC5B,CAAC;QACD,OAAO,IAAI,uBAAU,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,SAAU,CAAC,CAAC;IAClF,CAAC;IAEO,SAAS,CAAC,IAAY;QAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvB,OAAO,IAAI,uBAAU,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,wBAAwB,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,+FAA+F;IACvF,KAAK,CAAC,IAAwB;QAClC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;CACJ;AAnOD,wCAmOC","sourcesContent":["import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\n\n/** ONE field the renderer could not give a shape to, and WHERE in the document it would have sat. */\nexport class UnmappedField {\n constructor(\n /** A JSON pointer into the document that would have been written. */\n readonly pointer: string,\n /** The verbatim TypeScript type text, so the cure names the thing to go and type. */\n readonly typeText: string,\n ) {}\n}\n\n/**\n * {@link TypeRef} / {@link DocumentedType} -> JSON Schema 2020-12, which IS OpenAPI 3.1's schema\n * dialect and IS what MCP `tools/list` speaks. That identity is the reason #982 specifies 3.1 rather\n * than 3.0: the two are not \"similar dialects\", they are the same schemas, so the MCP projection\n * (#984) is a selection and an inline pass, not a translation.\n *\n * ## Three things 3.1 lets this renderer state HONESTLY that 3.0 could not\n *\n * - `type: [T, \"null\"]` for a nullable field, instead of 3.0's `nullable: true` keyword, which is not\n * JSON Schema at all.\n * - `description` BESIDE a `$ref`. In 3.0 a sibling of `$ref` is ignored, so a documented field whose\n * type is a named DTO simply lost its prose.\n * - OPTIONAL and NULLABLE as separate facts — absent from `required` versus `\"null\"` in `type`. `{}`\n * and `{x: null}` are different wire documents and a schema that conflates them rejects one.\n *\n * ## It records what it cannot map rather than emitting an untyped field\n *\n * An unmapped type yields an EMPTY schema, which in JSON Schema means \"anything\". That is precisely\n * the green-build-publishes-a-shapeless-field defect the guard exists to stop, so every one is\n * recorded with the pointer it would have occupied and {@link OpenApiGenerator} refuses on the set.\n */\nexport class SchemaRenderer {\n private readonly reached = new Set<string>();\n private readonly unmappedFields: UnmappedField[] = [];\n\n constructor(private readonly types: ReadonlyMap<string, DocumentedType>) {}\n\n /** Named types this renderer has been asked for, directly or through another schema. */\n reachedTypes(): ReadonlySet<string> {\n return this.reached;\n }\n\n /** Every field with no shape, with its pointer. Empty means the document is fully typed. */\n unmapped(): readonly UnmappedField[] {\n return this.unmappedFields;\n }\n\n /**\n * `components.schemas` for everything reachable from whatever has been rendered so far, expanded\n * to a FIXPOINT.\n *\n * A worklist and not recursion-with-a-guard because rendering a type reaches more types, and the\n * set has to close over that. It terminates for the same reason the extractor's walk does: a\n * named type is registered once, so the worklist strictly shrinks.\n */\n components(): JsonObject {\n const rendered = new Map<string, JsonObject | undefined>();\n let grew = true;\n while (grew) {\n grew = false;\n for (const name of Array.from(this.reached)) {\n if (rendered.has(name)) {\n continue;\n }\n const type = this.types.get(name);\n // Rendering it can add MORE names to `reached`, which is what the outer loop is for.\n rendered.set(name, type === undefined ? undefined : this.namedType(type));\n grew = true;\n }\n }\n const schemas = new JsonObject();\n // Alphabetical, because `components.schemas` is a lookup table and nothing reads it in order\n // — whereas discovery order would move every time an operation was added above another.\n for (const name of Array.from(rendered.keys()).sort()) {\n schemas.set(name, rendered.get(name));\n }\n return schemas;\n }\n\n /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */\n private namedType(type: DocumentedType): JsonObject {\n const pointer = `#/components/schemas/${type.name}`;\n if (type.enumValues.length > 0) {\n return new JsonObject()\n .set('type', 'string')\n .set('description', this.prose(type.description))\n .set('enum', type.enumValues.slice());\n }\n if (type.unionRefNames.length > 0) {\n return this.union(type);\n }\n const properties = new JsonObject();\n const required: string[] = [];\n for (const field of type.fields) {\n properties.set(field.name, this.field(field, `${pointer}/properties/${field.name}`));\n if (!field.optional) {\n required.push(field.name);\n }\n }\n return new JsonObject()\n .set('type', 'object')\n .set('description', this.prose(type.description))\n .set('properties', properties.isEmpty() ? undefined : properties)\n .set('required', required.length === 0 ? undefined : required)\n .set(\n 'additionalProperties',\n type.indexSignatureValue === undefined\n ? undefined\n : this.type(type.indexSignatureValue, `${pointer}/additionalProperties`),\n );\n }\n\n /**\n * A union, with a `discriminator` ONLY when the model derived one — which it does only when every\n * branch carries the same property typed as string values (a literal, a string-enum member, or a\n * union of them) that no two branches share. An invented discriminator\n * would claim a narrowing TypeScript itself cannot do.\n */\n private union(type: DocumentedType): JsonObject {\n const branches: JsonValue[] = type.unionRefNames.map((name: string) =>\n this.reference(name),\n );\n const schema = new JsonObject()\n .set('description', this.prose(type.description))\n .set('oneOf', branches);\n if (type.discriminator === undefined) {\n return schema;\n }\n const mapping = new JsonObject();\n // EVERY value a branch's property may hold maps to that branch — `mode: 'a' | 'b'` is two\n // entries pointing at one schema, which OpenAPI's mapping allows (#1023).\n for (const branch of type.unionRefNames) {\n for (const value of type.discriminator.branchValues.get(branch) ?? []) {\n mapping.set(value, `#/components/schemas/${branch}`);\n }\n }\n return schema.set(\n 'discriminator',\n new JsonObject()\n .set('propertyName', type.discriminator.propertyName)\n .set('mapping', mapping),\n );\n }\n\n /**\n * One FIELD: its type, plus the prose and the constraints that hang off the field rather than the\n * type. `@format`, `@WpMin` and `@WpMax` land on the SCALAR — on an array, on the ITEM — because\n * `minimum` on an array means nothing and a reader would have to guess which half was meant.\n */\n field(field: DocumentedField, pointer: string): JsonObject {\n const isArray = field.type.kind === 'array';\n const leafPointer = isArray ? `${pointer}/items` : pointer;\n const leaf = this.constrain(\n isArray ? this.type(field.type.items!, leafPointer) : this.type(field.type, pointer),\n field,\n );\n const schema = isArray\n ? new JsonObject().set('type', 'array').set('items', leaf)\n : this.nullable(leaf, field.nullable);\n if (isArray && field.nullable) {\n return this.described(this.nullable(schema, true), field);\n }\n return this.described(schema, field);\n }\n\n /** `description`, and the `@mcp` override as `x-mcp-description` when the author wrote one. */\n private described(schema: JsonObject, field: DocumentedField): JsonObject {\n return schema\n .set('description', this.prose(field.description))\n .set('x-mcp-description', this.prose(field.mcpDescription));\n }\n\n private constrain(leaf: JsonObject, field: DocumentedField): JsonObject {\n return leaf.set('format', field.format).set('minimum', field.min).set('maximum', field.max);\n }\n\n /** `type: [T, \"null\"]` where there is a type to widen; `anyOf` where the shape is a `$ref`. */\n private nullable(schema: JsonObject, isNullable: boolean): JsonObject {\n if (!isNullable) {\n return schema;\n }\n const declared = schema.get('type');\n if (typeof declared === 'string') {\n return schema.set('type', [declared, 'null']);\n }\n return new JsonObject().set('anyOf', [schema, new JsonObject().set('type', 'null')]);\n }\n\n /** One resolved type, with no field-level prose or constraints on it. */\n type(ref: TypeRef, pointer: string): JsonObject {\n switch (ref.kind) {\n case 'primitive':\n return this.primitive(ref);\n case 'ref':\n return this.reference(ref.refName!);\n case 'array':\n return new JsonObject()\n .set('type', 'array')\n .set('items', this.type(ref.items!, `${pointer}/items`));\n case 'openMap':\n return new JsonObject()\n .set('type', 'object')\n .set(\n 'additionalProperties',\n this.type(ref.values!, `${pointer}/additionalProperties`),\n );\n case 'enum':\n return new JsonObject().set('type', 'string').set('enum', ref.enumValues.slice());\n case 'union':\n return this.namedUnion(ref);\n default:\n this.unmappedFields.push(\n new UnmappedField(pointer, ref.unmappedText ?? '<unknown>'),\n );\n return new JsonObject();\n }\n }\n\n /**\n * A union, as a `$ref` at the NAMED alias when the model registered one.\n *\n * The model records a `type X = A | B` alias as its own entry — carrying the DERIVED\n * discriminator — while the FIELD that used it holds a bare union of branch names. Rendering the\n * field's union inline would therefore publish the `oneOf` and silently drop the discriminator,\n * which is the one part of a union a client actually needs to narrow on. So the alias is looked\n * up by its branch list and referenced.\n */\n private namedUnion(ref: TypeRef): JsonObject {\n const branches = ref.unionRefNames.join(',');\n for (const name of Array.from(this.types.keys())) {\n if (this.types.get(name)!.unionRefNames.join(',') === branches) {\n return this.reference(name);\n }\n }\n return new JsonObject().set(\n 'oneOf',\n ref.unionRefNames.map((each: string) => this.reference(each)),\n );\n }\n\n private primitive(ref: TypeRef): JsonObject {\n if (ref.primitive === 'unknown') {\n // No `type` at all: JSON Schema's honest spelling of \"any shape\". It is only ever reached\n // by a `void` return, which is why it is not the unmapped refusal.\n return new JsonObject();\n }\n return new JsonObject().set('type', ref.integer ? 'integer' : ref.primitive!);\n }\n\n private reference(name: string): JsonObject {\n this.reached.add(name);\n return new JsonObject().set('$ref', `#/components/schemas/${name}`);\n }\n\n /** Empty prose is ABSENT prose. An empty `description` key is noise in every rendered page. */\n private prose(text: string | undefined): string | undefined {\n return text === undefined || text.trim() === '' ? undefined : text;\n }\n}\n"]}
1
+ {"version":3,"file":"SchemaRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SchemaRenderer.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAG3D,qGAAqG;AACrG,MAAa,aAAa;IAGT;IAEA;IAJb;IACI,qEAAqE;IAC5D,OAAe;IACxB,qFAAqF;IAC5E,QAAgB;QAFhB,YAAO,GAAP,OAAO,CAAQ;QAEf,aAAQ,GAAR,QAAQ,CAAQ;IAC1B,CAAC;CACP;AAPD,sCAOC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,cAAc;IAOF;IACA;IAPJ,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5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AU,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEO,SAAS,CAAC,GAAW;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,yFAAyF;YACzF,gEAAgE;YAChE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,OAAO,wBAAwB,GAAG,EAAE,CAAC;QACzC,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,+FAA+F;IACvF,KAAK,CAAC,IAAwB;QAClC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;CACJ;AA5QD,wCA4QC","sourcesContent":["import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { SchemaPlacement } from './SchemaPlacement';\n\n/** ONE field the renderer could not give a shape to, and WHERE in the document it would have sat. */\nexport class UnmappedField {\n constructor(\n /** A JSON pointer into the document that would have been written. */\n readonly pointer: string,\n /** The verbatim TypeScript type text, so the cure names the thing to go and type. */\n readonly typeText: string,\n ) {}\n}\n\n/**\n * {@link TypeRef} / {@link DocumentedType} -> JSON Schema 2020-12, which IS OpenAPI 3.1's schema\n * dialect and IS what MCP `tools/list` speaks. That identity is the reason #982 specifies 3.1 rather\n * than 3.0: the two are not \"similar dialects\", they are the same schemas, so the MCP projection\n * (#984) is a selection and an inline pass, not a translation.\n *\n * ## Three things 3.1 lets this renderer state HONESTLY that 3.0 could not\n *\n * - `type: [T, \"null\"]` for a nullable field, instead of 3.0's `nullable: true` keyword, which is not\n * JSON Schema at all.\n * - `description` BESIDE a `$ref`. In 3.0 a sibling of `$ref` is ignored, so a documented field whose\n * type is a named DTO simply lost its prose.\n * - OPTIONAL and NULLABLE as separate facts — absent from `required` versus `\"null\"` in `type`. `{}`\n * and `{x: null}` are different wire documents and a schema that conflates them rejects one.\n *\n * ## It records what it cannot map rather than emitting an untyped field\n *\n * An unmapped type yields an EMPTY schema, which in JSON Schema means \"anything\". That is precisely\n * the green-build-publishes-a-shapeless-field defect the guard exists to stop, so every one is\n * recorded with the pointer it would have occupied and {@link OpenApiGenerator} refuses on the set.\n *\n * ## WHERE a schema is defined is the placement's answer, not this class's (#1058)\n *\n * The {@link SchemaPlacement} decides, per type, whether its schema is defined in THIS document's\n * `components.schemas` (and under which name) or referenced in another package's components\n * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —\n * is written through it, so the split, the bundled and the MCP document are one renderer.\n */\nexport class SchemaRenderer {\n private readonly reached = new Set<string>();\n private readonly external = new Set<string>();\n private readonly unmappedFields: UnmappedField[] = [];\n\n constructor(\n /** The model's named types, by key (`DocumentedType.keyOf`). */\n private readonly types: ReadonlyMap<string, DocumentedType>,\n private readonly placement: SchemaPlacement,\n ) {}\n\n /** Keys of the named types this document DEFINES, reached directly or through another schema. */\n reachedTypes(): ReadonlySet<string> {\n return this.reached;\n }\n\n /** Keys of the named types this document REFERENCES in another package's components document. */\n externalTypes(): ReadonlySet<string> {\n return this.external;\n }\n\n /** Every field with no shape, with its pointer. Empty means the document is fully typed. */\n unmapped(): readonly UnmappedField[] {\n return this.unmappedFields;\n }\n\n /**\n * `components.schemas` for everything reachable from whatever has been rendered so far, expanded\n * to a FIXPOINT.\n *\n * A worklist and not recursion-with-a-guard because rendering a type reaches more types, and the\n * set has to close over that. It terminates for the same reason the extractor's walk does: a\n * named type is registered once, so the worklist strictly shrinks.\n */\n components(): JsonObject {\n const rendered = new Map<string, JsonObject | undefined>();\n let grew = true;\n while (grew) {\n grew = false;\n for (const key of Array.from(this.reached)) {\n const type = this.types.get(key);\n const name = type === undefined ? key : this.placement.localName(key, type);\n if (rendered.has(name)) {\n continue;\n }\n // Rendering it can add MORE names to `reached`, which is what the outer loop is for.\n rendered.set(name, type === undefined ? undefined : this.namedType(key, type));\n grew = true;\n }\n }\n const schemas = new JsonObject();\n // Alphabetical, because `components.schemas` is a lookup table and nothing reads it in order\n // — whereas discovery order would move every time an operation was added above another.\n for (const name of Array.from(rendered.keys()).sort()) {\n schemas.set(name, rendered.get(name));\n }\n return schemas;\n }\n\n /**\n * Mark `key` as DEFINED by this document even when nothing in it refers to the type — the\n * components document of a DTO library publishes every type the library exports (#1058).\n */\n define(key: string): void {\n const type = this.types.get(key);\n if (type !== undefined && this.placement.isLocal(key, type)) {\n this.reached.add(key);\n }\n }\n\n /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */\n private namedType(key: string, type: DocumentedType): JsonObject {\n const pointer = `#/components/schemas/${this.placement.localName(key, type)}`;\n if (type.enumValues.length > 0) {\n return new JsonObject()\n .set('type', 'string')\n .set('description', this.prose(type.description))\n .set('enum', type.enumValues.slice());\n }\n if (type.unionRefNames.length > 0) {\n return this.union(type);\n }\n const properties = new JsonObject();\n const required: string[] = [];\n for (const field of type.fields) {\n properties.set(field.name, this.field(field, `${pointer}/properties/${field.name}`));\n if (!field.optional) {\n required.push(field.name);\n }\n }\n return new JsonObject()\n .set('type', 'object')\n .set('description', this.prose(type.description))\n .set('properties', properties.isEmpty() ? undefined : properties)\n .set('required', required.length === 0 ? undefined : required)\n .set(\n 'additionalProperties',\n type.indexSignatureValue === undefined\n ? undefined\n : this.type(type.indexSignatureValue, `${pointer}/additionalProperties`),\n );\n }\n\n /**\n * A union, with a `discriminator` ONLY when the model derived one — which it does only when every\n * branch carries the same property typed as string values (a literal, a string-enum member, or a\n * union of them) that no two branches share. An invented discriminator\n * would claim a narrowing TypeScript itself cannot do.\n */\n private union(type: DocumentedType): JsonObject {\n const branches: JsonValue[] = type.unionRefNames.map((name: string) =>\n this.reference(name),\n );\n const schema = new JsonObject()\n .set('description', this.prose(type.description))\n .set('oneOf', branches);\n if (type.discriminator === undefined) {\n return schema;\n }\n const mapping = new JsonObject();\n // EVERY value a branch's property may hold maps to that branch — `mode: 'a' | 'b'` is two\n // entries pointing at one schema, which OpenAPI's mapping allows (#1023).\n for (const branch of type.unionRefNames) {\n for (const value of type.discriminator.branchValues.get(branch) ?? []) {\n mapping.set(value, this.pointerTo(branch));\n }\n }\n return schema.set(\n 'discriminator',\n new JsonObject()\n .set('propertyName', type.discriminator.propertyName)\n .set('mapping', mapping),\n );\n }\n\n /**\n * One FIELD: its type, plus the prose and the constraints that hang off the field rather than the\n * type. `@format`, `@WpMin` and `@WpMax` land on the SCALAR — on an array, on the ITEM — because\n * `minimum` on an array means nothing and a reader would have to guess which half was meant.\n */\n field(field: DocumentedField, pointer: string): JsonObject {\n const isArray = field.type.kind === 'array';\n const leafPointer = isArray ? `${pointer}/items` : pointer;\n const leaf = this.constrain(\n isArray ? this.type(field.type.items!, leafPointer) : this.type(field.type, pointer),\n field,\n );\n const schema = isArray\n ? new JsonObject().set('type', 'array').set('items', leaf)\n : this.nullable(leaf, field.nullable);\n if (isArray && field.nullable) {\n return this.described(this.nullable(schema, true), field);\n }\n return this.described(schema, field);\n }\n\n /** `description`, and the `@mcp` override as `x-mcp-description` when the author wrote one. */\n private described(schema: JsonObject, field: DocumentedField): JsonObject {\n return schema\n .set('description', this.prose(field.description))\n .set('x-mcp-description', this.prose(field.mcpDescription));\n }\n\n private constrain(leaf: JsonObject, field: DocumentedField): JsonObject {\n return leaf.set('format', field.format).set('minimum', field.min).set('maximum', field.max);\n }\n\n /** `type: [T, \"null\"]` where there is a type to widen; `anyOf` where the shape is a `$ref`. */\n private nullable(schema: JsonObject, isNullable: boolean): JsonObject {\n if (!isNullable) {\n return schema;\n }\n const declared = schema.get('type');\n if (typeof declared === 'string') {\n return schema.set('type', [declared, 'null']);\n }\n return new JsonObject().set('anyOf', [schema, new JsonObject().set('type', 'null')]);\n }\n\n /** One resolved type, with no field-level prose or constraints on it. */\n type(ref: TypeRef, pointer: string): JsonObject {\n switch (ref.kind) {\n case 'primitive':\n return this.primitive(ref);\n case 'ref':\n return this.reference(ref.refName!);\n case 'array':\n return new JsonObject()\n .set('type', 'array')\n .set('items', this.type(ref.items!, `${pointer}/items`));\n case 'openMap':\n return new JsonObject()\n .set('type', 'object')\n .set(\n 'additionalProperties',\n this.type(ref.values!, `${pointer}/additionalProperties`),\n );\n case 'enum':\n return new JsonObject().set('type', 'string').set('enum', ref.enumValues.slice());\n case 'union':\n return this.namedUnion(ref);\n default:\n this.unmappedFields.push(\n new UnmappedField(pointer, ref.unmappedText ?? '<unknown>'),\n );\n return new JsonObject();\n }\n }\n\n /**\n * A union, as a `$ref` at the NAMED alias when the model registered one.\n *\n * The model records a `type X = A | B` alias as its own entry — carrying the DERIVED\n * discriminator — while the FIELD that used it holds a bare union of branch names. Rendering the\n * field's union inline would therefore publish the `oneOf` and silently drop the discriminator,\n * which is the one part of a union a client actually needs to narrow on. So the alias is looked\n * up by its branch list and referenced.\n */\n private namedUnion(ref: TypeRef): JsonObject {\n const branches = ref.unionRefNames.join(',');\n for (const name of Array.from(this.types.keys())) {\n if (this.types.get(name)!.unionRefNames.join(',') === branches) {\n return this.reference(name);\n }\n }\n return new JsonObject().set(\n 'oneOf',\n ref.unionRefNames.map((each: string) => this.reference(each)),\n );\n }\n\n private primitive(ref: TypeRef): JsonObject {\n if (ref.primitive === 'unknown') {\n // No `type` at all: JSON Schema's honest spelling of \"any shape\". It is only ever reached\n // by a `void` return, which is why it is not the unmapped refusal.\n return new JsonObject();\n }\n return new JsonObject().set('type', ref.integer ? 'integer' : ref.primitive!);\n }\n\n /**\n * A `$ref` to the type registered under `key`, recording whether this document defines it or\n * references it in its declaring package's components document.\n */\n private reference(key: string): JsonObject {\n return new JsonObject().set('$ref', this.pointerTo(key));\n }\n\n private pointerTo(key: string): string {\n const type = this.types.get(key);\n if (type === undefined) {\n // Not in the model at all (a manifest naming an error type that does not exist): keep it\n // local so `components()` writes the hole the guards then name.\n this.reached.add(key);\n return `#/components/schemas/${key}`;\n }\n if (this.placement.isLocal(key, type)) {\n this.reached.add(key);\n } else {\n this.external.add(key);\n }\n return this.placement.pointer(key, type);\n }\n\n /** Empty prose is ABSENT prose. An empty `description` key is noise in every rendered page. */\n private prose(text: string | undefined): string | undefined {\n return text === undefined || text.trim() === '' ? undefined : text;\n }\n}\n"]}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * What generation knows about the OTHER packages a document's types are declared in (#1058) — read
3
+ * from disk by the loader BEFORE generation, so the generator stays a pure function of established
4
+ * facts.
5
+ *
6
+ * A contract (or DTO library) document defines only the schemas its own package declares and
7
+ * `$ref`s every other one into the declaring package's `components.openapi.json`. Whether that
8
+ * document exists, and which schemas it holds, is therefore an INPUT — and its absence is the
9
+ * fail-closed refusal, never a reason to copy the schema in.
10
+ */
11
+ /** A package that publishes a components document, and the schema names it holds. Data-only. */
12
+ export declare class PublishedComponents {
13
+ readonly packageName: string;
14
+ /** Absolute path of the `components.openapi.json` that was read. */
15
+ readonly documentPath: string;
16
+ /** Every key of its `components.schemas`. */
17
+ readonly schemaNames: ReadonlySet<string>;
18
+ constructor(packageName: string,
19
+ /** Absolute path of the `components.openapi.json` that was read. */
20
+ documentPath: string,
21
+ /** Every key of its `components.schemas`. */
22
+ schemaNames: ReadonlySet<string>);
23
+ }
24
+ /** A package that publishes NO components document, and why the lookup says so. Data-only. */
25
+ export declare class MissingComponents {
26
+ readonly packageName: string;
27
+ /** One sentence: where it looked and what it found instead. */
28
+ readonly reason: string;
29
+ constructor(packageName: string,
30
+ /** One sentence: where it looked and what it found instead. */
31
+ reason: string);
32
+ }
33
+ /** Every other package a document's types are declared in, by package name. */
34
+ export declare class UpstreamComponentsIndex {
35
+ private readonly published;
36
+ private readonly missing;
37
+ constructor(published: ReadonlyMap<string, PublishedComponents>, missing: ReadonlyMap<string, MissingComponents>);
38
+ static empty(): UpstreamComponentsIndex;
39
+ publishedBy(packageName: string): PublishedComponents | undefined;
40
+ missingFor(packageName: string): MissingComponents | undefined;
41
+ /** Every published upstream document, in package-name order. */
42
+ allPublished(): readonly PublishedComponents[];
43
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * What generation knows about the OTHER packages a document's types are declared in (#1058) — read
4
+ * from disk by the loader BEFORE generation, so the generator stays a pure function of established
5
+ * facts.
6
+ *
7
+ * A contract (or DTO library) document defines only the schemas its own package declares and
8
+ * `$ref`s every other one into the declaring package's `components.openapi.json`. Whether that
9
+ * document exists, and which schemas it holds, is therefore an INPUT — and its absence is the
10
+ * fail-closed refusal, never a reason to copy the schema in.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.UpstreamComponentsIndex = exports.MissingComponents = exports.PublishedComponents = void 0;
14
+ /** A package that publishes a components document, and the schema names it holds. Data-only. */
15
+ class PublishedComponents {
16
+ packageName;
17
+ documentPath;
18
+ schemaNames;
19
+ constructor(packageName,
20
+ /** Absolute path of the `components.openapi.json` that was read. */
21
+ documentPath,
22
+ /** Every key of its `components.schemas`. */
23
+ schemaNames) {
24
+ this.packageName = packageName;
25
+ this.documentPath = documentPath;
26
+ this.schemaNames = schemaNames;
27
+ }
28
+ }
29
+ exports.PublishedComponents = PublishedComponents;
30
+ /** A package that publishes NO components document, and why the lookup says so. Data-only. */
31
+ class MissingComponents {
32
+ packageName;
33
+ reason;
34
+ constructor(packageName,
35
+ /** One sentence: where it looked and what it found instead. */
36
+ reason) {
37
+ this.packageName = packageName;
38
+ this.reason = reason;
39
+ }
40
+ }
41
+ exports.MissingComponents = MissingComponents;
42
+ /** Every other package a document's types are declared in, by package name. */
43
+ class UpstreamComponentsIndex {
44
+ published;
45
+ missing;
46
+ constructor(published, missing) {
47
+ this.published = published;
48
+ this.missing = missing;
49
+ }
50
+ // webpieces-disable no-function-outside-class -- static factory of this class
51
+ static empty() {
52
+ return new UpstreamComponentsIndex(new Map(), new Map());
53
+ }
54
+ publishedBy(packageName) {
55
+ return this.published.get(packageName);
56
+ }
57
+ missingFor(packageName) {
58
+ return this.missing.get(packageName);
59
+ }
60
+ /** Every published upstream document, in package-name order. */
61
+ allPublished() {
62
+ return Array.from(this.published.keys())
63
+ .sort()
64
+ .map((name) => this.published.get(name));
65
+ }
66
+ }
67
+ exports.UpstreamComponentsIndex = UpstreamComponentsIndex;
68
+ //# sourceMappingURL=UpstreamComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UpstreamComponents.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/UpstreamComponents.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,gGAAgG;AAChG,MAAa,mBAAmB;IAEf;IAEA;IAEA;IALb,YACa,WAAmB;IAC5B,oEAAoE;IAC3D,YAAoB;IAC7B,6CAA6C;IACpC,WAAgC;QAJhC,gBAAW,GAAX,WAAW,CAAQ;QAEnB,iBAAY,GAAZ,YAAY,CAAQ;QAEpB,gBAAW,GAAX,WAAW,CAAqB;IAC1C,CAAC;CACP;AARD,kDAQC;AAED,8FAA8F;AAC9F,MAAa,iBAAiB;IAEb;IAEA;IAHb,YACa,WAAmB;IAC5B,+DAA+D;IACtD,MAAc;QAFd,gBAAW,GAAX,WAAW,CAAQ;QAEnB,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AAND,8CAMC;AAED,+EAA+E;AAC/E,MAAa,uBAAuB;IAEX;IACA;IAFrB,YACqB,SAAmD,EACnD,OAA+C;QAD/C,cAAS,GAAT,SAAS,CAA0C;QACnD,YAAO,GAAP,OAAO,CAAwC;IACjE,CAAC;IAEJ,8EAA8E;IAC9E,MAAM,CAAC,KAAK;QACR,OAAO,IAAI,uBAAuB,CAC9B,IAAI,GAAG,EAA+B,EACtC,IAAI,GAAG,EAA6B,CACvC,CAAC;IACN,CAAC;IAED,WAAW,CAAC,WAAmB;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED,UAAU,CAAC,WAAmB;QAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,gEAAgE;IAChE,YAAY;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;aACnC,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC;IAC1D,CAAC;CACJ;AA5BD,0DA4BC","sourcesContent":["/**\n * What generation knows about the OTHER packages a document's types are declared in (#1058) — read\n * from disk by the loader BEFORE generation, so the generator stays a pure function of established\n * facts.\n *\n * A contract (or DTO library) document defines only the schemas its own package declares and\n * `$ref`s every other one into the declaring package's `components.openapi.json`. Whether that\n * document exists, and which schemas it holds, is therefore an INPUT — and its absence is the\n * fail-closed refusal, never a reason to copy the schema in.\n */\n\n/** A package that publishes a components document, and the schema names it holds. Data-only. */\nexport class PublishedComponents {\n constructor(\n readonly packageName: string,\n /** Absolute path of the `components.openapi.json` that was read. */\n readonly documentPath: string,\n /** Every key of its `components.schemas`. */\n readonly schemaNames: ReadonlySet<string>,\n ) {}\n}\n\n/** A package that publishes NO components document, and why the lookup says so. Data-only. */\nexport class MissingComponents {\n constructor(\n readonly packageName: string,\n /** One sentence: where it looked and what it found instead. */\n readonly reason: string,\n ) {}\n}\n\n/** Every other package a document's types are declared in, by package name. */\nexport class UpstreamComponentsIndex {\n constructor(\n private readonly published: ReadonlyMap<string, PublishedComponents>,\n private readonly missing: ReadonlyMap<string, MissingComponents>,\n ) {}\n\n // webpieces-disable no-function-outside-class -- static factory of this class\n static empty(): UpstreamComponentsIndex {\n return new UpstreamComponentsIndex(\n new Map<string, PublishedComponents>(),\n new Map<string, MissingComponents>(),\n );\n }\n\n publishedBy(packageName: string): PublishedComponents | undefined {\n return this.published.get(packageName);\n }\n\n missingFor(packageName: string): MissingComponents | undefined {\n return this.missing.get(packageName);\n }\n\n /** Every published upstream document, in package-name order. */\n allPublished(): readonly PublishedComponents[] {\n return Array.from(this.published.keys())\n .sort()\n .map((name: string) => this.published.get(name)!);\n }\n}\n"]}
package/src/index.d.ts CHANGED
@@ -14,14 +14,18 @@ export type { JsonValue } from './json/JsonObject';
14
14
  export { JsonWriter } from './json/JsonWriter';
15
15
  export { YamlWriter } from './json/YamlWriter';
16
16
  export { YamlReader } from './json/YamlReader';
17
- export { ApiEntry, ErrorResponseEntry, ErrorsEntry, OpenApiManifest, ResponseHeaderEntry, ServerEntry, } from './manifest/OpenApiManifest';
17
+ export { ApiEntry, ComponentsManifest, ErrorResponseEntry, ErrorsEntry, OpenApiManifest, ResponseHeaderEntry, ServerEntry, } from './manifest/OpenApiManifest';
18
18
  export { JsonReader } from './manifest/JsonReader';
19
19
  export { ManifestLoader } from './manifest/ManifestLoader';
20
- export { ContractModel, GeneratedDocument, GeneratedDocuments, GenerationInputs, ResolvedResponseHeader, } from './generate/GenerationInputs';
20
+ export { ComponentsInputs, ContractModel, GeneratedDocument, GeneratedDocuments, GenerationInputs, ResolvedResponseHeader, } from './generate/GenerationInputs';
21
21
  export { DocumentSelection, INTERNAL_ONLY_LINE, OPERATION_SEMANTICS, } from './generate/DocumentSelection';
22
22
  export { OpenApiGenerator } from './generate/OpenApiGenerator';
23
23
  export { OperationRenderer, ResponseContract } from './generate/OperationRenderer';
24
24
  export { SchemaRenderer, UnmappedField } from './generate/SchemaRenderer';
25
+ export { BundledNames, BundledPlacement, ComponentsReference, DiscoveryPlacement, SplitPlacement, } from './generate/SchemaPlacement';
26
+ export type { SchemaPlacement } from './generate/SchemaPlacement';
27
+ export { MissingComponents, PublishedComponents, UpstreamComponentsIndex, } from './generate/UpstreamComponents';
28
+ export { ComponentsLocator, LocatedComponents } from './load/ComponentsLocator';
25
29
  export { SecurityDeriver } from './generate/SecurityDeriver';
26
30
  export { ExportedConstantFolder } from './load/ExportedConstantFolder';
27
31
  export { ForeignFailure } from './load/ForeignFailure';
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WpOpenApiMain = exports.USAGE = exports.OpenApiCli = exports.CliResult = exports.GeneratedArtifact = exports.ArtifactWriter = exports.InputsLoader = exports.ForeignFailure = exports.ExportedConstantFolder = exports.SecurityDeriver = exports.UnmappedField = exports.SchemaRenderer = exports.ResponseContract = exports.OperationRenderer = exports.OpenApiGenerator = exports.OPERATION_SEMANTICS = exports.INTERNAL_ONLY_LINE = exports.DocumentSelection = exports.ResolvedResponseHeader = exports.GenerationInputs = exports.GeneratedDocuments = exports.GeneratedDocument = exports.ContractModel = exports.ManifestLoader = exports.JsonReader = exports.ServerEntry = exports.ResponseHeaderEntry = exports.OpenApiManifest = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ApiEntry = exports.YamlReader = exports.YamlWriter = exports.JsonWriter = exports.JsonObject = exports.OpenApiGenerationError = void 0;
3
+ exports.WpOpenApiMain = exports.USAGE = exports.OpenApiCli = exports.CliResult = exports.GeneratedArtifact = exports.ArtifactWriter = exports.InputsLoader = exports.ForeignFailure = exports.ExportedConstantFolder = exports.SecurityDeriver = exports.LocatedComponents = exports.ComponentsLocator = exports.UpstreamComponentsIndex = exports.PublishedComponents = exports.MissingComponents = exports.SplitPlacement = exports.DiscoveryPlacement = exports.ComponentsReference = exports.BundledPlacement = exports.BundledNames = exports.UnmappedField = exports.SchemaRenderer = exports.ResponseContract = exports.OperationRenderer = exports.OpenApiGenerator = exports.OPERATION_SEMANTICS = exports.INTERNAL_ONLY_LINE = exports.DocumentSelection = exports.ResolvedResponseHeader = exports.GenerationInputs = exports.GeneratedDocuments = exports.GeneratedDocument = exports.ContractModel = exports.ComponentsInputs = exports.ManifestLoader = exports.JsonReader = exports.ServerEntry = exports.ResponseHeaderEntry = exports.OpenApiManifest = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ComponentsManifest = exports.ApiEntry = exports.YamlReader = exports.YamlWriter = exports.JsonWriter = exports.JsonObject = exports.OpenApiGenerationError = void 0;
4
4
  /**
5
5
  * `@webpieces/openapi-generator` — render an `ApiDocModel` to OpenAPI 3.1.0.
6
6
  *
@@ -23,6 +23,7 @@ var YamlReader_1 = require("./json/YamlReader");
23
23
  Object.defineProperty(exports, "YamlReader", { enumerable: true, get: function () { return YamlReader_1.YamlReader; } });
24
24
  var OpenApiManifest_1 = require("./manifest/OpenApiManifest");
25
25
  Object.defineProperty(exports, "ApiEntry", { enumerable: true, get: function () { return OpenApiManifest_1.ApiEntry; } });
26
+ Object.defineProperty(exports, "ComponentsManifest", { enumerable: true, get: function () { return OpenApiManifest_1.ComponentsManifest; } });
26
27
  Object.defineProperty(exports, "ErrorResponseEntry", { enumerable: true, get: function () { return OpenApiManifest_1.ErrorResponseEntry; } });
27
28
  Object.defineProperty(exports, "ErrorsEntry", { enumerable: true, get: function () { return OpenApiManifest_1.ErrorsEntry; } });
28
29
  Object.defineProperty(exports, "OpenApiManifest", { enumerable: true, get: function () { return OpenApiManifest_1.OpenApiManifest; } });
@@ -33,6 +34,7 @@ Object.defineProperty(exports, "JsonReader", { enumerable: true, get: function (
33
34
  var ManifestLoader_1 = require("./manifest/ManifestLoader");
34
35
  Object.defineProperty(exports, "ManifestLoader", { enumerable: true, get: function () { return ManifestLoader_1.ManifestLoader; } });
35
36
  var GenerationInputs_1 = require("./generate/GenerationInputs");
37
+ Object.defineProperty(exports, "ComponentsInputs", { enumerable: true, get: function () { return GenerationInputs_1.ComponentsInputs; } });
36
38
  Object.defineProperty(exports, "ContractModel", { enumerable: true, get: function () { return GenerationInputs_1.ContractModel; } });
37
39
  Object.defineProperty(exports, "GeneratedDocument", { enumerable: true, get: function () { return GenerationInputs_1.GeneratedDocument; } });
38
40
  Object.defineProperty(exports, "GeneratedDocuments", { enumerable: true, get: function () { return GenerationInputs_1.GeneratedDocuments; } });
@@ -50,6 +52,19 @@ Object.defineProperty(exports, "ResponseContract", { enumerable: true, get: func
50
52
  var SchemaRenderer_1 = require("./generate/SchemaRenderer");
51
53
  Object.defineProperty(exports, "SchemaRenderer", { enumerable: true, get: function () { return SchemaRenderer_1.SchemaRenderer; } });
52
54
  Object.defineProperty(exports, "UnmappedField", { enumerable: true, get: function () { return SchemaRenderer_1.UnmappedField; } });
55
+ var SchemaPlacement_1 = require("./generate/SchemaPlacement");
56
+ Object.defineProperty(exports, "BundledNames", { enumerable: true, get: function () { return SchemaPlacement_1.BundledNames; } });
57
+ Object.defineProperty(exports, "BundledPlacement", { enumerable: true, get: function () { return SchemaPlacement_1.BundledPlacement; } });
58
+ Object.defineProperty(exports, "ComponentsReference", { enumerable: true, get: function () { return SchemaPlacement_1.ComponentsReference; } });
59
+ Object.defineProperty(exports, "DiscoveryPlacement", { enumerable: true, get: function () { return SchemaPlacement_1.DiscoveryPlacement; } });
60
+ Object.defineProperty(exports, "SplitPlacement", { enumerable: true, get: function () { return SchemaPlacement_1.SplitPlacement; } });
61
+ var UpstreamComponents_1 = require("./generate/UpstreamComponents");
62
+ Object.defineProperty(exports, "MissingComponents", { enumerable: true, get: function () { return UpstreamComponents_1.MissingComponents; } });
63
+ Object.defineProperty(exports, "PublishedComponents", { enumerable: true, get: function () { return UpstreamComponents_1.PublishedComponents; } });
64
+ Object.defineProperty(exports, "UpstreamComponentsIndex", { enumerable: true, get: function () { return UpstreamComponents_1.UpstreamComponentsIndex; } });
65
+ var ComponentsLocator_1 = require("./load/ComponentsLocator");
66
+ Object.defineProperty(exports, "ComponentsLocator", { enumerable: true, get: function () { return ComponentsLocator_1.ComponentsLocator; } });
67
+ Object.defineProperty(exports, "LocatedComponents", { enumerable: true, get: function () { return ComponentsLocator_1.LocatedComponents; } });
53
68
  var SecurityDeriver_1 = require("./generate/SecurityDeriver");
54
69
  Object.defineProperty(exports, "SecurityDeriver", { enumerable: true, get: function () { return SecurityDeriver_1.SecurityDeriver; } });
55
70
  var ExportedConstantFolder_1 = require("./load/ExportedConstantFolder");
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/openapi-generator/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AAEnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,8DAOoC;AANhC,2GAAA,QAAQ,OAAA;AACR,qHAAA,kBAAkB,OAAA;AAClB,8GAAA,WAAW,OAAA;AACX,kHAAA,eAAe,OAAA;AACf,sHAAA,mBAAmB,OAAA;AACnB,8GAAA,WAAW,OAAA;AAEf,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,gEAMqC;AALjC,iHAAA,aAAa,OAAA;AACb,qHAAA,iBAAiB,OAAA;AACjB,sHAAA,kBAAkB,OAAA;AAClB,oHAAA,gBAAgB,OAAA;AAChB,0HAAA,sBAAsB,OAAA;AAE1B,kEAIsC;AAHlC,sHAAA,iBAAiB,OAAA;AACjB,uHAAA,kBAAkB,OAAA;AAClB,wHAAA,mBAAmB,OAAA;AAEvB,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,kEAAmF;AAA1E,sHAAA,iBAAiB,OAAA;AAAE,qHAAA,gBAAgB,OAAA;AAC5C,4DAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,+GAAA,aAAa,OAAA;AACtC,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,wEAAuE;AAA9D,gIAAA,sBAAsB,OAAA;AAC/B,wDAAuD;AAA9C,gHAAA,cAAc,OAAA;AACvB,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AACrB,wDAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAE1C,+CAAgE;AAAvD,uGAAA,SAAS,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,mGAAA,KAAK,OAAA;AACrC,qDAAoD;AAA3C,8GAAA,aAAa,OAAA","sourcesContent":["/**\n * `@webpieces/openapi-generator` — render an `ApiDocModel` to OpenAPI 3.1.0.\n *\n * ONE generation pass produces TWO documents: the CANONICAL internal one, which carries every\n * operation including hidden ones plus the `x-mcp-*` extensions, and the CUSTOMER one, from which a\n * hidden endpoint is absent entirely. They are byte-identical when nothing is hidden, which is the\n * property that makes hiding reviewable — see `responsibilities.md`.\n *\n * It ships the `wp-openapi` bin, and depends on `typescript` and `@webpieces/api-doc-model` alone.\n */\nexport { OpenApiGenerationError } from './OpenApiGenerationError';\nexport { JsonObject } from './json/JsonObject';\nexport type { JsonValue } from './json/JsonObject';\nexport { JsonWriter } from './json/JsonWriter';\nexport { YamlWriter } from './json/YamlWriter';\nexport { YamlReader } from './json/YamlReader';\nexport {\n ApiEntry,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './manifest/OpenApiManifest';\nexport { JsonReader } from './manifest/JsonReader';\nexport { ManifestLoader } from './manifest/ManifestLoader';\nexport {\n ContractModel,\n GeneratedDocument,\n GeneratedDocuments,\n GenerationInputs,\n ResolvedResponseHeader,\n} from './generate/GenerationInputs';\nexport {\n DocumentSelection,\n INTERNAL_ONLY_LINE,\n OPERATION_SEMANTICS,\n} from './generate/DocumentSelection';\nexport { OpenApiGenerator } from './generate/OpenApiGenerator';\nexport { OperationRenderer, ResponseContract } from './generate/OperationRenderer';\nexport { SchemaRenderer, UnmappedField } from './generate/SchemaRenderer';\nexport { SecurityDeriver } from './generate/SecurityDeriver';\nexport { ExportedConstantFolder } from './load/ExportedConstantFolder';\nexport { ForeignFailure } from './load/ForeignFailure';\nexport { InputsLoader } from './load/InputsLoader';\nexport { ArtifactWriter, GeneratedArtifact } from './emit/ArtifactWriter';\nexport type { OutputFormat } from './emit/ArtifactWriter';\nexport { CliResult, OpenApiCli, USAGE } from './cli/OpenApiCli';\nexport { WpOpenApiMain } from './cli/WpOpenApiMain';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/openapi-generator/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AAEnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,8DAQoC;AAPhC,2GAAA,QAAQ,OAAA;AACR,qHAAA,kBAAkB,OAAA;AAClB,qHAAA,kBAAkB,OAAA;AAClB,8GAAA,WAAW,OAAA;AACX,kHAAA,eAAe,OAAA;AACf,sHAAA,mBAAmB,OAAA;AACnB,8GAAA,WAAW,OAAA;AAEf,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,gEAOqC;AANjC,oHAAA,gBAAgB,OAAA;AAChB,iHAAA,aAAa,OAAA;AACb,qHAAA,iBAAiB,OAAA;AACjB,sHAAA,kBAAkB,OAAA;AAClB,oHAAA,gBAAgB,OAAA;AAChB,0HAAA,sBAAsB,OAAA;AAE1B,kEAIsC;AAHlC,sHAAA,iBAAiB,OAAA;AACjB,uHAAA,kBAAkB,OAAA;AAClB,wHAAA,mBAAmB,OAAA;AAEvB,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,kEAAmF;AAA1E,sHAAA,iBAAiB,OAAA;AAAE,qHAAA,gBAAgB,OAAA;AAC5C,4DAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,+GAAA,aAAa,OAAA;AACtC,8DAMoC;AALhC,+GAAA,YAAY,OAAA;AACZ,mHAAA,gBAAgB,OAAA;AAChB,sHAAA,mBAAmB,OAAA;AACnB,qHAAA,kBAAkB,OAAA;AAClB,iHAAA,cAAc,OAAA;AAGlB,oEAIuC;AAHnC,uHAAA,iBAAiB,OAAA;AACjB,yHAAA,mBAAmB,OAAA;AACnB,6HAAA,uBAAuB,OAAA;AAE3B,8DAAgF;AAAvE,sHAAA,iBAAiB,OAAA;AAAE,sHAAA,iBAAiB,OAAA;AAC7C,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,wEAAuE;AAA9D,gIAAA,sBAAsB,OAAA;AAC/B,wDAAuD;AAA9C,gHAAA,cAAc,OAAA;AACvB,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AACrB,wDAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAE1C,+CAAgE;AAAvD,uGAAA,SAAS,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,mGAAA,KAAK,OAAA;AACrC,qDAAoD;AAA3C,8GAAA,aAAa,OAAA","sourcesContent":["/**\n * `@webpieces/openapi-generator` — render an `ApiDocModel` to OpenAPI 3.1.0.\n *\n * ONE generation pass produces TWO documents: the CANONICAL internal one, which carries every\n * operation including hidden ones plus the `x-mcp-*` extensions, and the CUSTOMER one, from which a\n * hidden endpoint is absent entirely. They are byte-identical when nothing is hidden, which is the\n * property that makes hiding reviewable — see `responsibilities.md`.\n *\n * It ships the `wp-openapi` bin, and depends on `typescript` and `@webpieces/api-doc-model` alone.\n */\nexport { OpenApiGenerationError } from './OpenApiGenerationError';\nexport { JsonObject } from './json/JsonObject';\nexport type { JsonValue } from './json/JsonObject';\nexport { JsonWriter } from './json/JsonWriter';\nexport { YamlWriter } from './json/YamlWriter';\nexport { YamlReader } from './json/YamlReader';\nexport {\n ApiEntry,\n ComponentsManifest,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './manifest/OpenApiManifest';\nexport { JsonReader } from './manifest/JsonReader';\nexport { ManifestLoader } from './manifest/ManifestLoader';\nexport {\n ComponentsInputs,\n ContractModel,\n GeneratedDocument,\n GeneratedDocuments,\n GenerationInputs,\n ResolvedResponseHeader,\n} from './generate/GenerationInputs';\nexport {\n DocumentSelection,\n INTERNAL_ONLY_LINE,\n OPERATION_SEMANTICS,\n} from './generate/DocumentSelection';\nexport { OpenApiGenerator } from './generate/OpenApiGenerator';\nexport { OperationRenderer, ResponseContract } from './generate/OperationRenderer';\nexport { SchemaRenderer, UnmappedField } from './generate/SchemaRenderer';\nexport {\n BundledNames,\n BundledPlacement,\n ComponentsReference,\n DiscoveryPlacement,\n SplitPlacement,\n} from './generate/SchemaPlacement';\nexport type { SchemaPlacement } from './generate/SchemaPlacement';\nexport {\n MissingComponents,\n PublishedComponents,\n UpstreamComponentsIndex,\n} from './generate/UpstreamComponents';\nexport { ComponentsLocator, LocatedComponents } from './load/ComponentsLocator';\nexport { SecurityDeriver } from './generate/SecurityDeriver';\nexport { ExportedConstantFolder } from './load/ExportedConstantFolder';\nexport { ForeignFailure } from './load/ForeignFailure';\nexport { InputsLoader } from './load/InputsLoader';\nexport { ArtifactWriter, GeneratedArtifact } from './emit/ArtifactWriter';\nexport type { OutputFormat } from './emit/ArtifactWriter';\nexport { CliResult, OpenApiCli, USAGE } from './cli/OpenApiCli';\nexport { WpOpenApiMain } from './cli/WpOpenApiMain';\n"]}
@@ -0,0 +1,44 @@
1
+ import { MissingComponents, PublishedComponents } from '../generate/UpstreamComponents';
2
+ /** The outcome of locating ONE package's components document: exactly one side is set. Data-only. */
3
+ export declare class LocatedComponents {
4
+ readonly published: PublishedComponents | undefined;
5
+ readonly missing: MissingComponents | undefined;
6
+ constructor(published: PublishedComponents | undefined, missing: MissingComponents | undefined);
7
+ }
8
+ /**
9
+ * Find the `components.openapi.json` a package publishes (#1058) — by the SAME package lookup
10
+ * `McpToolCatalog.fromPackages` (`@webpieces/mcp-server`) uses to find a library's MCP catalogs:
11
+ *
12
+ * 1. resolve `<pkg>/package.json` the way node does, walking `node_modules` up from the manifest's
13
+ * directory (symlinks followed) — falling back to the directory the COMPILER read the type from
14
+ * (the nearest `package.json` above its declaration), for a workspace that maps packages with
15
+ * tsconfig `paths` and links none;
16
+ * 2. that directory holds `components.openapi.json` → a BUILT or PUBLISHED package → read it there;
17
+ * 3. it holds a `project.json` → a workspace SOURCE directory → read it from the `outputPath` of the
18
+ * target its `openapi-components-generate` dependsOn ({@link GeneratedApiDocsLayout}), resolved
19
+ * against the nx workspace root found by walking up to `nx.json`.
20
+ *
21
+ * Never an assumed `dist/`. Anything else is a {@link MissingComponents} carrying where it looked and
22
+ * what it found — which the generator turns into the fail-closed refusal, so a missing document is
23
+ * never a reason to copy a schema in.
24
+ */
25
+ export declare class ComponentsLocator {
26
+ /**
27
+ * @param packageName the package whose document is wanted.
28
+ * @param resolveFrom where node resolution starts — the manifest's directory.
29
+ * @param declaredIn the directory of the `package.json` the compiler read the type from, if any.
30
+ */
31
+ locate(packageName: string, resolveFrom: string, declaredIn: string | undefined): LocatedComponents;
32
+ /** `<dir>/node_modules/<pkg>/package.json` in `resolveFrom` and every parent — node's own walk. */
33
+ private resolve;
34
+ /** A workspace SOURCE directory: the outputPath of the target its components target dependsOn. */
35
+ private fromSource;
36
+ private workspaceRootAbove;
37
+ /**
38
+ * Read one document. Its `x-webpieces-id` must be the package-qualified URI it is referenced by:
39
+ * a document published under another package's name is a copy, and referencing it would point
40
+ * every `$ref` at the wrong owner.
41
+ */
42
+ private read;
43
+ private missing;
44
+ }