@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.
- package/README.md +8 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +2 -2
- package/dist/lib/external-documents.d.ts +10 -0
- package/dist/lib/external-documents.d.ts.map +1 -0
- package/dist/lib/external-documents.js +61 -0
- package/dist/lib/external-documents.js.map +7 -0
- package/dist/lib/finalize-operations.d.ts +8 -0
- package/dist/lib/finalize-operations.d.ts.map +1 -0
- package/dist/lib/finalize-operations.js +134 -0
- package/dist/lib/finalize-operations.js.map +7 -0
- package/dist/lib/find-polymorphic-varients.d.ts.map +1 -1
- package/dist/lib/find-polymorphic-varients.js +3 -2
- package/dist/lib/find-polymorphic-varients.js.map +2 -2
- package/dist/lib/find-unique-schema-name.d.ts.map +1 -1
- package/dist/lib/for-each-operation.d.ts +3 -2
- package/dist/lib/for-each-operation.d.ts.map +1 -1
- package/dist/lib/for-each-operation.js +9 -4
- package/dist/lib/for-each-operation.js.map +2 -2
- package/dist/lib/format-name.d.ts.map +1 -1
- package/dist/lib/get-ref-usage.d.ts.map +1 -1
- package/dist/lib/get-ref-usage.js +1 -2
- package/dist/lib/get-ref-usage.js.map +2 -2
- package/dist/lib/guess/guess-resource.d.ts.map +1 -1
- package/dist/lib/guess/guess-resource.js +4 -4
- package/dist/lib/guess/guess-resource.js.map +2 -2
- package/dist/lib/ir.d.ts +2 -2
- package/dist/lib/ir.d.ts.map +1 -1
- package/dist/lib/ir.js +5 -3
- package/dist/lib/ir.js.map +2 -2
- package/dist/lib/is-primitive-schema.d.ts +12 -0
- package/dist/lib/is-primitive-schema.d.ts.map +1 -1
- package/dist/lib/is-primitive-schema.js +34 -1
- package/dist/lib/is-primitive-schema.js.map +2 -2
- package/dist/lib/is.d.ts +10 -1
- package/dist/lib/is.d.ts.map +1 -1
- package/dist/lib/is.js +20 -9
- package/dist/lib/is.js.map +2 -2
- package/dist/lib/loaders/load-spec.d.ts +9 -2
- package/dist/lib/loaders/load-spec.d.ts.map +1 -1
- package/dist/lib/loaders/load-spec.js +15 -20
- package/dist/lib/loaders/load-spec.js.map +2 -2
- package/dist/lib/loaders/local-loader.d.ts.map +1 -1
- package/dist/lib/loaders/postman/postman-converter.d.ts +1 -1
- package/dist/lib/loaders/postman/postman-converter.d.ts.map +1 -1
- package/dist/lib/loaders/postman/postman-converter.js +2 -3
- package/dist/lib/loaders/postman/postman-converter.js.map +2 -2
- package/dist/lib/loaders/postman/spec-types.d.ts.map +1 -1
- package/dist/lib/loaders/remote-loader.d.ts.map +1 -1
- package/dist/lib/loaders/remote-loader.js +4 -3
- package/dist/lib/loaders/remote-loader.js.map +2 -2
- package/dist/lib/metadata.d.ts +3 -9
- package/dist/lib/metadata.d.ts.map +1 -1
- package/dist/lib/metadata.js +22 -17
- package/dist/lib/metadata.js.map +2 -2
- package/dist/lib/operation-input.d.ts +33 -0
- package/dist/lib/operation-input.d.ts.map +1 -0
- package/dist/lib/operation-input.js +189 -0
- package/dist/lib/operation-input.js.map +7 -0
- package/dist/lib/options.d.ts +5 -6
- package/dist/lib/options.d.ts.map +1 -1
- package/dist/lib/options.js +0 -6
- package/dist/lib/options.js.map +2 -2
- package/dist/lib/overview-docs/doc-text-utils.d.ts +13 -13
- package/dist/lib/overview-docs/doc-text-utils.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-auth.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-auth.js.map +2 -2
- package/dist/lib/overview-docs/overview-docs.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-errors.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-errors.js +8 -5
- package/dist/lib/overview-docs/overview-errors.js.map +2 -2
- package/dist/lib/overview-docs/overview-page.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-page.js +2 -3
- package/dist/lib/overview-docs/overview-page.js.map +2 -2
- package/dist/lib/overview-docs/overview-pagination.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-sdks.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-sdks.js +2 -1
- package/dist/lib/overview-docs/overview-sdks.js.map +2 -2
- package/dist/lib/overview-docs/types.d.ts.map +1 -1
- package/dist/lib/overview-docs/types.js +1 -1
- package/dist/lib/overview-docs/types.js.map +2 -2
- package/dist/lib/pagination/guess-pagination.d.ts.map +1 -1
- package/dist/lib/pagination/guess-pagination.js.map +2 -2
- package/dist/lib/pagination/pagination-result.d.ts +3 -3
- package/dist/lib/pagination/pagination-result.d.ts.map +1 -1
- package/dist/lib/pagination/pagination-result.js +6 -3
- package/dist/lib/pagination/pagination-result.js.map +2 -2
- package/dist/lib/pagination/pagination.d.ts +31 -1
- package/dist/lib/pagination/pagination.d.ts.map +1 -1
- package/dist/lib/pagination/pagination.js +30 -11
- package/dist/lib/pagination/pagination.js.map +2 -2
- package/dist/lib/processing-plugins/bundle-external-refs.d.ts +17 -0
- package/dist/lib/processing-plugins/bundle-external-refs.d.ts.map +1 -0
- package/dist/lib/processing-plugins/bundle-external-refs.js +241 -0
- package/dist/lib/processing-plugins/bundle-external-refs.js.map +7 -0
- package/dist/lib/processing-plugins/canonicalize-spec.d.ts +2 -2
- package/dist/lib/processing-plugins/canonicalize-spec.d.ts.map +1 -1
- package/dist/lib/processing-plugins/canonicalize-spec.js.map +2 -2
- package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts +4 -3
- package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts.map +1 -1
- package/dist/lib/processing-plugins/create-default-processing-plugins.js +10 -3
- package/dist/lib/processing-plugins/create-default-processing-plugins.js.map +2 -2
- package/dist/lib/processing-plugins/enrich-examples.d.ts +4 -4
- package/dist/lib/processing-plugins/enrich-examples.d.ts.map +1 -1
- package/dist/lib/processing-plugins/enrich-examples.js +1 -1
- package/dist/lib/processing-plugins/enrich-examples.js.map +2 -2
- package/dist/lib/processing-plugins/extract-inline-schemas.d.ts +2 -2
- package/dist/lib/processing-plugins/extract-inline-schemas.d.ts.map +1 -1
- package/dist/lib/processing-plugins/extract-inline-schemas.js.map +2 -2
- package/dist/lib/processing-plugins/extract-overview-docs.d.ts +2 -2
- package/dist/lib/processing-plugins/extract-overview-docs.d.ts.map +1 -1
- package/dist/lib/processing-plugins/extract-overview-docs.js +4 -1
- package/dist/lib/processing-plugins/extract-overview-docs.js.map +2 -2
- package/dist/lib/processing-plugins/index.d.ts +1 -0
- package/dist/lib/processing-plugins/index.d.ts.map +1 -1
- package/dist/lib/processing-plugins/index.js +1 -0
- package/dist/lib/processing-plugins/index.js.map +2 -2
- package/dist/lib/processing-plugins/infer-pagination.d.ts +2 -2
- package/dist/lib/processing-plugins/infer-pagination.d.ts.map +1 -1
- package/dist/lib/processing-plugins/infer-pagination.js +5 -6
- package/dist/lib/processing-plugins/infer-pagination.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-operation-ids.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-operation-ids.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-operation-ids.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-parameters.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-parameters.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-parameters.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-paths.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-paths.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-paths.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-request-bodies.d.ts +9 -3
- package/dist/lib/processing-plugins/normalize-request-bodies.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-request-bodies.js +36 -15
- package/dist/lib/processing-plugins/normalize-request-bodies.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-responses.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-responses.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-responses.js +11 -15
- package/dist/lib/processing-plugins/normalize-responses.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-schemas.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-schemas.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-schemas.js +14 -4
- package/dist/lib/processing-plugins/normalize-schemas.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-security.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-security.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-security.js +6 -5
- package/dist/lib/processing-plugins/normalize-security.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-tags.d.ts +8 -2
- package/dist/lib/processing-plugins/normalize-tags.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-tags.js +35 -1
- package/dist/lib/processing-plugins/normalize-tags.js.map +2 -2
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.d.ts +13 -2
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.d.ts.map +1 -1
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.js +68 -90
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.js.map +2 -2
- package/dist/lib/processing.d.ts +25 -11
- package/dist/lib/processing.d.ts.map +1 -1
- package/dist/lib/processing.js +53 -16
- package/dist/lib/processing.js.map +2 -2
- package/dist/lib/reserved-keywords.d.ts.map +1 -1
- package/dist/lib/sidebar.d.ts +5 -4
- package/dist/lib/sidebar.d.ts.map +1 -1
- package/dist/lib/sidebar.js +46 -23
- package/dist/lib/sidebar.js.map +2 -2
- package/dist/lib/tag.d.ts.map +1 -1
- package/dist/lib/types.d.ts +34 -12
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +11 -0
- package/dist/lib/types.js.map +3 -3
- package/dist/lib/walk-schemas.d.ts +4 -2
- package/dist/lib/walk-schemas.d.ts.map +1 -1
- package/dist/lib/walk-schemas.js +15 -13
- package/dist/lib/walk-schemas.js.map +2 -2
- package/package.json +17 -6
- package/dist/lib/create-operation.d.ts +0 -28
- package/dist/lib/create-operation.d.ts.map +0 -1
- package/dist/lib/create-operation.js +0 -62
- 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
|
|
5
|
-
"mappings": "AAAA,
|
|
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.split('/').filter(Boolean).at(-1);\n}\n"],
|
|
5
|
+
"mappings": "AAEA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAS3B,SAAS,4BAA4C;AAC1D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,QAAQ,EAAE,MAAM,OAAO,GAAG;AAC9B,YAAM,WAAW,MAAM,gCAAgC,MAAM,oBAAI,IAAI,CAAC;AACtE,iBAAW,EAAE,KAAK,MAAM,KAAK,UAAU;AACrC,eAAO;AAAA,UACL,MAAM;AAAA,UACN,UAAU;AAAA,UACV,MAAM;AAAA,UACN,SAAS,yCAAyC,GAAG,KAAK,MAAM,QAAQ,KAAK,IAAI,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,QAChH,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;AAOA,eAAsB,gCACpB,MACA,WACA;AACA,QAAM,eAAe,oBAAoB,IAAI;AAC7C,QAAM,OAAO,IAAI;AAAA,IACf,aACG,QAAQ,CAAC,gBAAgB,OAAO,KAAK,WAAW,CAAC,EACjD;AAAA,MACC,CAAC,QAAQ,CAAC,KAAK,YAAY,kBAAkB,GAAG,KAAK,SAAS,GAAG;AAAA,IAC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WAAW,WACb,MAAM,eAAe,UAAU,MAAM,SAAS,IAC9C;AACJ,MAAI,SAAS,WAAW,YAAY,UAAU,QAAQ,IAAI;AAC1D,MAAI,MAAM,MAAM,GAAG;AACjB,aAAS,UAAU,UAAU,OAAO,IAAI;AAAA,EAC1C;AACA,MAAI,CAAC,iBAAiB,MAAM,GAAG;AAC7B,WAAO,QAAQ;AAAA,MACb,IAAI,MAAM,4CAA4C;AAAA,IACxD;AAAA,EACF;AACA,SAAO;AACT;AAEA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,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
|
}
|
package/dist/lib/processing.d.ts
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
onDiagnostic?: (diagnostic: ProcessingDiagnostic) => void;
|
|
33
|
+
documentPlugins?: readonly DocumentPlugin[];
|
|
34
|
+
irPlugins?: readonly IRPlugin[];
|
|
27
35
|
}
|
|
28
|
-
export interface ProcessingResult {
|
|
29
|
-
spec:
|
|
36
|
+
export interface ProcessingResult<Spec> {
|
|
37
|
+
spec: Spec;
|
|
30
38
|
diagnostics: ProcessingDiagnostic[];
|
|
31
39
|
}
|
|
32
|
-
|
|
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","
|
|
1
|
+
{"version":3,"file":"processing.d.ts","sources":["../../src/lib/processing.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,iBAAiB,EACtB,aAAa,IAAI,YAAY,EAC9B,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,EAAE,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAExE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,4BAA4B,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC;AAE9E,MAAM,WAAW,iBAAiB,CAAC,IAAI;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,iBAAiB,CAAC;IAC3B,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CACJ,UAAU,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,GAC/C,oBAAoB,CAAC;CACzB;AAED,2FAA2F;AAC3F,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E;AAED,yEAAyE;AACzE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,OAAO,EAAE,SAAS,cAAc,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,eAAe,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5C,SAAS,CAAC,EAAE,SAAS,QAAQ,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"}
|
package/dist/lib/processing.js
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;
|
|
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;A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AiB,gBAAgB,eAAe;AAC1D,QAAM,OAAO,mBAAmB,QAAQ;AACxC,QAAM,WAAW,MAAM,WAAW,GAAG;AACrC,OAAK,kBAAkB,IAAI;AAAA,IACzB,SAAS,CAAC,GAAG,iBAAiB,GAAG,SAAS,EAAE,IAAI,CAAC,WAAW,OAAO,IAAI;AAAA,IACvE;AAAA,EACF;AACA,SAAO,EAAE,MAAM,aAAa,IAAI,YAAY;AAC9C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reserved-keywords.d.ts","
|
|
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"}
|
package/dist/lib/sidebar.d.ts
CHANGED
|
@@ -19,9 +19,10 @@ export type CategoryItem = {
|
|
|
19
19
|
items: NavItem[];
|
|
20
20
|
};
|
|
21
21
|
export type SidebarData = CategoryItem[];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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","
|
|
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"}
|
package/dist/lib/sidebar.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
};
|
package/dist/lib/sidebar.js.map
CHANGED
|
@@ -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\
|
|
5
|
-
"mappings": "
|
|
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,KAAK,MAAM;AAC3B,UAAM,aAAa;AAAA,MAAiB;AAAA,MAAM,CAAC,OAAO,cAChD,UAAU,KAAK,SAAS,IAAI,IAAI,IAC5B;AAAA,QACE,IAAI,UAAU;AAAA,QACd,OAAO,UAAU,WAAW,UAAU;AAAA,QACtC,KAAK,GAAG,UAAU,IAAI,IAAI,CAAC,IAAI,UAAU,UAAU,WAAW,CAAC;AAAA,MACjE,IACA;AAAA,IACN,EAAE,OAAO,kBAAkB;AAC3B,QAAI,WAAW,WAAW,GAAG;AAC3B;AAAA,IACF;AACA,UAAM,OAAO,YAAY,KAAK,IAAI;AAClC,QAAI,UAAU,SAAS,IAAI,IAAI;AAC/B,QAAI,CAAC,SAAS;AACZ,gBAAU,OACN;AAAA,QACE,IAAI,UAAU,KAAK,IAAI;AAAA,QACvB,UAAU,KAAK,WAAW,KAAK;AAAA,QAC/B,aAAa,KAAK;AAAA,QAClB,OAAO,CAAC;AAAA,MACV,IACA,EAAE,IAAI,UAAU,KAAK,GAAG,UAAU,OAAO,OAAO,CAAC,EAAE;AACvD,eAAS,IAAI,MAAM,OAAO;AAC1B,cAAQ,KAAK,OAAO;AAAA,IACtB;AACA,YAAQ,MAAM,KAAK;AAAA,MACjB,IAAI,OAAO,WAAW;AAAA,MACtB,OAAO,IAAI,WAAW,IAAI;AAAA,MAC1B,aAAa,IAAI;AAAA,MACjB,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAGA,SAAS,YAAY,KAAgB,MAA8B;AACjE,MAAI;AACJ,QAAM,SAAS,oBAAI,IAAI,CAAC,IAAI,IAAI,CAAC;AACjC,MAAI,SAAS,IAAI;AACjB,SAAO,WAAW,UAAa,CAAC,OAAO,IAAI,MAAM,GAAG;AAClD,UAAM,OAAO,KAAK,IAAI,MAAM;AAC5B,QAAI,CAAC,MAAM;AACT;AAAA,IACF;AACA,WAAO,IAAI,MAAM;AACjB,eAAW;AACX,aAAS,KAAK;AAAA,EAChB;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/tag.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","
|
|
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"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { MediaTypeObject, OperationObject, ParameterObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject,
|
|
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 {
|
|
5
|
-
import type { SidebarData
|
|
6
|
-
|
|
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:
|
|
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
|
|
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' | '
|
|
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']
|
|
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:
|
|
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
|
-
|
|
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
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","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,yBAAyB,EACzB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EACV,uBAAuB,EACvB,eAAe,EACf,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EAC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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
package/dist/lib/types.js.map
CHANGED
|
@@ -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
|
-
|
|
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","
|
|
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"}
|
package/dist/lib/walk-schemas.js
CHANGED
|
@@ -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*
|
|
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
|
|
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
|
|
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
|
|
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
|