@sdk-it/spec 0.49.1 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export * from './lib/overview-docs/types.js';
23
23
  export * from './lib/reserved-keywords.js';
24
24
  export * from './lib/sidebar.js';
25
25
  export * from './lib/tag.js';
26
+ export * from './lib/tuple.js';
26
27
  export * from './lib/types.js';
27
28
  export * from './lib/walk-schemas.js';
28
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wCAAwC,CAAC;AACvD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wCAAwC,CAAC;AACvD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ export * from "./lib/overview-docs/types.js";
23
23
  export * from "./lib/reserved-keywords.js";
24
24
  export * from "./lib/sidebar.js";
25
25
  export * from "./lib/tag.js";
26
+ export * from "./lib/tuple.js";
26
27
  export * from "./lib/types.js";
27
28
  export * from "./lib/walk-schemas.js";
28
29
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export * from './lib/finalize-operations.js';\nexport * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/ir.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/documents/document-parser.js';\nexport * from './lib/documents/document-source.js';\nexport * from './lib/documents/documents.js';\nexport * from './lib/documents/errors.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/spec-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/operation-input.js';\nexport * from './lib/options.js';\nexport * from './lib/processing-plugins/index.js';\nexport * from './lib/processing.js';\nexport * from './lib/overview-docs/overview-errors.js';\nexport * from './lib/overview-docs/types.js';\nexport * from './lib/reserved-keywords.js';\nexport * from './lib/sidebar.js';\nexport * from './lib/tag.js';\nexport * from './lib/types.js';\nexport * from './lib/walk-schemas.js';\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './lib/finalize-operations.js';\nexport * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/ir.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/documents/document-parser.js';\nexport * from './lib/documents/document-source.js';\nexport * from './lib/documents/documents.js';\nexport * from './lib/documents/errors.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/spec-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/operation-input.js';\nexport * from './lib/options.js';\nexport * from './lib/processing-plugins/index.js';\nexport * from './lib/processing.js';\nexport * from './lib/overview-docs/overview-errors.js';\nexport * from './lib/overview-docs/types.js';\nexport * from './lib/reserved-keywords.js';\nexport * from './lib/sidebar.js';\nexport * from './lib/tag.js';\nexport * from './lib/tuple.js';\nexport * from './lib/types.js';\nexport * from './lib/walk-schemas.js';\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"operation-input.d.ts","sources":["../../src/lib/operation-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAYvE,OAAO,KAAK,EAAE,EAAE,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3D,8EAA8E;AAC9E,QAAA,MAAM,gBAAgB,YACpB,MAAM,EACN,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,CACC,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAuBhE,+FAA+F;AAC/F,MAAM,WAAW,cAAc;IAC7B,kHAAkH;IAClH,SAAS,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,0FAA0F;IAC1F,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,EAAE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,CAC7B,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,oBAAoB,GAC9B,cAAc,EAAE,CAelB;AAmCD,6GAA6G;AAC7G,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAEpE;AAED,kJAAkJ;AAClJ,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM,CAE7E;AAED,oJAAoJ;AACpJ,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM,CAErE"}
@@ -164,6 +164,7 @@ function holdsBinary(ir, schema, seen) {
164
164
  const children = [
165
165
  ...Object.values(schema.properties ?? {}),
166
166
  ...schema.items ? [schema.items] : [],
167
+ ...schema.prefixItems ?? [],
167
168
  ...typeof schema.additionalProperties === "object" ? [schema.additionalProperties] : [],
168
169
  ...schema.allOf ?? [],
169
170
  ...schema.oneOf ?? [],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/operation-input.ts"],
4
- "sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\nimport { pascalcase } from 'stringcase';\n\nimport { followRef, isRef, resolveRef } from '@sdk-it/core/ref.js';\nimport { isEmpty, sortArray } from '@sdk-it/core/utils.js';\n\nimport {\n isTextContentType,\n isXmlContentType,\n parseJsonContentType,\n} from './is.js';\nimport { withParameters } from './processing-plugins/normalize-request-bodies.js';\nimport type { IR, TunedOperationObject } from './types.js';\n\n/** How a client writes a request body, in the order a client prefers them. */\nconst requestEncodings = [\n 'json',\n 'urlencoded',\n 'formdata',\n 'text',\n 'binary',\n 'empty',\n] as const;\n\nexport type RequestEncoding = (typeof requestEncodings)[number];\n\n/** The encoding a client sends a body of media type `contentType` with. */\nfunction requestEncoding(contentType: string): RequestEncoding {\n const mainType = contentType.split(';')[0].trim().toLowerCase();\n if (mainType === 'application/empty') {\n return 'empty';\n }\n if (parseJsonContentType(mainType)) {\n return 'json';\n }\n if (mainType === 'application/x-www-form-urlencoded') {\n return 'urlencoded';\n }\n if (mainType === 'multipart/form-data') {\n return 'formdata';\n }\n if (isTextContentType(mainType) || isXmlContentType(mainType)) {\n return 'text';\n }\n return 'binary';\n}\n\n/** How a client sends an operation: its body encoding, its input and where each input goes. */\nexport interface OperationInput {\n /** Whether a client exposes this input under the operation's own key and name; every other input is a variant. */\n preferred: boolean;\n /** The request media type the client sends. */\n contentType: string;\n encoding: RequestEncoding;\n /** The input object a client accepts: its body fields or `$body`, plus its parameters. */\n schema: SchemaObject;\n header: string[];\n query: string[];\n body: string[];\n path: string[];\n}\n\nfunction bodyObject(\n operation: TunedOperationObject,\n body: SchemaObject,\n parameters: SchemaObject,\n): SchemaObject {\n return {\n type: 'object',\n required: operation.requestBody.required ? ['$body'] : [],\n properties: { $body: body },\n ...parameters,\n };\n}\n\n/**\n * A text body is a string and a binary body a Blob, whatever structure the\n * media type's schema describes (an XML document is sent as written); a string\n * schema keeps its own constraints.\n */\nfunction rawBody(\n schema: SchemaObject,\n encoding: 'text' | 'binary',\n): SchemaObject {\n if (schema.type === 'string') {\n return schema;\n }\n return encoding === 'text'\n ? { type: 'string' }\n : { type: 'string', format: 'binary' };\n}\n\n/**\n * The object for `contentType` before its parameters are folded in: an empty\n * body becomes an object of parameters only, and a text or binary body, or any\n * other body that is not an object, becomes `$body`.\n */\nfunction requestObject(\n ir: IR,\n operation: TunedOperationObject,\n contentType: string,\n encoding: RequestEncoding,\n): SchemaObject {\n const schema = resolveRef<SchemaObject>(\n ir,\n operation.requestBody.content[contentType].schema,\n );\n const parameters = {\n 'x-properties': schema['x-properties'],\n 'x-required': schema['x-required'],\n };\n switch (encoding) {\n case 'empty':\n // An operation without a body or parameters still takes an object, so\n // the client accepts any input instead of none.\n return {\n type: 'object',\n additionalProperties: isEmpty(schema['x-properties']),\n ...parameters,\n };\n case 'text':\n case 'binary':\n return bodyObject(operation, rawBody(schema, encoding), parameters);\n default:\n return schema.type === 'object'\n ? schema\n : bodyObject(operation, schema, parameters);\n }\n}\n\nfunction bodyNames(\n ir: IR,\n schema: SchemaObject | ReferenceObject,\n names: string[],\n): void {\n if (isRef(schema)) {\n bodyNames(ir, followRef(ir, schema.$ref), names);\n } else if (schema.type === 'object') {\n names.push(...Object.keys(schema.properties ?? {}));\n } else if (\n (schema.type === 'array' || schema.type?.includes('array')) &&\n schema.items\n ) {\n bodyNames(ir, schema.items, names);\n } else if (schema.allOf) {\n for (const part of schema.allOf) bodyNames(ir, part, names);\n } else if (schema.oneOf) {\n for (const part of schema.oneOf) bodyNames(ir, part, names);\n } else if (schema.anyOf) {\n for (const part of schema.anyOf) bodyNames(ir, part, names);\n } else {\n console.warn('Unknown schema in body', schema);\n }\n}\n\nfunction toInput(\n ir: IR,\n operation: TunedOperationObject,\n contentType: string,\n encoding: RequestEncoding,\n preferred: boolean,\n): OperationInput {\n const object = requestObject(ir, operation, contentType, encoding);\n const input: OperationInput = {\n preferred,\n contentType,\n encoding,\n schema: withParameters(object),\n header: [],\n query: [],\n body: [],\n path: [],\n };\n const locations: Record<string, string> = {};\n for (const [name, parameter] of Object.entries<SchemaObject>(\n object['x-properties'],\n )) {\n locations[name] = parameter['x-in'];\n }\n const names: string[] = [];\n bodyNames(ir, object, names);\n for (const name of sortArray(names)) {\n locations[name] = 'body';\n }\n for (const [name, location] of Object.entries(locations)) {\n switch (location) {\n case 'header':\n case 'headers':\n input.header.push(name);\n break;\n case 'query':\n input.query.push(name);\n break;\n case 'body':\n input.body.push(name);\n break;\n case 'path':\n input.path.push(name);\n break;\n default:\n throw new Error(\n `Unknown source ${location} in ${name} in ${operation.operationId}`,\n );\n }\n }\n return input;\n}\n\n/**\n * Every way a client can send `operation`: one input per encoding it accepts,\n * the preferred input first, then the variants in {@link requestEncodings}\n * order. Within one encoding the media type the operation declares first wins.\n */\nexport function operationInputs(\n ir: IR,\n operation: TunedOperationObject,\n): OperationInput[] {\n const contentTypes = new Map<RequestEncoding, string>();\n for (const contentType of Object.keys(operation.requestBody.content)) {\n contentTypes.getOrInsert(requestEncoding(contentType), contentType);\n }\n const inputs: OperationInput[] = [];\n for (const encoding of requestEncodings) {\n const contentType = contentTypes.get(encoding);\n if (contentType) {\n inputs.push(\n toInput(ir, operation, contentType, encoding, inputs.length === 0),\n );\n }\n }\n return inputs;\n}\n\nfunction holdsBinary(\n ir: IR,\n schema: SchemaObject | ReferenceObject,\n seen: Set<string>,\n): boolean {\n if (isRef(schema)) {\n if (seen.has(schema.$ref)) {\n return false;\n }\n seen.add(schema.$ref);\n return holdsBinary(ir, followRef(ir, schema.$ref), seen);\n }\n if (\n schema.format === 'binary' ||\n schema.format === 'byte' ||\n schema.contentEncoding === 'binary'\n ) {\n return true;\n }\n const children = [\n ...Object.values(schema.properties ?? {}),\n ...(schema.items ? [schema.items] : []),\n ...(typeof schema.additionalProperties === 'object'\n ? [schema.additionalProperties]\n : []),\n ...(schema.allOf ?? []),\n ...(schema.oneOf ?? []),\n ...(schema.anyOf ?? []),\n ];\n return children.some((child) => holdsBinary(ir, child, seen));\n}\n\n/** Whether `input` carries binary data (a file field or a Blob body), which a JSON tool call cannot send. */\nexport function carriesBinary(ir: IR, input: OperationInput): boolean {\n return holdsBinary(ir, input.schema, new Set());\n}\n\n/** The key a client exposes `input` under: `endpoint` itself for the preferred input, `formdata POST /upload` for a variant of `POST /upload`. */\nexport function inputEndpoint(endpoint: string, input: OperationInput): string {\n return input.preferred ? endpoint : `${input.encoding} ${endpoint}`;\n}\n\n/** The name of `input` of an operation called `name`: `name` itself for the preferred input, `uploadFileFormdata` for a variant of `uploadFile`. */\nexport function inputName(name: string, input: OperationInput): string {\n return input.preferred ? name : `${name}${pascalcase(input.encoding)}`;\n}\n"],
5
- "mappings": "AACA,SAAS,kBAAkB;AAE3B,SAAS,WAAW,OAAO,kBAAkB;AAC7C,SAAS,SAAS,iBAAiB;AAEnC;AAAA,EACE;AAAA,EACA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,EACzD;AACA,MACE,OAAO,WAAW,YAClB,OAAO,WAAW,UAClB,OAAO,oBAAoB,UAC3B;AACA,WAAO;AAAA,EACT;AACA,QAAM,WAAW;AAAA,IACf,GAAG,OAAO,OAAO,OAAO,cAAc,CAAC,CAAC;AAAA,IACxC,GAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC;AAAA,IACrC,GAAI,OAAO,OAAO,yBAAyB,WACvC,CAAC,OAAO,oBAAoB,IAC5B,CAAC;AAAA,IACL,GAAI,OAAO,SAAS,CAAC;AAAA,IACrB,GAAI,OAAO,SAAS,CAAC;AAAA,IACrB,GAAI,OAAO,SAAS,CAAC;AAAA,EACvB;AACA,SAAO,SAAS,KAAK,CAAC,UAAU,YAAY,IAAI,OAAO,IAAI,CAAC;AAC9D;AAGO,SAAS,cAAc,IAAQ,OAAgC;AACpE,SAAO,YAAY,IAAI,MAAM,QAAQ,oBAAI,IAAI,CAAC;AAChD;AAGO,SAAS,cAAc,UAAkB,OAA+B;AAC7E,SAAO,MAAM,YAAY,WAAW,GAAG,MAAM,QAAQ,IAAI,QAAQ;AACnE;AAGO,SAAS,UAAU,MAAc,OAA+B;AACrE,SAAO,MAAM,YAAY,OAAO,GAAG,IAAI,GAAG,WAAW,MAAM,QAAQ,CAAC;AACtE;",
4
+ "sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\nimport { pascalcase } from 'stringcase';\n\nimport { followRef, isRef, resolveRef } from '@sdk-it/core/ref.js';\nimport { isEmpty, sortArray } from '@sdk-it/core/utils.js';\n\nimport {\n isTextContentType,\n isXmlContentType,\n parseJsonContentType,\n} from './is.js';\nimport { withParameters } from './processing-plugins/normalize-request-bodies.js';\nimport type { IR, TunedOperationObject } from './types.js';\n\n/** How a client writes a request body, in the order a client prefers them. */\nconst requestEncodings = [\n 'json',\n 'urlencoded',\n 'formdata',\n 'text',\n 'binary',\n 'empty',\n] as const;\n\nexport type RequestEncoding = (typeof requestEncodings)[number];\n\n/** The encoding a client sends a body of media type `contentType` with. */\nfunction requestEncoding(contentType: string): RequestEncoding {\n const mainType = contentType.split(';')[0].trim().toLowerCase();\n if (mainType === 'application/empty') {\n return 'empty';\n }\n if (parseJsonContentType(mainType)) {\n return 'json';\n }\n if (mainType === 'application/x-www-form-urlencoded') {\n return 'urlencoded';\n }\n if (mainType === 'multipart/form-data') {\n return 'formdata';\n }\n if (isTextContentType(mainType) || isXmlContentType(mainType)) {\n return 'text';\n }\n return 'binary';\n}\n\n/** How a client sends an operation: its body encoding, its input and where each input goes. */\nexport interface OperationInput {\n /** Whether a client exposes this input under the operation's own key and name; every other input is a variant. */\n preferred: boolean;\n /** The request media type the client sends. */\n contentType: string;\n encoding: RequestEncoding;\n /** The input object a client accepts: its body fields or `$body`, plus its parameters. */\n schema: SchemaObject;\n header: string[];\n query: string[];\n body: string[];\n path: string[];\n}\n\nfunction bodyObject(\n operation: TunedOperationObject,\n body: SchemaObject,\n parameters: SchemaObject,\n): SchemaObject {\n return {\n type: 'object',\n required: operation.requestBody.required ? ['$body'] : [],\n properties: { $body: body },\n ...parameters,\n };\n}\n\n/**\n * A text body is a string and a binary body a Blob, whatever structure the\n * media type's schema describes (an XML document is sent as written); a string\n * schema keeps its own constraints.\n */\nfunction rawBody(\n schema: SchemaObject,\n encoding: 'text' | 'binary',\n): SchemaObject {\n if (schema.type === 'string') {\n return schema;\n }\n return encoding === 'text'\n ? { type: 'string' }\n : { type: 'string', format: 'binary' };\n}\n\n/**\n * The object for `contentType` before its parameters are folded in: an empty\n * body becomes an object of parameters only, and a text or binary body, or any\n * other body that is not an object, becomes `$body`.\n */\nfunction requestObject(\n ir: IR,\n operation: TunedOperationObject,\n contentType: string,\n encoding: RequestEncoding,\n): SchemaObject {\n const schema = resolveRef<SchemaObject>(\n ir,\n operation.requestBody.content[contentType].schema,\n );\n const parameters = {\n 'x-properties': schema['x-properties'],\n 'x-required': schema['x-required'],\n };\n switch (encoding) {\n case 'empty':\n // An operation without a body or parameters still takes an object, so\n // the client accepts any input instead of none.\n return {\n type: 'object',\n additionalProperties: isEmpty(schema['x-properties']),\n ...parameters,\n };\n case 'text':\n case 'binary':\n return bodyObject(operation, rawBody(schema, encoding), parameters);\n default:\n return schema.type === 'object'\n ? schema\n : bodyObject(operation, schema, parameters);\n }\n}\n\nfunction bodyNames(\n ir: IR,\n schema: SchemaObject | ReferenceObject,\n names: string[],\n): void {\n if (isRef(schema)) {\n bodyNames(ir, followRef(ir, schema.$ref), names);\n } else if (schema.type === 'object') {\n names.push(...Object.keys(schema.properties ?? {}));\n } else if (\n (schema.type === 'array' || schema.type?.includes('array')) &&\n schema.items\n ) {\n bodyNames(ir, schema.items, names);\n } else if (schema.allOf) {\n for (const part of schema.allOf) bodyNames(ir, part, names);\n } else if (schema.oneOf) {\n for (const part of schema.oneOf) bodyNames(ir, part, names);\n } else if (schema.anyOf) {\n for (const part of schema.anyOf) bodyNames(ir, part, names);\n } else {\n console.warn('Unknown schema in body', schema);\n }\n}\n\nfunction toInput(\n ir: IR,\n operation: TunedOperationObject,\n contentType: string,\n encoding: RequestEncoding,\n preferred: boolean,\n): OperationInput {\n const object = requestObject(ir, operation, contentType, encoding);\n const input: OperationInput = {\n preferred,\n contentType,\n encoding,\n schema: withParameters(object),\n header: [],\n query: [],\n body: [],\n path: [],\n };\n const locations: Record<string, string> = {};\n for (const [name, parameter] of Object.entries<SchemaObject>(\n object['x-properties'],\n )) {\n locations[name] = parameter['x-in'];\n }\n const names: string[] = [];\n bodyNames(ir, object, names);\n for (const name of sortArray(names)) {\n locations[name] = 'body';\n }\n for (const [name, location] of Object.entries(locations)) {\n switch (location) {\n case 'header':\n case 'headers':\n input.header.push(name);\n break;\n case 'query':\n input.query.push(name);\n break;\n case 'body':\n input.body.push(name);\n break;\n case 'path':\n input.path.push(name);\n break;\n default:\n throw new Error(\n `Unknown source ${location} in ${name} in ${operation.operationId}`,\n );\n }\n }\n return input;\n}\n\n/**\n * Every way a client can send `operation`: one input per encoding it accepts,\n * the preferred input first, then the variants in {@link requestEncodings}\n * order. Within one encoding the media type the operation declares first wins.\n */\nexport function operationInputs(\n ir: IR,\n operation: TunedOperationObject,\n): OperationInput[] {\n const contentTypes = new Map<RequestEncoding, string>();\n for (const contentType of Object.keys(operation.requestBody.content)) {\n contentTypes.getOrInsert(requestEncoding(contentType), contentType);\n }\n const inputs: OperationInput[] = [];\n for (const encoding of requestEncodings) {\n const contentType = contentTypes.get(encoding);\n if (contentType) {\n inputs.push(\n toInput(ir, operation, contentType, encoding, inputs.length === 0),\n );\n }\n }\n return inputs;\n}\n\nfunction holdsBinary(\n ir: IR,\n schema: SchemaObject | ReferenceObject,\n seen: Set<string>,\n): boolean {\n if (isRef(schema)) {\n if (seen.has(schema.$ref)) {\n return false;\n }\n seen.add(schema.$ref);\n return holdsBinary(ir, followRef(ir, schema.$ref), seen);\n }\n if (\n schema.format === 'binary' ||\n schema.format === 'byte' ||\n schema.contentEncoding === 'binary'\n ) {\n return true;\n }\n const children = [\n ...Object.values(schema.properties ?? {}),\n ...(schema.items ? [schema.items] : []),\n ...(schema.prefixItems ?? []),\n ...(typeof schema.additionalProperties === 'object'\n ? [schema.additionalProperties]\n : []),\n ...(schema.allOf ?? []),\n ...(schema.oneOf ?? []),\n ...(schema.anyOf ?? []),\n ];\n return children.some((child) => holdsBinary(ir, child, seen));\n}\n\n/** Whether `input` carries binary data (a file field or a Blob body), which a JSON tool call cannot send. */\nexport function carriesBinary(ir: IR, input: OperationInput): boolean {\n return holdsBinary(ir, input.schema, new Set());\n}\n\n/** The key a client exposes `input` under: `endpoint` itself for the preferred input, `formdata POST /upload` for a variant of `POST /upload`. */\nexport function inputEndpoint(endpoint: string, input: OperationInput): string {\n return input.preferred ? endpoint : `${input.encoding} ${endpoint}`;\n}\n\n/** The name of `input` of an operation called `name`: `name` itself for the preferred input, `uploadFileFormdata` for a variant of `uploadFile`. */\nexport function inputName(name: string, input: OperationInput): string {\n return input.preferred ? name : `${name}${pascalcase(input.encoding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OAAO,IAAI,GAAG;AACzB,aAAO;AAAA,IACT;AACA,SAAK,IAAI,OAAO,IAAI;AACpB,WAAO,YAAY,IAAI,UAAU,IAAI,OAAO,IAAI,GAAG,IAAI;AAAA,EACzD;AACA,MACE,OAAO,WAAW,YAClB,OAAO,WAAW,UAClB,OAAO,oBAAoB,UAC3B;AACA,WAAO;AAAA,EACT;AACA,QAAM,WAAW;AAAA,IACf,GAAG,OAAO,OAAO,OAAO,cAAc,CAAC,CAAC;AAAA,IACxC,GAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC;AAAA,IACrC,GAAI,OAAO,eAAe,CAAC;AAAA,IAC3B,GAAI,OAAO,OAAO,yBAAyB,WACvC,CAAC,OAAO,oBAAoB,IAC5B,CAAC;AAAA,IACL,GAAI,OAAO,SAAS,CAAC;AAAA,IACrB,GAAI,OAAO,SAAS,CAAC;AAAA,IACrB,GAAI,OAAO,SAAS,CAAC;AAAA,EACvB;AACA,SAAO,SAAS,KAAK,CAAC,UAAU,YAAY,IAAI,OAAO,IAAI,CAAC;AAC9D;AAGO,SAAS,cAAc,IAAQ,OAAgC;AACpE,SAAO,YAAY,IAAI,MAAM,QAAQ,oBAAI,IAAI,CAAC;AAChD;AAGO,SAAS,cAAc,UAAkB,OAA+B;AAC7E,SAAO,MAAM,YAAY,WAAW,GAAG,MAAM,QAAQ,IAAI,QAAQ;AACnE;AAGO,SAAS,UAAU,MAAc,OAA+B;AACrE,SAAO,MAAM,YAAY,OAAO,GAAG,IAAI,GAAG,WAAW,MAAM,QAAQ,CAAC;AACtE;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-schemas.d.ts","sources":["../../../src/lib/processing-plugins/normalize-schemas.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAqNjD,wBAAgB,gBAAgB,IAAI,QAAQ,CAO3C"}
1
+ {"version":3,"file":"normalize-schemas.d.ts","sources":["../../../src/lib/processing-plugins/normalize-schemas.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AA4NjD,wBAAgB,gBAAgB,IAAI,QAAQ,CAO3C"}
@@ -37,7 +37,12 @@ function normalizeSchemaObjects(spec, schemas, visited = /* @__PURE__ */ new Set
37
37
  visited
38
38
  );
39
39
  }
40
- if (!isEmpty(schema.items)) {
40
+ if (!isEmpty(schema.prefixItems)) {
41
+ schema.type = "array";
42
+ normalizeSchemaObjects(spec, schema.prefixItems, visited);
43
+ }
44
+ const declaredItems = schema.items;
45
+ if (declaredItems !== false && !isEmpty(schema.items)) {
41
46
  delete schema.oneOf;
42
47
  delete schema.anyOf;
43
48
  schema.type = "array";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/processing-plugins/normalize-schemas.ts"],
4
- "sourcesContent": ["import { mergeWith, uniq } from 'lodash-es';\nimport assert from 'node:assert';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, notRef, resolveRef, snakecase } from '@sdk-it/core';\n\nimport { findVarients } from '../find-polymorphic-varients.js';\nimport { formatName } from '../format-name.js';\nimport { isPrimitiveSchema } from '../is-primitive-schema.js';\nimport { coerceTypes } from '../is.js';\nimport type { IRPlugin } from '../processing.js';\nimport type { IR } from '../types.js';\n\nfunction normalizeSchemaObjects(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n visited = new Set<string>(),\n) {\n for (const schema of schemas) {\n if (isRef(schema)) continue;\n\n // JSON Schema lists required names on the parent object. An OAS 3.0 style\n // `required: true` on a property moves there; any other non-array\n // `required` (a boolean on the schema itself) says nothing and goes.\n if (schema.required !== undefined && !Array.isArray(schema.required)) {\n delete schema.required;\n }\n for (const [key, property] of Object.entries(schema.properties ?? {})) {\n // The document breaks its own type here, so read the value as it is.\n const flag: unknown = notRef(property) ? property.required : undefined;\n if (flag === true) {\n schema.required = uniq([...(schema.required ?? []), key]);\n }\n }\n\n if (!isEmpty(schema.properties)) {\n schema.type ??= 'object';\n delete schema.oneOf;\n delete schema.anyOf;\n normalizeSchemaObjects(spec, Object.values(schema.properties), visited);\n for (const [key, value] of Object.entries(schema.properties)) {\n if (\n notRef(value) &&\n isPrimitiveSchema(value) &&\n schema.default?.[key] !== undefined\n ) {\n value.default ??= schema.default[key];\n delete schema.default?.[key];\n }\n }\n delete schema.default;\n }\n\n if (!isEmpty(schema['x-properties'])) {\n normalizeSchemaObjects(\n spec,\n Object.values(schema['x-properties']),\n visited,\n );\n }\n\n if (!isEmpty(schema.items)) {\n delete schema.oneOf;\n delete schema.anyOf;\n schema.type = 'array';\n normalizeSchemaObjects(spec, [schema.items], visited);\n const items = resolveRef<SchemaObject>(spec, schema.items);\n if (Array.isArray(items.default)) {\n schema.default ??= structuredClone(items.default);\n }\n delete items.default;\n }\n\n if (!isEmpty(schema.anyOf) && !isEmpty(schema.oneOf)) {\n delete schema.anyOf;\n }\n\n if (isEmpty(schema.enum)) {\n delete schema.enum;\n }\n\n if (!isEmpty(schema.enum)) {\n if (schema.enum.length === 1) {\n schema.const = schema.enum[0];\n delete schema.enum;\n } else {\n const valuesSet = new Set<string>();\n const valuesList = [];\n for (const value of schema.enum) {\n const formattedValue = formatName(snakecase(formatName(value)));\n if (!valuesSet.has(formattedValue)) {\n valuesSet.add(formattedValue);\n valuesList.push(value);\n }\n }\n schema.enum = valuesList;\n }\n delete schema.allOf;\n }\n\n if (!isEmpty(schema.allOf)) {\n const schemas = schema.allOf;\n const resolved = schemas.map((item) =>\n resolveRef<SchemaObject>(spec, item),\n );\n const hasObjects = resolved.some((item) => item.type === 'object');\n const hasOtherTypes = resolved.some(\n (item) => item.type && item.type !== 'object',\n );\n if (hasObjects && hasOtherTypes) {\n assert(false, `allOf must be an object`);\n }\n mergeWith(\n schema,\n ...resolved.map((resolvedSchema, index) => {\n const sourceSchema = schemas[index];\n if (isRef(sourceSchema)) {\n if (visited.has(sourceSchema.$ref)) {\n throw new Error(\n `Circular allOf reference detected: ${[\n ...visited,\n sourceSchema.$ref,\n ].join(' -> ')}`,\n );\n }\n normalizeSchemaObjects(\n spec,\n [resolvedSchema],\n new Set(visited).add(sourceSchema.$ref),\n );\n } else {\n normalizeSchemaObjects(spec, [resolvedSchema], visited);\n }\n return resolvedSchema;\n }),\n unionRequired,\n );\n delete schema.allOf;\n } else {\n delete schema.allOf;\n }\n\n if (\n schema.type === 'object' &&\n isEmpty(schema.properties) &&\n typeof schema.additionalProperties === 'object' &&\n !isEmpty(schema.additionalProperties) &&\n notRef(schema.additionalProperties) &&\n !isEmpty(schema.additionalProperties.properties)\n ) {\n normalizeSchemaObjects(\n spec,\n Object.values(schema.additionalProperties.properties),\n visited,\n );\n }\n\n for (const kind of ['oneOf', 'anyOf'] as const) {\n if (!isEmpty(schema[kind])) {\n delete schema.type;\n normalizeSchemaObjects(spec, schema[kind], visited);\n if (isEmpty(schema[kind])) {\n continue;\n }\n\n let enumSchemaIndex = -1;\n const enumValues: string[] = [];\n for (let index = 0; index < schema[kind].length; index++) {\n const item = schema[kind][index];\n if (notRef(item) && item.type === 'string') {\n if (item.enum && item.enum.length > 1) {\n enumValues.push(...item.enum);\n if (enumSchemaIndex === -1) {\n enumSchemaIndex = index;\n }\n }\n }\n }\n if (enumSchemaIndex !== -1) {\n const enumSchema = schema[kind][enumSchemaIndex];\n if (notRef(enumSchema)) {\n enumSchema.enum = uniq(enumValues);\n }\n schema[kind] = schema[kind].filter(\n (item, index) => index === enumSchemaIndex || isRef(item),\n );\n }\n const otherTypes = schema[kind].filter(\n (item) => resolveRef<SchemaObject>(spec, item).type !== 'null',\n );\n const [only] = otherTypes;\n const droppedNull = otherTypes.length !== schema[kind].length;\n // A $ref cannot carry null, so a nullable $ref keeps its union.\n if (otherTypes.length === 1 && !(droppedNull && isRef(only))) {\n Object.assign(schema, only);\n delete schema[kind];\n if (droppedNull && notRef(only)) {\n const types = coerceTypes(only, false);\n if (types.length) {\n const typesWithNull: SchemaObjectType[] = [...types, 'null'];\n schema.type = uniq(typesWithNull);\n }\n }\n continue;\n }\n\n schema['x-varients'] = findVarients(spec, schema[kind]);\n } else {\n delete schema[kind];\n }\n }\n }\n}\n\n// allOf is a conjunction, so a value must carry every part's required\n// properties; lodash's default merge would overwrite the arrays by index.\nfunction unionRequired(target: unknown, source: unknown, key: string) {\n if (key === 'required' && Array.isArray(target) && Array.isArray(source)) {\n return uniq([...target, ...source]);\n }\n return undefined;\n}\n\nexport function normalizeSchemas(): IRPlugin {\n return {\n name: 'normalize-schemas',\n process({ spec }) {\n normalizeSchemaObjects(spec, Object.values(spec.components.schemas));\n },\n };\n}\n"],
5
- "mappings": "AAAA,SAAS,WAAW,YAAY;AAChC,OAAO,YAAY;AAOnB,SAAS,SAAS,OAAO,QAAQ,YAAY,iBAAiB;AAE9D,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAI5B,SAAS,uBACP,MACA,SACA,UAAU,oBAAI,IAAY,GAC1B;AACA,aAAW,UAAU,SAAS;AAC5B,QAAI,MAAM,MAAM,EAAG;AAKnB,QAAI,OAAO,aAAa,UAAa,CAAC,MAAM,QAAQ,OAAO,QAAQ,GAAG;AACpE,aAAO,OAAO;AAAA,IAChB;AACA,eAAW,CAAC,KAAK,QAAQ,KAAK,OAAO,QAAQ,OAAO,cAAc,CAAC,CAAC,GAAG;AAErE,YAAM,OAAgB,OAAO,QAAQ,IAAI,SAAS,WAAW;AAC7D,UAAI,SAAS,MAAM;AACjB,eAAO,WAAW,KAAK,CAAC,GAAI,OAAO,YAAY,CAAC,GAAI,GAAG,CAAC;AAAA,MAC1D;AAAA,IACF;AAEA,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AAC/B,aAAO,SAAS;AAChB,aAAO,OAAO;AACd,aAAO,OAAO;AACd,6BAAuB,MAAM,O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vD,YAAI,WAAW,WAAW,KAAK,EAAE,eAAe,MAAM,IAAI,IAAI;AAC5D,iBAAO,OAAO,QAAQ,IAAI;AAC1B,iBAAO,OAAO,IAAI;AAClB,cAAI,eAAe,OAAO,IAAI,GAAG;AAC/B,kBAAM,QAAQ,YAAY,MAAM,KAAK;AACrC,gBAAI,MAAM,QAAQ;AAChB,oBAAM,gBAAoC,CAAC,GAAG,OAAO,MAAM;AAC3D,qBAAO,OAAO,KAAK,aAAa;AAAA,YAClC;AAAA,UACF;AACA;AAAA,QACF;AAEA,eAAO,YAAY,IAAI,aAAa,MAAM,OAAO,IAAI,CAAC;AAAA,MACxD,OAAO;AACL,eAAO,OAAO,IAAI;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;AAIA,SAAS,cAAc,QAAiB,QAAiB,KAAa;AACpE,MAAI,QAAQ,cAAc,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,MAAM,GAAG;AACxE,WAAO,KAAK,CAAC,GAAG,QAAQ,GAAG,MAAM,CAAC;AAAA,EACpC;AACA,SAAO;AACT;AAEO,SAAS,mBAA6B;AAC3C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,KAAK,GAAG;AAChB,6BAAuB,MAAM,OAAO,OAAO,KAAK,WAAW,OAAO,CAAC;AAAA,IACrE;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { mergeWith, uniq } from 'lodash-es';\nimport assert from 'node:assert';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, notRef, resolveRef, snakecase } from '@sdk-it/core';\n\nimport { findVarients } from '../find-polymorphic-varients.js';\nimport { formatName } from '../format-name.js';\nimport { isPrimitiveSchema } from '../is-primitive-schema.js';\nimport { coerceTypes } from '../is.js';\nimport type { IRPlugin } from '../processing.js';\nimport type { IR } from '../types.js';\n\nfunction normalizeSchemaObjects(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n visited = new Set<string>(),\n) {\n for (const schema of schemas) {\n if (isRef(schema)) continue;\n\n // JSON Schema lists required names on the parent object. An OAS 3.0 style\n // `required: true` on a property moves there; any other non-array\n // `required` (a boolean on the schema itself) says nothing and goes.\n if (schema.required !== undefined && !Array.isArray(schema.required)) {\n delete schema.required;\n }\n for (const [key, property] of Object.entries(schema.properties ?? {})) {\n // The document breaks its own type here, so read the value as it is.\n const flag: unknown = notRef(property) ? property.required : undefined;\n if (flag === true) {\n schema.required = uniq([...(schema.required ?? []), key]);\n }\n }\n\n if (!isEmpty(schema.properties)) {\n schema.type ??= 'object';\n delete schema.oneOf;\n delete schema.anyOf;\n normalizeSchemaObjects(spec, Object.values(schema.properties), visited);\n for (const [key, value] of Object.entries(schema.properties)) {\n if (\n notRef(value) &&\n isPrimitiveSchema(value) &&\n schema.default?.[key] !== undefined\n ) {\n value.default ??= schema.default[key];\n delete schema.default?.[key];\n }\n }\n delete schema.default;\n }\n\n if (!isEmpty(schema['x-properties'])) {\n normalizeSchemaObjects(\n spec,\n Object.values(schema['x-properties']),\n visited,\n );\n }\n\n if (!isEmpty(schema.prefixItems)) {\n schema.type = 'array';\n normalizeSchemaObjects(spec, schema.prefixItems, visited);\n }\n\n // items: false closes a tuple; it is no schema to normalize.\n const declaredItems: unknown = schema.items;\n if (declaredItems !== false && !isEmpty(schema.items)) {\n delete schema.oneOf;\n delete schema.anyOf;\n schema.type = 'array';\n normalizeSchemaObjects(spec, [schema.items], visited);\n const items = resolveRef<SchemaObject>(spec, schema.items);\n if (Array.isArray(items.default)) {\n schema.default ??= structuredClone(items.default);\n }\n delete items.default;\n }\n\n if (!isEmpty(schema.anyOf) && !isEmpty(schema.oneOf)) {\n delete schema.anyOf;\n }\n\n if (isEmpty(schema.enum)) {\n delete schema.enum;\n }\n\n if (!isEmpty(schema.enum)) {\n if (schema.enum.length === 1) {\n schema.const = schema.enum[0];\n delete schema.enum;\n } else {\n const valuesSet = new Set<string>();\n const valuesList = [];\n for (const value of schema.enum) {\n const formattedValue = formatName(snakecase(formatName(value)));\n if (!valuesSet.has(formattedValue)) {\n valuesSet.add(formattedValue);\n valuesList.push(value);\n }\n }\n schema.enum = valuesList;\n }\n delete schema.allOf;\n }\n\n if (!isEmpty(schema.allOf)) {\n const schemas = schema.allOf;\n const resolved = schemas.map((item) =>\n resolveRef<SchemaObject>(spec, item),\n );\n const hasObjects = resolved.some((item) => item.type === 'object');\n const hasOtherTypes = resolved.some(\n (item) => item.type && item.type !== 'object',\n );\n if (hasObjects && hasOtherTypes) {\n assert(false, `allOf must be an object`);\n }\n mergeWith(\n schema,\n ...resolved.map((resolvedSchema, index) => {\n const sourceSchema = schemas[index];\n if (isRef(sourceSchema)) {\n if (visited.has(sourceSchema.$ref)) {\n throw new Error(\n `Circular allOf reference detected: ${[\n ...visited,\n sourceSchema.$ref,\n ].join(' -> ')}`,\n );\n }\n normalizeSchemaObjects(\n spec,\n [resolvedSchema],\n new Set(visited).add(sourceSchema.$ref),\n );\n } else {\n normalizeSchemaObjects(spec, [resolvedSchema], visited);\n }\n return resolvedSchema;\n }),\n unionRequired,\n );\n delete schema.allOf;\n } else {\n delete schema.allOf;\n }\n\n if (\n schema.type === 'object' &&\n isEmpty(schema.properties) &&\n typeof schema.additionalProperties === 'object' &&\n !isEmpty(schema.additionalProperties) &&\n notRef(schema.additionalProperties) &&\n !isEmpty(schema.additionalProperties.properties)\n ) {\n normalizeSchemaObjects(\n spec,\n Object.values(schema.additionalProperties.properties),\n visited,\n );\n }\n\n for (const kind of ['oneOf', 'anyOf'] as const) {\n if (!isEmpty(schema[kind])) {\n delete schema.type;\n normalizeSchemaObjects(spec, schema[kind], visited);\n if (isEmpty(schema[kind])) {\n continue;\n }\n\n let enumSchemaIndex = -1;\n const enumValues: string[] = [];\n for (let index = 0; index < schema[kind].length; index++) {\n const item = schema[kind][index];\n if (notRef(item) && item.type === 'string') {\n if (item.enum && item.enum.length > 1) {\n enumValues.push(...item.enum);\n if (enumSchemaIndex === -1) {\n enumSchemaIndex = index;\n }\n }\n }\n }\n if (enumSchemaIndex !== -1) {\n const enumSchema = schema[kind][enumSchemaIndex];\n if (notRef(enumSchema)) {\n enumSchema.enum = uniq(enumValues);\n }\n schema[kind] = schema[kind].filter(\n (item, index) => index === enumSchemaIndex || isRef(item),\n );\n }\n const otherTypes = schema[kind].filter(\n (item) => resolveRef<SchemaObject>(spec, item).type !== 'null',\n );\n const [only] = otherTypes;\n const droppedNull = otherTypes.length !== schema[kind].length;\n // A $ref cannot carry null, so a nullable $ref keeps its union.\n if (otherTypes.length === 1 && !(droppedNull && isRef(only))) {\n Object.assign(schema, only);\n delete schema[kind];\n if (droppedNull && notRef(only)) {\n const types = coerceTypes(only, false);\n if (types.length) {\n const typesWithNull: SchemaObjectType[] = [...types, 'null'];\n schema.type = uniq(typesWithNull);\n }\n }\n continue;\n }\n\n schema['x-varients'] = findVarients(spec, schema[kind]);\n } else {\n delete schema[kind];\n }\n }\n }\n}\n\n// allOf is a conjunction, so a value must carry every part's required\n// properties; lodash's default merge would overwrite the arrays by index.\nfunction unionRequired(target: unknown, source: unknown, key: string) {\n if (key === 'required' && Array.isArray(target) && Array.isArray(source)) {\n return uniq([...target, ...source]);\n }\n return undefined;\n}\n\nexport function normalizeSchemas(): IRPlugin {\n return {\n name: 'normalize-schemas',\n process({ spec }) {\n normalizeSchemaObjects(spec, Object.values(spec.components.schemas));\n },\n };\n}\n"],
5
+ "mappings": "AAAA,SAAS,WAAW,YAAY;AAChC,OAAO,YAAY;AAOnB,SAAS,SAAS,OAAO,QAAQ,YAAY,iBAAiB;AAE9D,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAI5B,SAAS,uBACP,MACA,SACA,UAAU,oBAAI,IAAY,GAC1B;AACA,aAAW,UAAU,SAAS;AAC5B,QAAI,MAAM,MAAM,EAAG;AAKnB,QAAI,OAAO,aAAa,UAAa,CAAC,MAAM,QAAQ,O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AACT;AAEO,SAAS,mBAA6B;AAC3C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,KAAK,GAAG;AAChB,6BAAuB,MAAM,OAAO,OAAO,KAAK,WAAW,OAAO,CAAC;AAAA,IACrE;AAAA,EACF;AACF;",
6
6
  "names": ["schemas"]
7
7
  }
@@ -0,0 +1,20 @@
1
+ import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';
2
+ type Schema = SchemaObject | ReferenceObject;
3
+ export interface TupleElement {
4
+ schema: Schema;
5
+ /** Whether the array must reach this element (`minItems`). */
6
+ required: boolean;
7
+ }
8
+ /** A JSON Schema 2020-12 tuple: `prefixItems`, then what follows them. */
9
+ export interface Tuple {
10
+ elements: [TupleElement, ...TupleElement[]];
11
+ /** The schema of each item after the elements, or undefined when the array holds no more. */
12
+ rest: Schema | undefined;
13
+ }
14
+ /**
15
+ * The tuple `schema` describes, or undefined when it has no `prefixItems`
16
+ * element: an empty `prefixItems` leaves an array of `items`.
17
+ */
18
+ export declare function tupleOf(schema: SchemaObject): Tuple | undefined;
19
+ export {};
20
+ //# sourceMappingURL=tuple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuple.d.ts","sources":["../../src/lib/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEvE,KAAK,MAAM,GAAG,YAAY,GAAG,eAAe,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,0EAA0E;AAC1E,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,CAAC,YAAY,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;IAC5C,6FAA6F;IAC7F,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAMD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,KAAK,GAAG,SAAS,CAsB/D"}
@@ -0,0 +1,26 @@
1
+ function isSchema(value) {
2
+ return typeof value === "object" && value !== null;
3
+ }
4
+ function tupleOf(schema) {
5
+ const { prefixItems = [], minItems = 0, maxItems } = schema;
6
+ const [first, ...others] = prefixItems;
7
+ if (!first) {
8
+ return void 0;
9
+ }
10
+ const items = schema.items;
11
+ const closed = items === false || maxItems !== void 0 && maxItems <= prefixItems.length;
12
+ return {
13
+ elements: [
14
+ { schema: first, required: minItems > 0 },
15
+ ...others.map((element, index) => ({
16
+ schema: element,
17
+ required: index + 1 < minItems
18
+ }))
19
+ ],
20
+ rest: closed ? void 0 : isSchema(items) ? items : {}
21
+ };
22
+ }
23
+ export {
24
+ tupleOf
25
+ };
26
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/tuple.ts"],
4
+ "sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\ntype Schema = SchemaObject | ReferenceObject;\n\nexport interface TupleElement {\n schema: Schema;\n /** Whether the array must reach this element (`minItems`). */\n required: boolean;\n}\n\n/** A JSON Schema 2020-12 tuple: `prefixItems`, then what follows them. */\nexport interface Tuple {\n elements: [TupleElement, ...TupleElement[]];\n /** The schema of each item after the elements, or undefined when the array holds no more. */\n rest: Schema | undefined;\n}\n\nfunction isSchema(value: unknown): value is Schema {\n return typeof value === 'object' && value !== null;\n}\n\n/**\n * The tuple `schema` describes, or undefined when it has no `prefixItems`\n * element: an empty `prefixItems` leaves an array of `items`.\n */\nexport function tupleOf(schema: SchemaObject): Tuple | undefined {\n const { prefixItems = [], minItems = 0, maxItems } = schema;\n const [first, ...others] = prefixItems;\n if (!first) {\n return undefined;\n }\n // openapi3-ts types items as a schema object, though 2020-12 lets a schema\n // be a boolean: items: false closes the tuple.\n const items: unknown = schema.items;\n const closed =\n items === false ||\n (maxItems !== undefined && maxItems <= prefixItems.length);\n return {\n elements: [\n { schema: first, required: minItems > 0 },\n ...others.map((element, index) => ({\n schema: element,\n required: index + 1 < minItems,\n })),\n ],\n rest: closed ? undefined : isSchema(items) ? items : {},\n };\n}\n"],
5
+ "mappings": "AAiBA,SAAS,SAAS,OAAiC;AACjD,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAMO,SAAS,QAAQ,QAAyC;AAC/D,QAAM,EAAE,cAAc,CAAC,GAAG,WAAW,GAAG,SAAS,IAAI;AACrD,QAAM,CAAC,OAAO,GAAG,MAAM,IAAI;AAC3B,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAGA,QAAM,QAAiB,OAAO;AAC9B,QAAM,SACJ,UAAU,SACT,aAAa,UAAa,YAAY,YAAY;AACrD,SAAO;AAAA,IACL,UAAU;AAAA,MACR,EAAE,QAAQ,OAAO,UAAU,WAAW,EAAE;AAAA,MACxC,GAAG,OAAO,IAAI,CAAC,SAAS,WAAW;AAAA,QACjC,QAAQ;AAAA,QACR,UAAU,QAAQ,IAAI;AAAA,MACxB,EAAE;AAAA,IACJ;AAAA,IACA,MAAM,SAAS,SAAY,SAAS,KAAK,IAAI,QAAQ,CAAC;AAAA,EACxD;AACF;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdk-it/spec",
3
- "version": "0.49.1",
3
+ "version": "0.50.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/JanuaryLabs/sdk-it",
@@ -36,7 +36,7 @@
36
36
  "!**/*.test.*"
37
37
  ],
38
38
  "dependencies": {
39
- "@sdk-it/core": "0.49.1",
39
+ "@sdk-it/core": "0.50.0",
40
40
  "@zukhruf/async": "^0.8.33",
41
41
  "@zukhruf/fs": "^0.8.33",
42
42
  "lodash-es": "^4.17.21",