@webpieces/openapi-generator 0.4.937 → 0.4.939

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.
@@ -1,5 +1,6 @@
1
1
  import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';
2
2
  import { JsonObject } from '../json/JsonObject';
3
+ import { InlinedWrappers } from './InlinedWrappers';
3
4
  import { SchemaPlacement } from './SchemaPlacement';
4
5
  /** ONE field the renderer could not give a shape to, and WHERE in the document it would have sat. */
5
6
  export declare class UnmappedField {
@@ -40,19 +41,34 @@ export declare class UnmappedField {
40
41
  * `components.schemas` (and under which name) or referenced in another package's components
41
42
  * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —
42
43
  * is written through it, so the split, the bundled and the MCP document are one renderer.
44
+ *
45
+ * ## A single-use request/response wrapper is written INLINE at its operation (#1303)
46
+ *
47
+ * {@link body} is how an operation asks for its request or success-response schema. A wrapper
48
+ * {@link InlinedWrappers} names is rendered right there — `title` set to its published name, its
49
+ * description, and `properties` even when empty — instead of as a `$ref`; it is never added to
50
+ * `components.schemas`. It is recorded in {@link inlinedTypes} so the description guard still judges
51
+ * it: inlining is never a way around a missing JSDoc.
43
52
  */
44
53
  export declare class SchemaRenderer {
45
54
  /** The model's named types, by key (`DocumentedType.keyOf`). */
46
55
  private readonly types;
47
56
  private readonly placement;
57
+ /** The wrappers an operation defines inline rather than by `$ref` (#1303). */
58
+ private readonly wrappers;
48
59
  private readonly reached;
60
+ private readonly inlined;
49
61
  private readonly external;
50
62
  private readonly unmappedFields;
51
63
  constructor(
52
64
  /** The model's named types, by key (`DocumentedType.keyOf`). */
53
- types: ReadonlyMap<string, DocumentedType>, placement: SchemaPlacement);
65
+ types: ReadonlyMap<string, DocumentedType>, placement: SchemaPlacement,
66
+ /** The wrappers an operation defines inline rather than by `$ref` (#1303). */
67
+ wrappers: InlinedWrappers);
54
68
  /** Keys of the named types this document DEFINES, reached directly or through another schema. */
55
69
  reachedTypes(): ReadonlySet<string>;
70
+ /** Keys of the wrappers this document defined INLINE at their one operation (#1303). */
71
+ inlinedTypes(): ReadonlySet<string>;
56
72
  /** Keys of the named types this document REFERENCES in another package's components document. */
57
73
  externalTypes(): ReadonlySet<string>;
58
74
  /** Every field with no shape, with its pointer. Empty means the document is fully typed. */
@@ -71,8 +87,22 @@ export declare class SchemaRenderer {
71
87
  * components document of a DTO library publishes every type the library exports (#1058).
72
88
  */
73
89
  define(key: string): void;
90
+ /**
91
+ * An operation's request body or success-response schema: the wrapper itself, INLINE, when
92
+ * {@link InlinedWrappers} names it — else exactly what {@link type} writes.
93
+ *
94
+ * The inline form is an object schema carrying `title` (the PUBLISHED name, which client
95
+ * generators name the model from) and `properties` even when the class is empty, which a client
96
+ * generator needs in order to emit an empty class rather than an untyped map.
97
+ */
98
+ body(ref: TypeRef, pointer: string): JsonObject;
74
99
  /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */
75
100
  private namedType;
101
+ /**
102
+ * An object DTO. `title` is set only on an INLINED wrapper, and then `properties` is written even
103
+ * when empty (#1303); a component keeps its name as its key and omits an empty `properties`.
104
+ */
105
+ private objectType;
76
106
  /**
77
107
  * A union, with a `discriminator` ONLY when the model derived one — which it does only when every
78
108
  * branch carries the same property typed as string values (a literal, a string-enum member, or a
@@ -43,23 +43,40 @@ exports.UnmappedField = UnmappedField;
43
43
  * `components.schemas` (and under which name) or referenced in another package's components
44
44
  * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —
45
45
  * is written through it, so the split, the bundled and the MCP document are one renderer.
46
+ *
47
+ * ## A single-use request/response wrapper is written INLINE at its operation (#1303)
48
+ *
49
+ * {@link body} is how an operation asks for its request or success-response schema. A wrapper
50
+ * {@link InlinedWrappers} names is rendered right there — `title` set to its published name, its
51
+ * description, and `properties` even when empty — instead of as a `$ref`; it is never added to
52
+ * `components.schemas`. It is recorded in {@link inlinedTypes} so the description guard still judges
53
+ * it: inlining is never a way around a missing JSDoc.
46
54
  */
47
55
  class SchemaRenderer {
48
56
  types;
49
57
  placement;
58
+ wrappers;
50
59
  reached = new Set();
60
+ inlined = new Set();
51
61
  external = new Set();
52
62
  unmappedFields = [];
53
63
  constructor(
54
64
  /** The model's named types, by key (`DocumentedType.keyOf`). */
55
- types, placement) {
65
+ types, placement,
66
+ /** The wrappers an operation defines inline rather than by `$ref` (#1303). */
67
+ wrappers) {
56
68
  this.types = types;
57
69
  this.placement = placement;
70
+ this.wrappers = wrappers;
58
71
  }
59
72
  /** Keys of the named types this document DEFINES, reached directly or through another schema. */
60
73
  reachedTypes() {
61
74
  return this.reached;
62
75
  }
76
+ /** Keys of the wrappers this document defined INLINE at their one operation (#1303). */
77
+ inlinedTypes() {
78
+ return this.inlined;
79
+ }
63
80
  /** Keys of the named types this document REFERENCES in another package's components document. */
64
81
  externalTypes() {
65
82
  return this.external;
@@ -88,7 +105,9 @@ class SchemaRenderer {
88
105
  continue;
89
106
  }
90
107
  // Rendering it can add MORE names to `reached`, which is what the outer loop is for.
91
- rendered.set(name, type === undefined ? undefined : this.namedType(key, type));
108
+ rendered.set(name, type === undefined
109
+ ? undefined
110
+ : this.namedType(type, `#/components/schemas/${this.placement.localName(key, type)}`));
92
111
  grew = true;
93
112
  }
94
113
  }
@@ -110,9 +129,25 @@ class SchemaRenderer {
110
129
  this.reached.add(key);
111
130
  }
112
131
  }
132
+ /**
133
+ * An operation's request body or success-response schema: the wrapper itself, INLINE, when
134
+ * {@link InlinedWrappers} names it — else exactly what {@link type} writes.
135
+ *
136
+ * The inline form is an object schema carrying `title` (the PUBLISHED name, which client
137
+ * generators name the model from) and `properties` even when the class is empty, which a client
138
+ * generator needs in order to emit an empty class rather than an untyped map.
139
+ */
140
+ body(ref, pointer) {
141
+ const key = ref.kind === 'ref' ? ref.refName : undefined;
142
+ const type = key === undefined ? undefined : this.types.get(key);
143
+ if (key === undefined || type === undefined || !this.wrappers.has(key)) {
144
+ return this.type(ref, pointer);
145
+ }
146
+ this.inlined.add(key);
147
+ return this.objectType(type, pointer, type.schemaName);
148
+ }
113
149
  /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */
114
- namedType(key, type) {
115
- const pointer = `#/components/schemas/${this.placement.localName(key, type)}`;
150
+ namedType(type, pointer) {
116
151
  if (type.enumValues.length > 0) {
117
152
  return new JsonObject_1.JsonObject()
118
153
  .set('type', 'string')
@@ -122,6 +157,13 @@ class SchemaRenderer {
122
157
  if (type.unionRefNames.length > 0) {
123
158
  return this.union(type);
124
159
  }
160
+ return this.objectType(type, pointer, undefined);
161
+ }
162
+ /**
163
+ * An object DTO. `title` is set only on an INLINED wrapper, and then `properties` is written even
164
+ * when empty (#1303); a component keeps its name as its key and omits an empty `properties`.
165
+ */
166
+ objectType(type, pointer, title) {
125
167
  const properties = new JsonObject_1.JsonObject();
126
168
  const required = [];
127
169
  for (const field of type.fields) {
@@ -132,8 +174,9 @@ class SchemaRenderer {
132
174
  }
133
175
  return new JsonObject_1.JsonObject()
134
176
  .set('type', 'object')
177
+ .set('title', title)
135
178
  .set('description', this.prose(type.description))
136
- .set('properties', properties.isEmpty() ? undefined : properties)
179
+ .set('properties', properties.isEmpty() && title === undefined ? undefined : properties)
137
180
  .set('required', required.length === 0 ? undefined : required)
138
181
  .set('additionalProperties', type.indexSignatureValue === undefined
139
182
  ? undefined
@@ -1 +1 @@
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;I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,CAAC,IAAI,CAAC;IACvE,CAAC;CACJ;AAlRD,wCAkRC","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 const values = schema.get('enum');\n if (Array.isArray(values) && !values.includes(null)) {\n // `enum` is checked independently of `type`, so a nullable inline enum\n // (`'a' | 'b' | null`) must list `null` too or the document rejects it (#1197).\n schema.set('enum', [...values, null]);\n }\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"]}
1
+ {"version":3,"file":"SchemaRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SchemaRenderer.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAI3D,qGAAqG;AACrG,MAAa,aAAa;IAG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AAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;CACJ;AA5TD,wCA4TC","sourcesContent":["import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { InlinedWrappers } from './InlinedWrappers';\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 *\n * ## A single-use request/response wrapper is written INLINE at its operation (#1303)\n *\n * {@link body} is how an operation asks for its request or success-response schema. A wrapper\n * {@link InlinedWrappers} names is rendered right there — `title` set to its published name, its\n * description, and `properties` even when empty — instead of as a `$ref`; it is never added to\n * `components.schemas`. It is recorded in {@link inlinedTypes} so the description guard still judges\n * it: inlining is never a way around a missing JSDoc.\n */\nexport class SchemaRenderer {\n private readonly reached = new Set<string>();\n private readonly inlined = 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 /** The wrappers an operation defines inline rather than by `$ref` (#1303). */\n private readonly wrappers: InlinedWrappers,\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 wrappers this document defined INLINE at their one operation (#1303). */\n inlinedTypes(): ReadonlySet<string> {\n return this.inlined;\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(\n name,\n type === undefined\n ? undefined\n : this.namedType(\n type,\n `#/components/schemas/${this.placement.localName(key, type)}`,\n ),\n );\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 /**\n * An operation's request body or success-response schema: the wrapper itself, INLINE, when\n * {@link InlinedWrappers} names it — else exactly what {@link type} writes.\n *\n * The inline form is an object schema carrying `title` (the PUBLISHED name, which client\n * generators name the model from) and `properties` even when the class is empty, which a client\n * generator needs in order to emit an empty class rather than an untyped map.\n */\n body(ref: TypeRef, pointer: string): JsonObject {\n const key = ref.kind === 'ref' ? ref.refName! : undefined;\n const type = key === undefined ? undefined : this.types.get(key);\n if (key === undefined || type === undefined || !this.wrappers.has(key)) {\n return this.type(ref, pointer);\n }\n this.inlined.add(key);\n return this.objectType(type, pointer, type.schemaName);\n }\n\n /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */\n private namedType(type: DocumentedType, pointer: string): JsonObject {\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 return this.objectType(type, pointer, undefined);\n }\n\n /**\n * An object DTO. `title` is set only on an INLINED wrapper, and then `properties` is written even\n * when empty (#1303); a component keeps its name as its key and omits an empty `properties`.\n */\n private objectType(type: DocumentedType, pointer: string, title: string | undefined): JsonObject {\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('title', title)\n .set('description', this.prose(type.description))\n .set('properties', properties.isEmpty() && title === undefined ? 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 const values = schema.get('enum');\n if (Array.isArray(values) && !values.includes(null)) {\n // `enum` is checked independently of `type`, so a nullable inline enum\n // (`'a' | 'b' | null`) must list `null` too or the document rejects it (#1197).\n schema.set('enum', [...values, null]);\n }\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"]}
package/src/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export { DocumentSelection, INTERNAL_ONLY_LINE, OPERATION_SEMANTICS, } from './g
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 { InlinedWrappers } from './generate/InlinedWrappers';
25
26
  export { BundledNames, BundledPlacement, ComponentsReference, DiscoveryPlacement, SplitPlacement, } from './generate/SchemaPlacement';
26
27
  export type { SchemaPlacement } from './generate/SchemaPlacement';
27
28
  export { MissingComponents, PublishedComponents, UpstreamComponentsIndex, } from './generate/UpstreamComponents';
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.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.OperationIdStyle = exports.OpenApiManifest = exports.MANIFEST_SUMMARY_MAX_LENGTH = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ComponentsManifest = 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.SecurityDeriver = exports.LocatedComponents = exports.ComponentsLocator = exports.UpstreamComponentsIndex = exports.PublishedComponents = exports.MissingComponents = exports.SplitPlacement = exports.DiscoveryPlacement = exports.ComponentsReference = exports.BundledPlacement = exports.BundledNames = exports.InlinedWrappers = 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.OperationIdStyle = exports.OpenApiManifest = exports.MANIFEST_SUMMARY_MAX_LENGTH = 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
  *
@@ -54,6 +54,8 @@ Object.defineProperty(exports, "ResponseContract", { enumerable: true, get: func
54
54
  var SchemaRenderer_1 = require("./generate/SchemaRenderer");
55
55
  Object.defineProperty(exports, "SchemaRenderer", { enumerable: true, get: function () { return SchemaRenderer_1.SchemaRenderer; } });
56
56
  Object.defineProperty(exports, "UnmappedField", { enumerable: true, get: function () { return SchemaRenderer_1.UnmappedField; } });
57
+ var InlinedWrappers_1 = require("./generate/InlinedWrappers");
58
+ Object.defineProperty(exports, "InlinedWrappers", { enumerable: true, get: function () { return InlinedWrappers_1.InlinedWrappers; } });
57
59
  var SchemaPlacement_1 = require("./generate/SchemaPlacement");
58
60
  Object.defineProperty(exports, "BundledNames", { enumerable: true, get: function () { return SchemaPlacement_1.BundledNames; } });
59
61
  Object.defineProperty(exports, "BundledPlacement", { enumerable: true, get: function () { return SchemaPlacement_1.BundledPlacement; } });
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;A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AAA;AAC7C,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,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 MANIFEST_SUMMARY_MAX_LENGTH,\n OpenApiManifest,\n OperationIdStyle,\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 { 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,8DAUoC;AAThC,2GAAA,QAAQ,OAAA;AACR,qHAAA,kBAAkB,OAAA;AAClB,qHAAA,kBAAkB,OAAA;AAClB,8GAAA,WAAW,OAAA;AACX,8HAAA,2BAA2B,OAAA;AAC3B,kHAAA,eAAe,OAAA;AACf,mHAAA,gBAAgB,OAAA;AAChB,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,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,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,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 MANIFEST_SUMMARY_MAX_LENGTH,\n OpenApiManifest,\n OperationIdStyle,\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 { InlinedWrappers } from './generate/InlinedWrappers';\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 { 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"]}