@sdk-it/spec 0.46.10 → 0.47.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.
Files changed (179) hide show
  1. package/README.md +8 -4
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -1
  5. package/dist/index.js.map +2 -2
  6. package/dist/lib/external-documents.d.ts +10 -0
  7. package/dist/lib/external-documents.d.ts.map +1 -0
  8. package/dist/lib/external-documents.js +61 -0
  9. package/dist/lib/external-documents.js.map +7 -0
  10. package/dist/lib/finalize-operations.d.ts +8 -0
  11. package/dist/lib/finalize-operations.d.ts.map +1 -0
  12. package/dist/lib/finalize-operations.js +134 -0
  13. package/dist/lib/finalize-operations.js.map +7 -0
  14. package/dist/lib/find-polymorphic-varients.d.ts.map +1 -1
  15. package/dist/lib/find-polymorphic-varients.js +3 -2
  16. package/dist/lib/find-polymorphic-varients.js.map +2 -2
  17. package/dist/lib/find-unique-schema-name.d.ts.map +1 -1
  18. package/dist/lib/for-each-operation.d.ts +3 -2
  19. package/dist/lib/for-each-operation.d.ts.map +1 -1
  20. package/dist/lib/for-each-operation.js +9 -4
  21. package/dist/lib/for-each-operation.js.map +2 -2
  22. package/dist/lib/format-name.d.ts.map +1 -1
  23. package/dist/lib/get-ref-usage.d.ts.map +1 -1
  24. package/dist/lib/get-ref-usage.js +1 -2
  25. package/dist/lib/get-ref-usage.js.map +2 -2
  26. package/dist/lib/guess/guess-resource.d.ts.map +1 -1
  27. package/dist/lib/guess/guess-resource.js +4 -4
  28. package/dist/lib/guess/guess-resource.js.map +2 -2
  29. package/dist/lib/ir.d.ts +2 -2
  30. package/dist/lib/ir.d.ts.map +1 -1
  31. package/dist/lib/ir.js +5 -3
  32. package/dist/lib/ir.js.map +2 -2
  33. package/dist/lib/is-primitive-schema.d.ts +12 -0
  34. package/dist/lib/is-primitive-schema.d.ts.map +1 -1
  35. package/dist/lib/is-primitive-schema.js +34 -1
  36. package/dist/lib/is-primitive-schema.js.map +2 -2
  37. package/dist/lib/is.d.ts +10 -1
  38. package/dist/lib/is.d.ts.map +1 -1
  39. package/dist/lib/is.js +20 -9
  40. package/dist/lib/is.js.map +2 -2
  41. package/dist/lib/loaders/load-spec.d.ts +9 -2
  42. package/dist/lib/loaders/load-spec.d.ts.map +1 -1
  43. package/dist/lib/loaders/load-spec.js +15 -20
  44. package/dist/lib/loaders/load-spec.js.map +2 -2
  45. package/dist/lib/loaders/local-loader.d.ts.map +1 -1
  46. package/dist/lib/loaders/postman/postman-converter.d.ts +1 -1
  47. package/dist/lib/loaders/postman/postman-converter.d.ts.map +1 -1
  48. package/dist/lib/loaders/postman/postman-converter.js +2 -3
  49. package/dist/lib/loaders/postman/postman-converter.js.map +2 -2
  50. package/dist/lib/loaders/postman/spec-types.d.ts.map +1 -1
  51. package/dist/lib/loaders/remote-loader.d.ts.map +1 -1
  52. package/dist/lib/loaders/remote-loader.js +4 -3
  53. package/dist/lib/loaders/remote-loader.js.map +2 -2
  54. package/dist/lib/metadata.d.ts +3 -9
  55. package/dist/lib/metadata.d.ts.map +1 -1
  56. package/dist/lib/metadata.js +22 -17
  57. package/dist/lib/metadata.js.map +2 -2
  58. package/dist/lib/operation-input.d.ts +33 -0
  59. package/dist/lib/operation-input.d.ts.map +1 -0
  60. package/dist/lib/operation-input.js +189 -0
  61. package/dist/lib/operation-input.js.map +7 -0
  62. package/dist/lib/options.d.ts +5 -6
  63. package/dist/lib/options.d.ts.map +1 -1
  64. package/dist/lib/options.js +0 -6
  65. package/dist/lib/options.js.map +2 -2
  66. package/dist/lib/overview-docs/doc-text-utils.d.ts +13 -13
  67. package/dist/lib/overview-docs/doc-text-utils.d.ts.map +1 -1
  68. package/dist/lib/overview-docs/overview-auth.d.ts.map +1 -1
  69. package/dist/lib/overview-docs/overview-auth.js.map +2 -2
  70. package/dist/lib/overview-docs/overview-docs.d.ts.map +1 -1
  71. package/dist/lib/overview-docs/overview-errors.d.ts.map +1 -1
  72. package/dist/lib/overview-docs/overview-errors.js +8 -5
  73. package/dist/lib/overview-docs/overview-errors.js.map +2 -2
  74. package/dist/lib/overview-docs/overview-page.d.ts.map +1 -1
  75. package/dist/lib/overview-docs/overview-page.js +2 -3
  76. package/dist/lib/overview-docs/overview-page.js.map +2 -2
  77. package/dist/lib/overview-docs/overview-pagination.d.ts.map +1 -1
  78. package/dist/lib/overview-docs/overview-sdks.d.ts.map +1 -1
  79. package/dist/lib/overview-docs/overview-sdks.js +2 -1
  80. package/dist/lib/overview-docs/overview-sdks.js.map +2 -2
  81. package/dist/lib/overview-docs/types.d.ts.map +1 -1
  82. package/dist/lib/overview-docs/types.js +1 -1
  83. package/dist/lib/overview-docs/types.js.map +2 -2
  84. package/dist/lib/pagination/guess-pagination.d.ts.map +1 -1
  85. package/dist/lib/pagination/guess-pagination.js.map +2 -2
  86. package/dist/lib/pagination/pagination-result.d.ts +3 -3
  87. package/dist/lib/pagination/pagination-result.d.ts.map +1 -1
  88. package/dist/lib/pagination/pagination-result.js +6 -3
  89. package/dist/lib/pagination/pagination-result.js.map +2 -2
  90. package/dist/lib/pagination/pagination.d.ts +31 -1
  91. package/dist/lib/pagination/pagination.d.ts.map +1 -1
  92. package/dist/lib/pagination/pagination.js +30 -11
  93. package/dist/lib/pagination/pagination.js.map +2 -2
  94. package/dist/lib/processing-plugins/bundle-external-refs.d.ts +17 -0
  95. package/dist/lib/processing-plugins/bundle-external-refs.d.ts.map +1 -0
  96. package/dist/lib/processing-plugins/bundle-external-refs.js +241 -0
  97. package/dist/lib/processing-plugins/bundle-external-refs.js.map +7 -0
  98. package/dist/lib/processing-plugins/canonicalize-spec.d.ts +2 -2
  99. package/dist/lib/processing-plugins/canonicalize-spec.d.ts.map +1 -1
  100. package/dist/lib/processing-plugins/canonicalize-spec.js.map +2 -2
  101. package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts +4 -3
  102. package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts.map +1 -1
  103. package/dist/lib/processing-plugins/create-default-processing-plugins.js +10 -3
  104. package/dist/lib/processing-plugins/create-default-processing-plugins.js.map +2 -2
  105. package/dist/lib/processing-plugins/enrich-examples.d.ts +4 -4
  106. package/dist/lib/processing-plugins/enrich-examples.d.ts.map +1 -1
  107. package/dist/lib/processing-plugins/enrich-examples.js +1 -1
  108. package/dist/lib/processing-plugins/enrich-examples.js.map +2 -2
  109. package/dist/lib/processing-plugins/extract-inline-schemas.d.ts +2 -2
  110. package/dist/lib/processing-plugins/extract-inline-schemas.d.ts.map +1 -1
  111. package/dist/lib/processing-plugins/extract-inline-schemas.js.map +2 -2
  112. package/dist/lib/processing-plugins/extract-overview-docs.d.ts +2 -2
  113. package/dist/lib/processing-plugins/extract-overview-docs.d.ts.map +1 -1
  114. package/dist/lib/processing-plugins/extract-overview-docs.js +4 -1
  115. package/dist/lib/processing-plugins/extract-overview-docs.js.map +2 -2
  116. package/dist/lib/processing-plugins/index.d.ts +1 -0
  117. package/dist/lib/processing-plugins/index.d.ts.map +1 -1
  118. package/dist/lib/processing-plugins/index.js +1 -0
  119. package/dist/lib/processing-plugins/index.js.map +2 -2
  120. package/dist/lib/processing-plugins/infer-pagination.d.ts +2 -2
  121. package/dist/lib/processing-plugins/infer-pagination.d.ts.map +1 -1
  122. package/dist/lib/processing-plugins/infer-pagination.js +5 -6
  123. package/dist/lib/processing-plugins/infer-pagination.js.map +2 -2
  124. package/dist/lib/processing-plugins/normalize-operation-ids.d.ts +2 -2
  125. package/dist/lib/processing-plugins/normalize-operation-ids.d.ts.map +1 -1
  126. package/dist/lib/processing-plugins/normalize-operation-ids.js.map +2 -2
  127. package/dist/lib/processing-plugins/normalize-parameters.d.ts +2 -2
  128. package/dist/lib/processing-plugins/normalize-parameters.d.ts.map +1 -1
  129. package/dist/lib/processing-plugins/normalize-parameters.js.map +2 -2
  130. package/dist/lib/processing-plugins/normalize-paths.d.ts +2 -2
  131. package/dist/lib/processing-plugins/normalize-paths.d.ts.map +1 -1
  132. package/dist/lib/processing-plugins/normalize-paths.js.map +2 -2
  133. package/dist/lib/processing-plugins/normalize-request-bodies.d.ts +9 -3
  134. package/dist/lib/processing-plugins/normalize-request-bodies.d.ts.map +1 -1
  135. package/dist/lib/processing-plugins/normalize-request-bodies.js +36 -15
  136. package/dist/lib/processing-plugins/normalize-request-bodies.js.map +2 -2
  137. package/dist/lib/processing-plugins/normalize-responses.d.ts +2 -2
  138. package/dist/lib/processing-plugins/normalize-responses.d.ts.map +1 -1
  139. package/dist/lib/processing-plugins/normalize-responses.js +11 -15
  140. package/dist/lib/processing-plugins/normalize-responses.js.map +2 -2
  141. package/dist/lib/processing-plugins/normalize-schemas.d.ts +2 -2
  142. package/dist/lib/processing-plugins/normalize-schemas.d.ts.map +1 -1
  143. package/dist/lib/processing-plugins/normalize-schemas.js +14 -4
  144. package/dist/lib/processing-plugins/normalize-schemas.js.map +2 -2
  145. package/dist/lib/processing-plugins/normalize-security.d.ts +2 -2
  146. package/dist/lib/processing-plugins/normalize-security.d.ts.map +1 -1
  147. package/dist/lib/processing-plugins/normalize-security.js +6 -5
  148. package/dist/lib/processing-plugins/normalize-security.js.map +2 -2
  149. package/dist/lib/processing-plugins/normalize-tags.d.ts +8 -2
  150. package/dist/lib/processing-plugins/normalize-tags.d.ts.map +1 -1
  151. package/dist/lib/processing-plugins/normalize-tags.js +35 -1
  152. package/dist/lib/processing-plugins/normalize-tags.js.map +2 -2
  153. package/dist/lib/processing-plugins/resolve-security-scheme-uris.d.ts +13 -2
  154. package/dist/lib/processing-plugins/resolve-security-scheme-uris.d.ts.map +1 -1
  155. package/dist/lib/processing-plugins/resolve-security-scheme-uris.js +68 -90
  156. package/dist/lib/processing-plugins/resolve-security-scheme-uris.js.map +2 -2
  157. package/dist/lib/processing.d.ts +25 -11
  158. package/dist/lib/processing.d.ts.map +1 -1
  159. package/dist/lib/processing.js +53 -16
  160. package/dist/lib/processing.js.map +2 -2
  161. package/dist/lib/reserved-keywords.d.ts.map +1 -1
  162. package/dist/lib/sidebar.d.ts +5 -4
  163. package/dist/lib/sidebar.d.ts.map +1 -1
  164. package/dist/lib/sidebar.js +46 -23
  165. package/dist/lib/sidebar.js.map +2 -2
  166. package/dist/lib/tag.d.ts.map +1 -1
  167. package/dist/lib/types.d.ts +34 -12
  168. package/dist/lib/types.d.ts.map +1 -1
  169. package/dist/lib/types.js +11 -0
  170. package/dist/lib/types.js.map +3 -3
  171. package/dist/lib/walk-schemas.d.ts +4 -2
  172. package/dist/lib/walk-schemas.d.ts.map +1 -1
  173. package/dist/lib/walk-schemas.js +15 -13
  174. package/dist/lib/walk-schemas.js.map +2 -2
  175. package/package.json +17 -6
  176. package/dist/lib/create-operation.d.ts +0 -28
  177. package/dist/lib/create-operation.d.ts.map +0 -1
  178. package/dist/lib/create-operation.js +0 -62
  179. package/dist/lib/create-operation.js.map +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/processing-plugins/resolve-security-scheme-uris.ts"],
4
- "sourcesContent": ["import { fileURLToPath } from 'node:url';\nimport type { SecurityRequirementObject } from 'openapi3-ts/oas31';\n\nimport {\n type OpenAPISecuritySchemeObject,\n followRef,\n isRef,\n} from '@sdk-it/core';\n\nimport { iterateOperations } from '../for-each-operation.js';\nimport { loadFile } from '../loaders/load-spec.js';\nimport type { ProcessingPlugin } from '../processing.js';\nimport type { IR } from '../types.js';\n\n/**\n * OpenAPI 3.2 lets a security requirement key be a URI of a Security Scheme\n * Object instead of a `components.securitySchemes` name. Generators key\n * credentials by scheme name, so each URI is fetched, registered locally, and\n * the requirement rewritten to point at the registered name.\n */\nexport function resolveSecuritySchemeUris(): ProcessingPlugin {\n return {\n name: 'resolve-security-scheme-uris',\n async process({ spec, report }) {\n const requirements = collectRequirements(spec);\n const uris = new Set(\n requirements\n .flatMap((requirement) => Object.keys(requirement))\n .filter(\n (key) => !spec.components.securitySchemes[key] && isUriKey(key),\n ),\n );\n if (!uris.size) {\n return;\n }\n\n const documents = new Map<string, Promise<unknown>>();\n const registered = new Map<string, string>();\n for (const uri of uris) {\n try {\n const scheme = await resolveScheme(uri, spec, documents);\n // A same-document pointer lands on an already registered object;\n // reuse its name instead of registering a second copy.\n const [alias] =\n Object.entries(spec.components.securitySchemes).find(\n ([, registeredScheme]) => registeredScheme === scheme,\n ) ?? [];\n const name = alias ?? availableName(spec, schemeName(uri));\n spec.components.securitySchemes[name] = scheme;\n registered.set(uri, name);\n } catch (error) {\n report({\n code: 'unresolvable-security-scheme-uri',\n severity: 'error',\n path: uri,\n message: `Could not resolve security scheme URI ${uri}: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n }\n\n for (const requirement of requirements) {\n for (const [uri, name] of registered) {\n if (Object.hasOwn(requirement, uri)) {\n requirement[name] = requirement[uri];\n delete requirement[uri];\n }\n }\n }\n },\n };\n}\n\nfunction collectRequirements(spec: IR) {\n const requirements: SecurityRequirementObject[] = [...(spec.security ?? [])];\n for (const { operation } of iterateOperations(spec)) {\n requirements.push(...(operation.security ?? []));\n }\n return requirements;\n}\n\n/**\n * Component keys are limited to `^[a-zA-Z0-9._-]+$`, so anything else can only\n * be a URI. A bare `auth.yaml` stays a name \u2014 treating it as a document would\n * turn a typo into a file read.\n */\nfunction isUriKey(key: string) {\n return !/^[a-zA-Z0-9._-]+$/.test(key);\n}\n\nasync function resolveScheme(\n uri: string,\n spec: IR,\n documents: Map<string, Promise<unknown>>,\n): Promise<OpenAPISecuritySchemeObject> {\n const [location, fragment] = splitFragment(uri);\n const document = location\n ? await loadDocument(location, spec, documents)\n : spec;\n let scheme = fragment ? readPointer(document, fragment) : document;\n if (isRef(scheme)) {\n scheme = followRef(document as never, scheme.$ref);\n }\n if (\n scheme === null ||\n typeof scheme !== 'object' ||\n typeof (scheme as { type?: unknown }).type !== 'string'\n ) {\n return Promise.reject(\n new Error('the target is not a Security Scheme Object'),\n );\n }\n return scheme as OpenAPISecuritySchemeObject;\n}\n\nfunction loadDocument(\n location: string,\n spec: IR,\n documents: Map<string, Promise<unknown>>,\n) {\n const base = spec.$self;\n if (!base && !isAbsolute(location)) {\n return Promise.reject(\n new Error(\n 'the document declares no $self, so a relative URI has no base to resolve against',\n ),\n );\n }\n const url = new URL(location, base);\n if (url.href === base) {\n return Promise.resolve(spec);\n }\n let pending = documents.get(url.href);\n if (!pending) {\n pending = loadFile(\n url.protocol === 'file:' ? fileURLToPath(url) : url.href,\n );\n documents.set(url.href, pending);\n }\n return pending;\n}\n\nfunction isAbsolute(location: string) {\n return URL.canParse(location);\n}\n\nfunction splitFragment(uri: string): [string, string | undefined] {\n const index = uri.indexOf('#');\n return index === -1\n ? [uri, undefined]\n : [uri.slice(0, index), uri.slice(index + 1)];\n}\n\nfunction readPointer(document: unknown, fragment: string) {\n let current: unknown = document;\n for (const segment of fragment.split('/')) {\n if (!segment) {\n continue;\n }\n const key = decodeURIComponent(segment)\n .replaceAll('~1', '/')\n .replaceAll('~0', '~');\n if (\n current === null ||\n typeof current !== 'object' ||\n !(key in (current as object))\n ) {\n throw new Error(`no value at pointer #${fragment}`);\n }\n current = (current as Record<string, unknown>)[key];\n }\n return current;\n}\n\nfunction schemeName(uri: string) {\n const [location, fragment] = splitFragment(uri);\n const candidate =\n lastSegment(fragment ?? '') ??\n lastSegment(location.split('?')[0])?.replace(/\\.(json|ya?ml)$/i, '');\n const sanitized = (candidate ?? '').replace(/[^a-zA-Z0-9._-]/g, '');\n return sanitized || 'externalSecurityScheme';\n}\n\nfunction lastSegment(value: string) {\n return value.split('/').filter(Boolean).at(-1);\n}\n\nfunction availableName(spec: IR, candidate: string) {\n let name = candidate;\n let suffix = 2;\n while (spec.components.securitySchemes[name]) {\n name = `${candidate}${suffix++}`;\n }\n return name;\n}\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAG9B;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAClC,SAAS,gBAAgB;AAUlB,SAAS,4BAA8C;AAC5D,SAAO;AAAA,IAC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C9B;AAEA,SAAS,cAAc,KAA2C;AAChE,QAAM,QAAQ,IAAI,QAAQ,GAAG;AAC7B,SAAO,UAAU,KACb,CAAC,KAAK,MAAS,IACf,CAAC,IAAI,MAAM,GAAG,KAAK,GAAG,IAAI,MAAM,QAAQ,CAAC,CAAC;AAChD;AAEA,SAAS,YAAY,UAAmB,UAAkB;AACxD,MAAI,UAAmB;AACvB,aAAW,WAAW,SAAS,MAAM,GAAG,GAAG;AACzC,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AACA,UAAM,MAAM,mBAAmB,OAAO,EACnC,WAAW,MAAM,GAAG,EACpB,WAAW,MAAM,GAAG;AACvB,QACE,YAAY,QACZ,OAAO,YAAY,YACnB,EAAE,OAAQ,UACV;AACA,YAAM,IAAI,MAAM,wBAAwB,QAAQ,EAAE;AAAA,IACpD;AACA,cAAW,QAAoC,GAAG;AAAA,EACpD;AACA,SAAO;AACT;AAEA,SAAS,WAAW,KAAa;AAC/B,QAAM,CAAC,UAAU,QAAQ,IAAI,cAAc,GAAG;AAC9C,QAAM,YACJ,YAAY,YAAY,EAAE,KAC1B,YAAY,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,GAAG,QAAQ,oBAAoB,EAAE;AACrE,QAAM,aAAa,aAAa,IAAI,QAAQ,oBAAoB,EAAE;AAClE,SAAO,aAAa;AACtB;AAEA,SAAS,YAAY,OAAe;AAClC,SAAO,MAAM,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE;AAC/C;AAEA,SAAS,cAAc,MAAU,WAAmB;AAClD,MAAI,OAAO;AACX,MAAI,SAAS;AACb,SAAO,KAAK,WAAW,gBAAgB,IAAI,GAAG;AAC5C,WAAO,GAAG,SAAS,GAAG,QAAQ;AAAA,EAChC;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import type { SecurityRequirementObject } from 'openapi3-ts/oas31';\n\nimport {\n type OpenAPIDocument,\n type OpenAPISecuritySchemeObject,\n followRef,\n isRef,\n} from '@sdk-it/core';\n\nimport {\n type Documents,\n availableName,\n documentUrl,\n isJsonObject,\n loadDocument,\n readPointer,\n splitFragment,\n} from '../external-documents.js';\nimport { iterateOperations } from '../for-each-operation.js';\nimport type { DocumentPlugin } from '../processing.js';\n\n/**\n * OpenAPI 3.2 lets a security requirement key be a URI of a Security Scheme\n * Object instead of a `components.securitySchemes` name. Generators key\n * credentials by scheme name, so each URI is fetched, registered locally, and\n * the requirement rewritten to point at the registered name.\n */\nexport function resolveSecuritySchemeUris(): DocumentPlugin {\n return {\n name: 'resolve-security-scheme-uris',\n async process({ spec, report }) {\n const failures = await registerExternalSecuritySchemes(spec, new Map());\n for (const { uri, error } of failures) {\n report({\n code: 'unresolvable-security-scheme-uri',\n severity: 'error',\n path: uri,\n message: `Could not resolve security scheme URI ${uri}: ${Error.isError(error) ? error.message : String(error)}`,\n });\n }\n },\n };\n}\n\n/**\n * Registers the scheme behind each URI requirement key under a local name and\n * rewrites the requirement to it. Every document read is recorded in\n * `documents`; the URIs that could not be resolved are returned.\n */\nexport async function registerExternalSecuritySchemes(\n spec: OpenAPIDocument,\n documents: Documents,\n) {\n const requirements = collectRequirements(spec);\n const uris = new Set(\n requirements\n .flatMap((requirement) => Object.keys(requirement))\n .filter(\n (key) => !spec.components?.securitySchemes?.[key] && isUriKey(key),\n ),\n );\n const failures: { uri: string; error: unknown }[] = [];\n if (!uris.size) {\n return failures;\n }\n\n const schemes = ((spec.components ??= {}).securitySchemes ??= {});\n const registered = new Map<string, string>();\n for (const uri of uris) {\n try {\n const scheme = await resolveScheme(uri, spec, documents);\n // A same-document pointer lands on an already registered object;\n // reuse its name instead of registering a second copy.\n const [alias] =\n Object.entries(schemes).find(\n ([, registeredScheme]) => registeredScheme === scheme,\n ) ?? [];\n const name = alias ?? availableName(schemes, schemeName(uri));\n schemes[name] = scheme;\n registered.set(uri, name);\n } catch (error) {\n failures.push({ uri, error });\n }\n }\n\n for (const requirement of requirements) {\n for (const [uri, name] of registered) {\n if (Object.hasOwn(requirement, uri)) {\n requirement[name] = requirement[uri];\n delete requirement[uri];\n }\n }\n }\n return failures;\n}\n\nfunction collectRequirements(spec: OpenAPIDocument) {\n const requirements: SecurityRequirementObject[] = [...(spec.security ?? [])];\n for (const { operation } of iterateOperations({ paths: spec.paths ?? {} })) {\n requirements.push(...(operation.security ?? []));\n }\n return requirements;\n}\n\n/**\n * Component keys are limited to `^[a-zA-Z0-9._-]+$`, so anything else can only\n * be a URI. A bare `auth.yaml` stays a name \u2014 treating it as a document would\n * turn a typo into a file read.\n */\nfunction isUriKey(key: string) {\n return !/^[a-zA-Z0-9._-]+$/.test(key);\n}\n\nasync function resolveScheme(\n uri: string,\n spec: OpenAPIDocument,\n documents: Documents,\n): Promise<OpenAPISecuritySchemeObject> {\n const [location, fragment] = splitFragment(uri);\n const document = location\n ? await schemeDocument(location, spec, documents)\n : spec;\n let scheme = fragment ? readPointer(document, fragment) : document;\n if (isRef(scheme)) {\n scheme = followRef(document, scheme.$ref);\n }\n if (!isSecurityScheme(scheme)) {\n return Promise.reject(\n new Error('the target is not a Security Scheme Object'),\n );\n }\n return scheme;\n}\n\nconst securitySchemeTypes = [\n 'apiKey',\n 'http',\n 'mutualTLS',\n 'oauth2',\n 'openIdConnect',\n] as const;\n\nfunction isSecurityScheme(\n value: unknown,\n): value is OpenAPISecuritySchemeObject {\n return (\n isJsonObject(value) &&\n securitySchemeTypes.some((type) => type === value.type)\n );\n}\n\nfunction schemeDocument(\n location: string,\n spec: OpenAPIDocument,\n documents: Documents,\n) {\n const url = documentUrl(location, spec.$self);\n return url.href === spec.$self ? spec : loadDocument(url, documents);\n}\n\nfunction schemeName(uri: string) {\n const [location, fragment] = splitFragment(uri);\n const candidate =\n lastSegment(fragment ?? '') ??\n lastSegment(location.split('?')[0])?.replace(/\\.(json|ya?ml)$/i, '');\n const sanitized = (candidate ?? '').replace(/[^a-zA-Z0-9._-]/g, '');\n return sanitized || 'externalSecurityScheme';\n}\n\nfunction lastSegment(value: string) {\n return value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S,iBACP,OACsC;AACtC,SACE,aAAa,KAAK,KAClB,oBAAoB,KAAK,CAAC,SAAS,SAAS,MAAM,IAAI;AAE1D;AAEA,SAAS,eACP,UACA,MACA,WACA;AACA,QAAM,MAAM,YAAY,UAAU,KAAK,KAAK;AAC5C,SAAO,IAAI,SAAS,KAAK,QAAQ,OAAO,aAAa,KAAK,SAAS;AACrE;AAEA,SAAS,WAAW,KAAa;AAC/B,QAAM,CAAC,UAAU,QAAQ,IAAI,cAAc,GAAG;AAC9C,QAAM,YACJ,YAAY,YAAY,EAAE,KAC1B,YAAY,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,GAAG,QAAQ,oBAAoB,EAAE;AACrE,QAAM,aAAa,aAAa,IAAI,QAAQ,oBAAoB,EAAE;AAClE,SAAO,aAAa;AACtB;AAEA,SAAS,YAAY,OAAe;AAClC,SAAO,MAAM,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE;AAC/C;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import { type GenerateSdkConfig, coeraceConfig as coerceConfig } from './options.js';
2
- import type { IR } from './types.js';
2
+ import type { IR, ProcessingDocument } from './types.js';
3
3
  export type ProcessingDiagnosticSeverity = 'info' | 'warning' | 'error';
4
4
  export interface ProcessingDiagnostic {
5
5
  plugin: string;
@@ -9,25 +9,39 @@ export interface ProcessingDiagnostic {
9
9
  path?: string;
10
10
  }
11
11
  export type ProcessingOptions = Omit<ReturnType<typeof coerceConfig>, 'spec'>;
12
- export interface ProcessingContext {
13
- spec: IR;
12
+ export interface ProcessingContext<Spec> {
13
+ spec: Spec;
14
14
  options: ProcessingOptions;
15
15
  diagnostics: ProcessingDiagnostic[];
16
16
  signal?: AbortSignal;
17
17
  report(diagnostic: Omit<ProcessingDiagnostic, 'plugin'>): ProcessingDiagnostic;
18
18
  }
19
- export interface ProcessingPlugin {
19
+ /** A plugin that rewrites the raw OpenAPI document before its operations are finalized. */
20
+ export interface DocumentPlugin {
20
21
  name: string;
21
- process(context: ProcessingContext): void | Promise<void>;
22
+ process(context: ProcessingContext<ProcessingDocument>): void | Promise<void>;
23
+ }
24
+ /** A plugin that works on the IR, whose operations are already tuned. */
25
+ export interface IRPlugin {
26
+ name: string;
27
+ process(context: ProcessingContext<IR>): void | Promise<void>;
28
+ }
29
+ export interface ProcessDocumentConfig extends GenerateSdkConfig {
30
+ plugins: readonly DocumentPlugin[];
22
31
  }
23
32
  export interface ProcessSpecConfig extends GenerateSdkConfig {
24
- plugins: readonly ProcessingPlugin[];
25
- signal?: AbortSignal;
26
- onDiagnostic?: (diagnostic: ProcessingDiagnostic) => void;
33
+ documentPlugins?: readonly DocumentPlugin[];
34
+ irPlugins?: readonly IRPlugin[];
27
35
  }
28
- export interface ProcessingResult {
29
- spec: IR;
36
+ export interface ProcessingResult<Spec> {
37
+ spec: Spec;
30
38
  diagnostics: ProcessingDiagnostic[];
31
39
  }
32
- export declare function processSpec(config: ProcessSpecConfig): Promise<ProcessingResult>;
40
+ /** Runs document-stage plugins only; the result's operations are still raw. */
41
+ export declare function processDocument(config: ProcessDocumentConfig): Promise<ProcessingResult<ProcessingDocument>>;
42
+ /**
43
+ * Runs the document-stage plugins, finalizes the operations into the IR, then
44
+ * runs the IR-stage plugins. Each omitted plugin list uses its defaults.
45
+ */
46
+ export declare function processSpec(config: ProcessSpecConfig): Promise<ProcessingResult<IR>>;
33
47
  //# sourceMappingURL=processing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../../src/lib/processing.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,iBAAiB,EACtB,aAAa,IAAI,YAAY,EAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAExE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,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,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB,CAAC,IAAI;IACpC,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC;AAuDD,+EAA+E;AAC/E,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,CAW/C;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAkB/B"}
@@ -1,21 +1,13 @@
1
1
  import { untilAborted } from "@zukhruf/async";
2
+ import { finalizeOperations } from "./finalize-operations.js";
2
3
  import {
3
4
  coeraceConfig as coerceConfig
4
5
  } from "./options.js";
5
- async function processSpec(config) {
6
- const { plugins, signal, onDiagnostic, ...generateConfig } = config;
7
- signal?.throwIfAborted();
8
- const coerced = coerceConfig({
9
- ...generateConfig,
10
- spec: structuredClone(generateConfig.spec)
11
- });
12
- const { spec, ...options } = coerced;
13
- const diagnostics = [];
14
- const pluginNames = plugins.map((plugin) => plugin.name);
15
- const configuration = JSON.stringify({
16
- pagination: options.pagination,
17
- responses: options.responses
18
- });
6
+ import {
7
+ createDefaultDocumentPlugins,
8
+ createDefaultIRPlugins
9
+ } from "./processing-plugins/create-default-processing-plugins.js";
10
+ async function runPlugins(spec, plugins, { options, diagnostics, signal, onDiagnostic }) {
19
11
  for (const plugin of plugins) {
20
12
  signal?.throwIfAborted();
21
13
  const context = {
@@ -33,10 +25,55 @@ async function processSpec(config) {
33
25
  await untilAborted(Promise.resolve(plugin.process(context)), signal);
34
26
  signal?.throwIfAborted();
35
27
  }
36
- spec["x-sdk-processing"] = { plugins: pluginNames, configuration };
37
- return { spec, diagnostics };
28
+ }
29
+ async function runDocumentStage(config, plugins) {
30
+ const { signal, onDiagnostic } = config;
31
+ signal?.throwIfAborted();
32
+ const { spec, ...options } = coerceConfig({
33
+ ...config,
34
+ spec: structuredClone(config.spec)
35
+ });
36
+ const run = { options, diagnostics: [], signal, onDiagnostic };
37
+ await runPlugins(spec, plugins, run);
38
+ const configuration = JSON.stringify({
39
+ pagination: options.pagination,
40
+ responses: options.responses
41
+ });
42
+ return { spec, run, configuration };
43
+ }
44
+ async function processDocument(config) {
45
+ const { plugins, ...generateConfig } = config;
46
+ const { spec, run, configuration } = await runDocumentStage(
47
+ generateConfig,
48
+ plugins
49
+ );
50
+ spec["x-sdk-processing"] = {
51
+ plugins: plugins.map((plugin) => plugin.name),
52
+ configuration
53
+ };
54
+ return { spec, diagnostics: run.diagnostics };
55
+ }
56
+ async function processSpec(config) {
57
+ const {
58
+ documentPlugins = createDefaultDocumentPlugins(),
59
+ irPlugins = createDefaultIRPlugins(),
60
+ ...generateConfig
61
+ } = config;
62
+ const {
63
+ spec: document,
64
+ run,
65
+ configuration
66
+ } = await runDocumentStage(generateConfig, documentPlugins);
67
+ const spec = finalizeOperations(document);
68
+ await runPlugins(spec, irPlugins, run);
69
+ spec["x-sdk-processing"] = {
70
+ plugins: [...documentPlugins, ...irPlugins].map((plugin) => plugin.name),
71
+ configuration
72
+ };
73
+ return { spec, diagnostics: run.diagnostics };
38
74
  }
39
75
  export {
76
+ processDocument,
40
77
  processSpec
41
78
  };
42
79
  //# sourceMappingURL=processing.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/processing.ts"],
4
- "sourcesContent": ["import { untilAborted } from '@zukhruf/async';\n\nimport type { OpenAPIDocument } from '@sdk-it/core';\n\nimport {\n type GenerateSdkConfig,\n coeraceConfig as coerceConfig,\n} from './options.js';\nimport type { IR } from './types.js';\n\nexport type ProcessingDiagnosticSeverity = 'info' | 'warning' | 'error';\n\nexport interface ProcessingDiagnostic {\n plugin: string;\n severity: ProcessingDiagnosticSeverity;\n code: string;\n message: string;\n path?: string;\n}\n\nexport type ProcessingOptions = Omit<ReturnType<typeof coerceConfig>, 'spec'>;\n\nexport interface ProcessingContext {\n spec: IR;\n options: ProcessingOptions;\n diagnostics: ProcessingDiagnostic[];\n signal?: AbortSignal;\n report(\n diagnostic: Omit<ProcessingDiagnostic, 'plugin'>,\n ): ProcessingDiagnostic;\n}\n\nexport interface ProcessingPlugin {\n name: string;\n process(context: ProcessingContext): void | Promise<void>;\n}\n\nexport interface ProcessSpecConfig extends GenerateSdkConfig {\n plugins: readonly ProcessingPlugin[];\n signal?: AbortSignal;\n onDiagnostic?: (diagnostic: ProcessingDiagnostic) => void;\n}\n\nexport interface ProcessingResult {\n spec: IR;\n diagnostics: ProcessingDiagnostic[];\n}\n\nexport async function processSpec(\n config: ProcessSpecConfig,\n): Promise<ProcessingResult> {\n const { plugins, signal, onDiagnostic, ...generateConfig } = config;\n signal?.throwIfAborted();\n const coerced = coerceConfig({\n ...generateConfig,\n spec: structuredClone(generateConfig.spec) as OpenAPIDocument,\n });\n const { spec, ...options } = coerced;\n const diagnostics: ProcessingDiagnostic[] = [];\n const pluginNames = plugins.map((plugin) => plugin.name);\n const configuration = JSON.stringify({\n pagination: options.pagination,\n responses: options.responses,\n });\n\n for (const plugin of plugins) {\n signal?.throwIfAborted();\n const context: ProcessingContext = {\n spec,\n options,\n diagnostics,\n signal,\n report(diagnostic) {\n const reported = { ...diagnostic, plugin: plugin.name };\n diagnostics.push(reported);\n onDiagnostic?.(reported);\n return reported;\n },\n };\n await untilAborted(Promise.resolve(plugin.process(context)), signal);\n signal?.throwIfAborted();\n }\n\n spec['x-sdk-processing'] = { plugins: pluginNames, configuration };\n\n return { spec, diagnostics };\n}\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAI7B;AAAA,EAEE,iBAAiB;AAAA,OACZ;AAyCP,eAAsB,YACpB,QAC2B;AAC3B,QAAM,EAAE,SAAS,QAAQ,cAAc,GAAG,eAAe,IAAI;AAC7D,UAAQ,eAAe;AACvB,QAAM,UAAU,aAAa;AAAA,IAC3B,GAAG;AAAA,IACH,MAAM,gBAAgB,eAAe,IAAI;AAAA,EAC3C,CAAC;AACD,QAAM,EAAE,MAAM,GAAG,QAAQ,IAAI;AAC7B,QAAM,cAAsC,CAAC;AAC7C,QAAM,cAAc,QAAQ,IAAI,CAAC,WAAW,OAAO,IAAI;AACvD,QAAM,gBAAgB,KAAK,UAAU;AAAA,IACnC,YAAY,QAAQ;AAAA,IACpB,WAAW,QAAQ;AAAA,EACrB,CAAC;AAED,aAAW,UAAU,SAAS;AAC5B,YAAQ,eAAe;AACvB,UAAM,UAA6B;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,YAAY;AACjB,cAAM,WAAW,EAAE,GAAG,YAAY,QAAQ,OAAO,KAAK;AACtD,oBAAY,KAAK,QAAQ;AACzB,uBAAe,QAAQ;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AACA,UAAM,aAAa,QAAQ,QAAQ,OAAO,QAAQ,OAAO,CAAC,GAAG,MAAM;AACnE,YAAQ,eAAe;AAAA,EACzB;AAEA,OAAK,kBAAkB,IAAI,EAAE,SAAS,aAAa,cAAc;AAEjE,SAAO,EAAE,MAAM,YAAY;AAC7B;",
4
+ "sourcesContent": ["import { untilAborted } from '@zukhruf/async';\n\nimport { finalizeOperations } from './finalize-operations.js';\nimport {\n type GenerateSdkConfig,\n coeraceConfig as coerceConfig,\n} from './options.js';\nimport {\n createDefaultDocumentPlugins,\n createDefaultIRPlugins,\n} from './processing-plugins/create-default-processing-plugins.js';\nimport type { IR, ProcessingDocument } from './types.js';\n\nexport type ProcessingDiagnosticSeverity = 'info' | 'warning' | 'error';\n\nexport interface ProcessingDiagnostic {\n plugin: string;\n severity: ProcessingDiagnosticSeverity;\n code: string;\n message: string;\n path?: string;\n}\n\nexport type ProcessingOptions = Omit<ReturnType<typeof coerceConfig>, 'spec'>;\n\nexport interface ProcessingContext<Spec> {\n spec: Spec;\n options: ProcessingOptions;\n diagnostics: ProcessingDiagnostic[];\n signal?: AbortSignal;\n report(\n diagnostic: Omit<ProcessingDiagnostic, 'plugin'>,\n ): ProcessingDiagnostic;\n}\n\n/** A plugin that rewrites the raw OpenAPI document before its operations are finalized. */\nexport interface DocumentPlugin {\n name: string;\n process(context: ProcessingContext<ProcessingDocument>): void | Promise<void>;\n}\n\n/** A plugin that works on the IR, whose operations are already tuned. */\nexport interface IRPlugin {\n name: string;\n process(context: ProcessingContext<IR>): void | Promise<void>;\n}\n\nexport interface ProcessDocumentConfig extends GenerateSdkConfig {\n plugins: readonly DocumentPlugin[];\n}\n\nexport interface ProcessSpecConfig extends GenerateSdkConfig {\n documentPlugins?: readonly DocumentPlugin[];\n irPlugins?: readonly IRPlugin[];\n}\n\nexport interface ProcessingResult<Spec> {\n spec: Spec;\n diagnostics: ProcessingDiagnostic[];\n}\n\ninterface Run {\n options: ProcessingOptions;\n diagnostics: ProcessingDiagnostic[];\n signal?: AbortSignal;\n onDiagnostic?: (diagnostic: ProcessingDiagnostic) => void;\n}\n\nasync function runPlugins<Spec>(\n spec: Spec,\n plugins: readonly {\n name: string;\n process(context: ProcessingContext<Spec>): void | Promise<void>;\n }[],\n { options, diagnostics, signal, onDiagnostic }: Run,\n) {\n for (const plugin of plugins) {\n signal?.throwIfAborted();\n const context: ProcessingContext<Spec> = {\n spec,\n options,\n diagnostics,\n signal,\n report(diagnostic) {\n const reported = { ...diagnostic, plugin: plugin.name };\n diagnostics.push(reported);\n onDiagnostic?.(reported);\n return reported;\n },\n };\n await untilAborted(Promise.resolve(plugin.process(context)), signal);\n signal?.throwIfAborted();\n }\n}\n\nasync function runDocumentStage(\n config: GenerateSdkConfig,\n plugins: readonly DocumentPlugin[],\n) {\n const { signal, onDiagnostic } = config;\n signal?.throwIfAborted();\n const { spec, ...options } = coerceConfig({\n ...config,\n spec: structuredClone(config.spec),\n });\n const run: Run = { options, diagnostics: [], signal, onDiagnostic };\n await runPlugins(spec, plugins, run);\n const configuration = JSON.stringify({\n pagination: options.pagination,\n responses: options.responses,\n });\n return { spec, run, configuration };\n}\n\n/** Runs document-stage plugins only; the result's operations are still raw. */\nexport async function processDocument(\n config: ProcessDocumentConfig,\n): Promise<ProcessingResult<ProcessingDocument>> {\n const { plugins, ...generateConfig } = config;\n const { spec, run, configuration } = await runDocumentStage(\n generateConfig,\n plugins,\n );\n spec['x-sdk-processing'] = {\n plugins: plugins.map((plugin) => plugin.name),\n configuration,\n };\n return { spec, diagnostics: run.diagnostics };\n}\n\n/**\n * Runs the document-stage plugins, finalizes the operations into the IR, then\n * runs the IR-stage plugins. Each omitted plugin list uses its defaults.\n */\nexport async function processSpec(\n config: ProcessSpecConfig,\n): Promise<ProcessingResult<IR>> {\n const {\n documentPlugins = createDefaultDocumentPlugins(),\n irPlugins = createDefaultIRPlugins(),\n ...generateConfig\n } = config;\n const {\n spec: document,\n run,\n configuration,\n } = await runDocumentStage(generateConfig, documentPlugins);\n const spec = finalizeOperations(document);\n await runPlugins(spec, irPlugins, run);\n spec['x-sdk-processing'] = {\n plugins: [...documentPlugins, ...irPlugins].map((plugin) => plugin.name),\n configuration,\n };\n return { spec, diagnostics: run.diagnostics };\n}\n"],
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC;AAAA,EAEE,iBAAiB;AAAA,OACZ;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AA0DP,eAAe,WACb,MACA,SAIA,EAAE,SAAS,aAAa,QAAQ,aAAa,GAC7C;AACA,aAAW,UAAU,SAAS;AAC5B,YAAQ,eAAe;AACvB,UAAM,UAAmC;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,YAAY;AACjB,cAAM,WAAW,EAAE,GAAG,YAAY,QAAQ,OAAO,KAAK;AACtD,oBAAY,KAAK,QAAQ;AACzB,uBAAe,QAAQ;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AACA,UAAM,aAAa,QAAQ,QAAQ,OAAO,QAAQ,OAAO,CAAC,GAAG,MAAM;AACnE,YA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AM,aAAa,IAAI,YAAY;AAC9C;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"reserved-keywords.d.ts","sourceRoot":"","sources":["../../src/lib/reserved-keywords.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB,aAmE3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAI9B,CAAC"}
1
+ {"version":3,"file":"reserved-keywords.d.ts","sources":["../../src/lib/reserved-keywords.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB,aAmE3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAI9B,CAAC"}
@@ -19,9 +19,10 @@ export type CategoryItem = {
19
19
  items: NavItem[];
20
20
  };
21
21
  export type SidebarData = CategoryItem[];
22
- export interface TagGroups {
23
- name: string;
24
- tags: string[];
25
- }
22
+ /**
23
+ * The documentation pages, then one section per tag hierarchy (OpenAPI 3.2
24
+ * `parent`): each group with operations sits under its top-most ancestor's
25
+ * section, and a group with no parent sits in the API section.
26
+ */
26
27
  export declare function toSidebar(spec: IR): SidebarData;
27
28
  //# sourceMappingURL=sidebar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sidebar.d.ts","sourceRoot":"","sources":["../../src/lib/sidebar.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,YAAY,EAAE,CAAC;AAEzC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,EAAE,eA8BjC"}
1
+ {"version":3,"file":"sidebar.d.ts","sources":["../../src/lib/sidebar.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,YAAY,EAAE,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,EAAE,eAuCjC"}
@@ -3,33 +3,56 @@ import { notNullOrUndefined } from "@sdk-it/core/file-system.js";
3
3
  import { forEachOperation } from "./for-each-operation.js";
4
4
  function toSidebar(spec) {
5
5
  const sidebar = [...spec["x-docs"]];
6
- for (const tagGroup of spec["x-tagGroups"]) {
7
- sidebar.push({
8
- id: camelcase(tagGroup.name),
9
- category: tagGroup.name,
10
- items: tagGroup.tags.map((tag) => {
11
- const tagSpec = spec.tags?.find((t) => t.name === tag);
12
- return {
13
- id: crypto.randomUUID(),
14
- description: tagSpec?.description,
15
- title: tagSpec ? tagSpec["x-displayName"] || tagSpec.name || tag : tag,
16
- items: forEachOperation(spec, (entry, operation) => {
17
- if (operation.tags.includes(tag)) {
18
- const title = operation.summary || operation.operationId;
19
- return {
20
- id: operation.operationId,
21
- title,
22
- url: `${camelcase(tag)}/${camelcase(operation.operationId)}`
23
- };
24
- }
25
- return null;
26
- }).filter(notNullOrUndefined)
27
- };
28
- })
6
+ const tags = new Map(spec.tags.map((tag) => [tag.name, tag]));
7
+ const sections = /* @__PURE__ */ new Map();
8
+ for (const tag of spec.tags) {
9
+ const operations = forEachOperation(
10
+ spec,
11
+ (entry, operation) => operation.tags.includes(tag.name) ? {
12
+ id: operation.operationId,
13
+ title: operation.summary || operation.operationId,
14
+ url: `${camelcase(tag.name)}/${camelcase(operation.operationId)}`
15
+ } : null
16
+ ).filter(notNullOrUndefined);
17
+ if (operations.length === 0) {
18
+ continue;
19
+ }
20
+ const root = topAncestor(tag, tags);
21
+ let section = sections.get(root);
22
+ if (!section) {
23
+ section = root ? {
24
+ id: camelcase(root.name),
25
+ category: root.summary ?? root.name,
26
+ description: root.description,
27
+ items: []
28
+ } : { id: camelcase("API"), category: "API", items: [] };
29
+ sections.set(root, section);
30
+ sidebar.push(section);
31
+ }
32
+ section.items.push({
33
+ id: crypto.randomUUID(),
34
+ title: tag.summary ?? tag.name,
35
+ description: tag.description,
36
+ items: operations
29
37
  });
30
38
  }
31
39
  return sidebar;
32
40
  }
41
+ function topAncestor(tag, tags) {
42
+ let ancestor;
43
+ const passed = /* @__PURE__ */ new Set([tag.name]);
44
+ let parent = tag.parent;
45
+ while (parent !== void 0 && !passed.has(parent)) {
46
+ const next = tags.get(parent);
47
+ if (!next) {
48
+ break;
49
+ }
50
+ passed.add(parent);
51
+ ancestor = next;
52
+ parent = next.parent;
53
+ }
54
+ return ancestor;
55
+ }
33
56
  export {
34
57
  toSidebar
35
58
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/sidebar.ts"],
4
- "sourcesContent": ["import { camelcase } from 'stringcase';\n\nimport { notNullOrUndefined } from '@sdk-it/core/file-system.js';\n\nimport { forEachOperation } from './for-each-operation.js';\nimport type { IR } from './types.js';\n\nexport type ChildNavItem = {\n id: string;\n title: string;\n url: string;\n};\n\nexport type NavItem = {\n id: string;\n title: string;\n description?: string;\n url?: string;\n items?: ChildNavItem[];\n content?: string; // Markdown content\n};\n\nexport type CategoryItem = {\n id: string;\n category: string;\n description?: string;\n items: NavItem[];\n};\n\nexport type SidebarData = CategoryItem[];\n\nexport interface TagGroups {\n name: string;\n tags: string[];\n}\n\nexport function toSidebar(spec: IR) {\n const sidebar: SidebarData = [...spec['x-docs']];\n for (const tagGroup of spec['x-tagGroups']) {\n sidebar.push({\n id: camelcase(tagGroup.name),\n category: tagGroup.name,\n items: tagGroup.tags.map((tag) => {\n const tagSpec = spec.tags?.find((t) => t.name === tag);\n return {\n id: crypto.randomUUID(),\n description: tagSpec?.description,\n title: tagSpec\n ? tagSpec['x-displayName'] || tagSpec.name || tag\n : tag,\n items: forEachOperation(spec, (entry, operation) => {\n if (operation.tags.includes(tag)) {\n const title = operation.summary || operation.operationId;\n return {\n id: operation.operationId,\n title,\n url: `${camelcase(tag)}/${camelcase(operation.operationId)}`,\n };\n }\n return null;\n }).filter(notNullOrUndefined),\n };\n }),\n });\n }\n return sidebar;\n}\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAE1B,SAAS,0BAA0B;AAEnC,SAAS,wBAAwB;AAgC1B,SAAS,UAAU,MAAU;AAClC,QAAM,UAAuB,CAAC,GAAG,KAAK,QAAQ,CAAC;AAC/C,aAAW,YAAY,KAAK,aAAa,GAAG;AAC1C,YAAQ,KAAK;AAAA,MACX,IAAI,UAAU,SAAS,IAAI;AAAA,MAC3B,UAAU,SAAS;AAAA,MACnB,OAAO,SAAS,KAAK,IAAI,CAAC,QAAQ;AAChC,cAAM,UAAU,KAAK,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG;AACrD,eAAO;AAAA,UACL,IAAI,OAAO,WAAW;AAAA,UACtB,aAAa,SAAS;AAAA,UACtB,OAAO,UACH,QAAQ,eAAe,KAAK,QAAQ,QAAQ,MAC5C;AAAA,UACJ,OAAO,iBAAiB,MAAM,CAAC,OAAO,cAAc;AAClD,gBAAI,UAAU,KAAK,SAAS,GAAG,GAAG;AAChC,oBAAM,QAAQ,UAAU,WAAW,UAAU;AAC7C,qBAAO;AAAA,gBACL,IAAI,UAAU;AAAA,gBACd;AAAA,gBACA,KAAK,GAAG,UAAU,GAAG,CAAC,IAAI,UAAU,UAAU,WAAW,CAAC;AAAA,cAC5D;AAAA,YACF;AACA,mBAAO;AAAA,UACT,CAAC,EAAE,OAAO,kBAAkB;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import type { TagObject } from 'openapi3-ts/oas32';\nimport { camelcase } from 'stringcase';\n\nimport { notNullOrUndefined } from '@sdk-it/core/file-system.js';\n\nimport { forEachOperation } from './for-each-operation.js';\nimport type { IR } from './types.js';\n\nexport type ChildNavItem = {\n id: string;\n title: string;\n url: string;\n};\n\nexport type NavItem = {\n id: string;\n title: string;\n description?: string;\n url?: string;\n items?: ChildNavItem[];\n content?: string; // Markdown content\n};\n\nexport type CategoryItem = {\n id: string;\n category: string;\n description?: string;\n items: NavItem[];\n};\n\nexport type SidebarData = CategoryItem[];\n\n/**\n * The documentation pages, then one section per tag hierarchy (OpenAPI 3.2\n * `parent`): each group with operations sits under its top-most ancestor's\n * section, and a group with no parent sits in the API section.\n */\nexport function toSidebar(spec: IR) {\n const sidebar: SidebarData = [...spec['x-docs']];\n const tags = new Map(spec.tags.map((tag) => [tag.name, tag]));\n const sections = new Map<TagObject | undefined, CategoryItem>();\n for (const tag of spec.tags) {\n const operations = forEachOperation(spec, (entry, operation) =>\n operation.tags.includes(tag.name)\n ? {\n id: operation.operationId,\n title: operation.summary || operation.operationId,\n url: `${camelcase(tag.name)}/${camelcase(operation.operationId)}`,\n }\n : null,\n ).filter(notNullOrUndefined);\n if (operations.length === 0) {\n continue;\n }\n const root = topAncestor(tag, tags);\n let section = sections.get(root);\n if (!section) {\n section = root\n ? {\n id: camelcase(root.name),\n category: root.summary ?? root.name,\n description: root.description,\n items: [],\n }\n : { id: camelcase('API'), category: 'API', items: [] };\n sections.set(root, section);\n sidebar.push(section);\n }\n section.items.push({\n id: crypto.randomUUID(),\n title: tag.summary ?? tag.name,\n description: tag.description,\n items: operations,\n });\n }\n return sidebar;\n}\n\n/** The tag that `tag`'s parent chain ends at; none for a tag without a parent. A chain stops at a name no tag has or one it already passed. */\nfunction topAncestor(tag: TagObject, tags: Map<string, TagObject>) {\n let ancestor: TagObject | undefined;\n const passed = new Set([tag.name]);\n let parent = tag.parent;\n while (parent !== undefined && !passed.has(parent)) {\n const next = tags.get(parent);\n if (!next) {\n break;\n }\n passed.add(parent);\n ancestor = next;\n parent = next.parent;\n }\n return ancestor;\n}\n"],
5
+ "mappings": "AACA,SAAS,iBAAiB;AAE1B,SAAS,0BAA0B;AAEnC,SAAS,wBAAwB;AAgC1B,SAAS,UAAU,MAAU;AAClC,QAAM,UAAuB,CAAC,GAAG,KAAK,QAAQ,CAAC;AAC/C,QAAM,OAAO,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AAC5D,QAAM,WAAW,oBAAI,IAAyC;AAC9D,aAAW,OAAO,KAA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",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../src/lib/tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMzD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C;AACD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAetD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,eAAe,GACzB,MAAM,CAoLR"}
1
+ {"version":3,"file":"tag.d.ts","sources":["../../src/lib/tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMzD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C;AACD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAetD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,eAAe,GACzB,MAAM,CAoLR"}
@@ -1,9 +1,11 @@
1
- import type { MediaTypeObject, OperationObject, ParameterObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject, ServerObject, TagObject } from 'openapi3-ts/oas31';
1
+ import type { MediaTypeObject, OperationObject, ParameterObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject, SecurityRequirementObject, ServerObject } from 'openapi3-ts/oas31';
2
+ import type { TagObject } from 'openapi3-ts/oas32';
2
3
  import type { OpenAPIComponentsObject, OpenAPIDocument, OpenAPISecuritySchemeObject } from '@sdk-it/core';
4
+ import type { Method } from '@sdk-it/core/paths.js';
3
5
  import type { SdkDoc } from './overview-docs/types.js';
4
- import type { PaginationGuess } from './pagination/guess-pagination.js';
5
- import type { SidebarData, TagGroups } from './sidebar.js';
6
- export type IR = Omit<OpenAPIDocument, 'components' | 'paths' | 'servers' | 'tags'> & {
6
+ import type { CursorPaginationResult, OffsetPaginationResult, PagePaginationResult } from './pagination/guess-pagination.js';
7
+ import type { SidebarData } from './sidebar.js';
8
+ type SpecDocument<Paths> = Omit<OpenAPIDocument, 'components' | 'paths' | 'servers' | 'tags'> & {
7
9
  servers: ServerObject[];
8
10
  'x-sdk-processing'?: {
9
11
  plugins: string[];
@@ -11,36 +13,49 @@ export type IR = Omit<OpenAPIDocument, 'components' | 'paths' | 'servers' | 'tag
11
13
  };
12
14
  'x-docs': SidebarData;
13
15
  'x-sdks': SdkDoc[];
14
- 'x-tagGroups': TagGroups[];
15
16
  components: Omit<OpenAPIComponentsObject, 'schemas' | 'securitySchemes'> & {
16
17
  schemas: Record<string, SchemaObject | ReferenceObject>;
17
18
  securitySchemes: Record<string, OpenAPISecuritySchemeObject>;
18
19
  };
19
- paths: PathsObject;
20
+ paths: Paths;
20
21
  tags: TagObject[];
21
22
  };
23
+ /** The document the document-stage plugins rewrite: its operations are still raw OpenAPI. */
24
+ export type ProcessingDocument = SpecDocument<PathsObject>;
25
+ export type IRPaths = Record<string, Partial<Record<Method, TunedOperationObject>>>;
26
+ /** The processed spec: every operation is a {@link TunedOperationObject} built by `finalizeOperations`. */
27
+ export type IR = SpecDocument<IRPaths>;
22
28
  export interface OurRequestBodyObject extends RequestBodyObject {
23
29
  content: Record<string, Omit<MediaTypeObject, 'schema'> & {
24
30
  schema: ReferenceObject;
25
31
  }>;
26
32
  }
27
- export type ResponseBody = 'json' | 'text' | 'binary' | 'stream' | 'sse' | 'empty';
33
+ export declare const responseBodies: readonly ['json', 'text', 'binary', 'stream', 'sse', 'empty'];
34
+ export type ResponseBody = (typeof responseBodies)[number];
28
35
  export type TunedResponseObject = Omit<ResponseObject, 'content'> & {
29
36
  content: Record<string, MediaTypeObject>;
30
37
  'x-body': ResponseBody;
31
38
  'x-response-name'?: string;
32
39
  };
33
- export type TunedOperationObject = Omit<OperationObject, 'operationId' | 'tags' | 'parameters' | 'responses' | 'requestBody' | 'tags'> & {
34
- tags: string[];
40
+ export type TunedOperationObject = Omit<OperationObject, 'operationId' | 'tags' | 'parameters' | 'responses' | 'requestBody' | 'security' | `x-${string}`> & {
41
+ tags: [string];
35
42
  operationId: string;
36
43
  parameters: ParameterObject[];
44
+ security: SecurityRequirementObject[];
37
45
  ['x-fn-name']: string;
38
- ['x-fn-group']?: string;
46
+ ['x-fn-group']: string;
47
+ ['x-pagination']?: OperationPagination;
48
+ ['x-tool']?: OperationTool;
39
49
  responses: Record<string, TunedResponseObject>;
40
50
  requestBody: OurRequestBodyObject;
41
51
  };
52
+ /** The agent tool an operation is exposed as (`x-tool`). */
53
+ export interface OperationTool {
54
+ name?: string;
55
+ description?: string;
56
+ }
42
57
  export interface OperationEntry {
43
- method: string;
58
+ method: Method;
44
59
  path: string;
45
60
  tag: string;
46
61
  }
@@ -48,8 +63,15 @@ export type Operation = {
48
63
  entry: OperationEntry;
49
64
  operation: TunedOperationObject;
50
65
  };
51
- export type OperationPagination = PaginationGuess & {
66
+ /** Spec processing stores a pagination only when one was configured or detected. */
67
+ export type OperationPagination = ((OffsetPaginationResult & {
68
+ start?: number;
69
+ }) | (PagePaginationResult & {
70
+ start?: number;
71
+ }) | CursorPaginationResult) & {
52
72
  items: string;
73
+ hasMore: string;
53
74
  statusCode: number;
54
75
  };
76
+ export {};
55
77
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EACV,uBAAuB,EACvB,eAAe,EACf,2BAA2B,EAC5B,MAAM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C;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AACD,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAEF,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,CAC9B,CAAC,sBAAsB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC7C,CAAC,oBAAoB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC3C,sBAAsB,CACzB,GAAG;IACF,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
package/dist/lib/types.js CHANGED
@@ -1 +1,12 @@
1
+ const responseBodies = [
2
+ "json",
3
+ "text",
4
+ "binary",
5
+ "stream",
6
+ "sse",
7
+ "empty"
8
+ ];
9
+ export {
10
+ responseBodies
11
+ };
1
12
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
3
+ "sources": ["../../src/lib/types.ts"],
4
+ "sourcesContent": ["import type {\n MediaTypeObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ReferenceObject,\n RequestBodyObject,\n ResponseObject,\n SchemaObject,\n SecurityRequirementObject,\n ServerObject,\n} from 'openapi3-ts/oas31';\nimport type { TagObject } from 'openapi3-ts/oas32';\n\nimport type {\n OpenAPIComponentsObject,\n OpenAPIDocument,\n OpenAPISecuritySchemeObject,\n} from '@sdk-it/core';\nimport type { Method } from '@sdk-it/core/paths.js';\n\nimport type { SdkDoc } from './overview-docs/types.js';\nimport type {\n CursorPaginationResult,\n OffsetPaginationResult,\n PagePaginationResult,\n} from './pagination/guess-pagination.js';\nimport type { SidebarData } from './sidebar.js';\n\ntype SpecDocument<Paths> = Omit<\n OpenAPIDocument,\n 'components' | 'paths' | 'servers' | 'tags'\n> & {\n servers: ServerObject[];\n 'x-sdk-processing'?: {\n plugins: string[];\n configuration: string;\n };\n 'x-docs': SidebarData;\n 'x-sdks': SdkDoc[];\n components: Omit<OpenAPIComponentsObject, 'schemas' | 'securitySchemes'> & {\n schemas: Record<string, SchemaObject | ReferenceObject>;\n securitySchemes: Record<string, OpenAPISecuritySchemeObject>;\n };\n paths: Paths;\n tags: TagObject[];\n};\n\n/** The document the document-stage plugins rewrite: its operations are still raw OpenAPI. */\nexport type ProcessingDocument = SpecDocument<PathsObject>;\n\nexport type IRPaths = Record<\n string,\n Partial<Record<Method, TunedOperationObject>>\n>;\n\n/** The processed spec: every operation is a {@link TunedOperationObject} built by `finalizeOperations`. */\nexport type IR = SpecDocument<IRPaths>;\n\nexport interface OurRequestBodyObject extends RequestBodyObject {\n content: Record<\n string,\n Omit<MediaTypeObject, 'schema'> & { schema: ReferenceObject }\n >;\n}\n\nexport const responseBodies = [\n 'json',\n 'text',\n 'binary',\n 'stream',\n 'sse',\n 'empty',\n] as const;\n\nexport type ResponseBody = (typeof responseBodies)[number];\n\nexport type TunedResponseObject = Omit<ResponseObject, 'content'> & {\n content: Record<string, MediaTypeObject>;\n 'x-body': ResponseBody;\n 'x-response-name'?: string;\n};\n\nexport type TunedOperationObject = Omit<\n OperationObject,\n | 'operationId'\n | 'tags'\n | 'parameters'\n | 'responses'\n | 'requestBody'\n | 'security'\n | `x-${string}`\n> & {\n tags: [string];\n operationId: string;\n parameters: ParameterObject[];\n security: SecurityRequirementObject[];\n ['x-fn-name']: string;\n ['x-fn-group']: string;\n ['x-pagination']?: OperationPagination;\n ['x-tool']?: OperationTool;\n responses: Record<string, TunedResponseObject>;\n requestBody: OurRequestBodyObject;\n};\n\n/** The agent tool an operation is exposed as (`x-tool`). */\nexport interface OperationTool {\n name?: string;\n description?: string;\n}\n\nexport interface OperationEntry {\n method: Method;\n path: string;\n tag: string;\n}\nexport type Operation = {\n entry: OperationEntry;\n operation: TunedOperationObject;\n};\n\n/** Spec processing stores a pagination only when one was configured or detected. */\nexport type OperationPagination = (\n | (OffsetPaginationResult & { start?: number })\n | (PagePaginationResult & { start?: number })\n | CursorPaginationResult\n) & {\n items: string;\n hasMore: string;\n statusCode: number;\n};\n"],
5
+ "mappings": "AAkEO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,10 @@
1
- import type { SchemaObject } from 'openapi3-ts/oas31';
1
+ import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';
2
2
  import type { IR } from './types.js';
3
3
  export interface WalkedSchema {
4
4
  schema: SchemaObject;
5
5
  pointer: string;
6
6
  }
7
- export declare function walkSchemas(spec: IR): Generator<WalkedSchema>;
7
+ /** Each schema `schema` nests directly, with its pointer segment. */
8
+ export declare function subschemas(schema: SchemaObject): Generator<[segment: string, child: SchemaObject | ReferenceObject]>;
9
+ export declare function walkSchemas(spec: Pick<IR, 'components'>): Generator<WalkedSchema>;
8
10
  //# sourceMappingURL=walk-schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"walk-schemas.d.ts","sourceRoot":"","sources":["../../src/lib/walk-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIvE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAiDD,wBAAiB,WAAW,CAAC,IAAI,EAAE,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,CAS9D"}
1
+ {"version":3,"file":"walk-schemas.d.ts","sources":["../../src/lib/walk-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIvE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,qEAAqE;AACrE,wBAAiB,UAAU,CACzB,MAAM,EAAE,YAAY,GACnB,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,eAAe,CAAC,CAAC,CA0BrE;AAmBD,wBAAiB,WAAW,CAC1B,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,CAAC,GAC3B,SAAS,CAAC,YAAY,CAAC,CASzB"}
@@ -2,20 +2,11 @@ import { isRef } from "@sdk-it/core/ref.js";
2
2
  function escapePointerSegment(segment) {
3
3
  return segment.replaceAll("~", "~0").replaceAll("/", "~1");
4
4
  }
5
- function* walkSchema(schema, pointer, visited) {
6
- if (isRef(schema) || visited.has(schema)) {
7
- return;
8
- }
9
- visited.add(schema);
10
- yield { schema, pointer };
5
+ function* subschemas(schema) {
11
6
  for (const key of ["properties", "x-properties"]) {
12
7
  const properties = schema[key];
13
8
  for (const [name, property] of Object.entries(properties ?? {})) {
14
- yield* walkSchema(
15
- property,
16
- `${pointer}/${key}/${escapePointerSegment(name)}`,
17
- visited
18
- );
9
+ yield [`${key}/${escapePointerSegment(name)}`, property];
19
10
  }
20
11
  }
21
12
  for (const key of [
@@ -26,15 +17,25 @@ function* walkSchema(schema, pointer, visited) {
26
17
  ]) {
27
18
  const child = schema[key];
28
19
  if (typeof child === "object" && child !== null) {
29
- yield* walkSchema(child, `${pointer}/${key}`, visited);
20
+ yield [key, child];
30
21
  }
31
22
  }
32
23
  for (const key of ["allOf", "oneOf", "anyOf", "prefixItems"]) {
33
24
  for (const [index, child] of (schema[key] ?? []).entries()) {
34
- yield* walkSchema(child, `${pointer}/${key}/${index}`, visited);
25
+ yield [`${key}/${index}`, child];
35
26
  }
36
27
  }
37
28
  }
29
+ function* walkSchema(schema, pointer, visited) {
30
+ if (isRef(schema) || visited.has(schema)) {
31
+ return;
32
+ }
33
+ visited.add(schema);
34
+ yield { schema, pointer };
35
+ for (const [segment, child] of subschemas(schema)) {
36
+ yield* walkSchema(child, `${pointer}/${segment}`, visited);
37
+ }
38
+ }
38
39
  function* walkSchemas(spec) {
39
40
  const visited = /* @__PURE__ */ new WeakSet();
40
41
  for (const [name, schema] of Object.entries(spec.components.schemas)) {
@@ -46,6 +47,7 @@ function* walkSchemas(spec) {
46
47
  }
47
48
  }
48
49
  export {
50
+ subschemas,
49
51
  walkSchemas
50
52
  };
51
53
  //# sourceMappingURL=walk-schemas.js.map