@sdk-it/spec 0.46.11 → 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 +4 -1
- package/dist/lib/external-documents.d.ts.map +1 -1
- package/dist/lib/external-documents.js +27 -20
- package/dist/lib/external-documents.js.map +2 -2
- 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 +13 -6
- package/dist/lib/processing-plugins/bundle-external-refs.d.ts.map +1 -1
- package/dist/lib/processing-plugins/bundle-external-refs.js +33 -18
- package/dist/lib/processing-plugins/bundle-external-refs.js.map +2 -2
- 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 +8 -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.map +1 -1
- 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 +58 -38
- 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
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @sdk-it/spec
|
|
|
14
14
|
```typescript
|
|
15
15
|
import { loadSpec, toIR } from '@sdk-it/spec';
|
|
16
16
|
|
|
17
|
-
const spec = await loadSpec('./openapi.yaml');
|
|
17
|
+
const { spec } = await loadSpec('./openapi.yaml');
|
|
18
18
|
const ir = await toIR({
|
|
19
19
|
spec,
|
|
20
20
|
responses: { flattenErrorResponses: true },
|
|
@@ -24,8 +24,12 @@ console.log(ir.paths);
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
`loadSpec` accepts local JSON or YAML paths and HTTP(S) URLs. It also detects
|
|
27
|
-
Postman collections and converts them to OpenAPI.
|
|
28
|
-
|
|
27
|
+
Postman collections and converts them to OpenAPI. When the specification
|
|
28
|
+
refers to other files through `$ref`, `loadSpec` reads those files too. It
|
|
29
|
+
returns `spec`, one document in which every reference is local, and
|
|
30
|
+
`documents`, the URI of each file that it read. The first URI is the location
|
|
31
|
+
that you gave. `toIR` runs the default ordered processing pipeline and returns
|
|
32
|
+
the normalized `IR`.
|
|
29
33
|
|
|
30
34
|
## Add a processing plugin
|
|
31
35
|
|
|
@@ -37,7 +41,7 @@ import {
|
|
|
37
41
|
toIR,
|
|
38
42
|
} from '@sdk-it/spec';
|
|
39
43
|
|
|
40
|
-
const spec = await loadSpec('./openapi.yaml');
|
|
44
|
+
const { spec } = await loadSpec('./openapi.yaml');
|
|
41
45
|
const plugins = createDefaultProcessingPlugins();
|
|
42
46
|
|
|
43
47
|
plugins.splice(-1, 0, {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/finalize-operations.js';
|
|
2
2
|
export * from './lib/find-polymorphic-varients.js';
|
|
3
3
|
export * from './lib/find-unique-schema-name.js';
|
|
4
4
|
export * from './lib/for-each-operation.js';
|
|
@@ -11,6 +11,7 @@ export * from './lib/loaders/load-spec.js';
|
|
|
11
11
|
export * from './lib/loaders/local-loader.js';
|
|
12
12
|
export * from './lib/loaders/remote-loader.js';
|
|
13
13
|
export * from './lib/metadata.js';
|
|
14
|
+
export * from './lib/operation-input.js';
|
|
14
15
|
export * from './lib/options.js';
|
|
15
16
|
export * from './lib/processing-plugins/index.js';
|
|
16
17
|
export * from './lib/processing.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wCAAwC,CAAC;AACvD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./lib/
|
|
1
|
+
export * from "./lib/finalize-operations.js";
|
|
2
2
|
export * from "./lib/find-polymorphic-varients.js";
|
|
3
3
|
export * from "./lib/find-unique-schema-name.js";
|
|
4
4
|
export * from "./lib/for-each-operation.js";
|
|
@@ -11,6 +11,7 @@ export * from "./lib/loaders/load-spec.js";
|
|
|
11
11
|
export * from "./lib/loaders/local-loader.js";
|
|
12
12
|
export * from "./lib/loaders/remote-loader.js";
|
|
13
13
|
export * from "./lib/metadata.js";
|
|
14
|
+
export * from "./lib/operation-input.js";
|
|
14
15
|
export * from "./lib/options.js";
|
|
15
16
|
export * from "./lib/processing-plugins/index.js";
|
|
16
17
|
export * from "./lib/processing.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './lib/
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './lib/finalize-operations.js';\nexport * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/ir.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/local-loader.js';\nexport * from './lib/loaders/remote-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/operation-input.js';\nexport * from './lib/options.js';\nexport * from './lib/processing-plugins/index.js';\nexport * from './lib/processing.js';\nexport * from './lib/overview-docs/overview-errors.js';\nexport * from './lib/overview-docs/types.js';\nexport * from './lib/reserved-keywords.js';\nexport * from './lib/sidebar.js';\nexport * from './lib/tag.js';\nexport * from './lib/types.js';\nexport * from './lib/walk-schemas.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type Documents = Map<string, Promise<unknown>>;
|
|
2
|
+
export declare function loadFile<T>(location: string): Promise<T>;
|
|
3
|
+
export declare function isRemote(location: string): boolean;
|
|
2
4
|
export declare function documentUrl(location: string, base: string | undefined): URL;
|
|
3
5
|
export declare function loadDocument(url: URL, documents: Documents): Promise<unknown>;
|
|
4
6
|
export declare function splitFragment(uri: string): [string, string | undefined];
|
|
5
|
-
export declare function
|
|
7
|
+
export declare function isJsonObject(value: unknown): value is Record<string, unknown>;
|
|
8
|
+
export declare function readPointer(document: unknown, fragment: string): {} | null;
|
|
6
9
|
export declare function availableName(taken: Record<string, unknown>, candidate: string): string;
|
|
7
10
|
//# sourceMappingURL=external-documents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-documents.d.ts","
|
|
1
|
+
{"version":3,"file":"external-documents.d.ts","sources":["../../src/lib/external-documents.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AAEtD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAKxD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,WAGxC;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,OAOrE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,oBAI1D;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAKvE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE7E;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAM9D;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,EAAE,MAAM,UAQlB"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
-
import {
|
|
2
|
+
import { pointerTokens, valueAtPointer } from "@sdk-it/core";
|
|
3
|
+
import { loadLocal } from "./loaders/local-loader.js";
|
|
4
|
+
import { loadRemote } from "./loaders/remote-loader.js";
|
|
5
|
+
function loadFile(location) {
|
|
6
|
+
if (isRemote(location)) {
|
|
7
|
+
return loadRemote(location);
|
|
8
|
+
}
|
|
9
|
+
return loadLocal(location);
|
|
10
|
+
}
|
|
11
|
+
function isRemote(location) {
|
|
12
|
+
const [protocol] = location.split(":");
|
|
13
|
+
return protocol === "http" || protocol === "https";
|
|
14
|
+
}
|
|
3
15
|
function documentUrl(location, base) {
|
|
4
16
|
if (!base && !URL.canParse(location)) {
|
|
5
17
|
throw new Error(
|
|
@@ -9,32 +21,24 @@ function documentUrl(location, base) {
|
|
|
9
21
|
return new URL(location, base);
|
|
10
22
|
}
|
|
11
23
|
function loadDocument(url, documents) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
);
|
|
17
|
-
documents.set(url.href, pending);
|
|
18
|
-
}
|
|
19
|
-
return pending;
|
|
24
|
+
return documents.getOrInsertComputed(
|
|
25
|
+
url.href,
|
|
26
|
+
() => loadFile(url.protocol === "file:" ? fileURLToPath(url) : url.href)
|
|
27
|
+
);
|
|
20
28
|
}
|
|
21
29
|
function splitFragment(uri) {
|
|
22
30
|
const index = uri.indexOf("#");
|
|
23
31
|
return index === -1 ? [uri, void 0] : [uri.slice(0, index), uri.slice(index + 1)];
|
|
24
32
|
}
|
|
33
|
+
function isJsonObject(value) {
|
|
34
|
+
return typeof value === "object" && value !== null;
|
|
35
|
+
}
|
|
25
36
|
function readPointer(document, fragment) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const key = decodeURIComponent(segment).replaceAll("~1", "/").replaceAll("~0", "~");
|
|
32
|
-
if (current === null || typeof current !== "object" || !(key in current)) {
|
|
33
|
-
throw new Error(`no value at pointer #${fragment}`);
|
|
34
|
-
}
|
|
35
|
-
current = current[key];
|
|
37
|
+
const value = valueAtPointer(document, pointerTokens(fragment));
|
|
38
|
+
if (value === void 0) {
|
|
39
|
+
throw new Error(`no value at pointer #${fragment}`);
|
|
36
40
|
}
|
|
37
|
-
return
|
|
41
|
+
return value;
|
|
38
42
|
}
|
|
39
43
|
function availableName(taken, candidate) {
|
|
40
44
|
let name = candidate;
|
|
@@ -47,7 +51,10 @@ function availableName(taken, candidate) {
|
|
|
47
51
|
export {
|
|
48
52
|
availableName,
|
|
49
53
|
documentUrl,
|
|
54
|
+
isJsonObject,
|
|
55
|
+
isRemote,
|
|
50
56
|
loadDocument,
|
|
57
|
+
loadFile,
|
|
51
58
|
readPointer,
|
|
52
59
|
splitFragment
|
|
53
60
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/external-documents.ts"],
|
|
4
|
-
"sourcesContent": ["import { fileURLToPath } from 'node:url';\n\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { fileURLToPath } from 'node:url';\n\nimport { pointerTokens, valueAtPointer } from '@sdk-it/core';\n\nimport { loadLocal } from './loaders/local-loader.js';\nimport { loadRemote } from './loaders/remote-loader.js';\n\nexport type Documents = Map<string, Promise<unknown>>;\n\nexport function loadFile<T>(location: string): Promise<T> {\n if (isRemote(location)) {\n return loadRemote(location);\n }\n return loadLocal(location);\n}\n\nexport function isRemote(location: string) {\n const [protocol] = location.split(':');\n return protocol === 'http' || protocol === 'https';\n}\n\nexport function documentUrl(location: string, base: string | undefined) {\n if (!base && !URL.canParse(location)) {\n throw new Error(\n 'the document declares no $self, so a relative URI has no base to resolve against',\n );\n }\n return new URL(location, base);\n}\n\nexport function loadDocument(url: URL, documents: Documents) {\n return documents.getOrInsertComputed(url.href, () =>\n loadFile(url.protocol === 'file:' ? fileURLToPath(url) : url.href),\n );\n}\n\nexport function 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\nexport function isJsonObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nexport function readPointer(document: unknown, fragment: string) {\n const value = valueAtPointer(document, pointerTokens(fragment));\n if (value === undefined) {\n throw new Error(`no value at pointer #${fragment}`);\n }\n return value;\n}\n\nexport function availableName(\n taken: Record<string, unknown>,\n candidate: string,\n) {\n let name = candidate;\n let suffix = 2;\n while (taken[name]) {\n name = `${candidate}${suffix++}`;\n }\n return name;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,eAAe,sBAAsB;AAE9C,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAIpB,SAAS,SAAY,UAA8B;AACxD,MAAI,SAAS,QAAQ,GAAG;AACtB,WAAO,WAAW,QAAQ;AAAA,EAC5B;AACA,SAAO,UAAU,QAAQ;AAC3B;AAEO,SAAS,SAAS,UAAkB;AACzC,QAAM,CAAC,QAAQ,IAAI,SAAS,MAAM,GAAG;AACrC,SAAO,aAAa,UAAU,aAAa;AAC7C;AAEO,SAAS,YAAY,UAAkB,MAA0B;AACtE,MAAI,CAAC,QAAQ,CAAC,IAAI,SAAS,QAAQ,GAAG;AACpC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,IAAI,IAAI,UAAU,IAAI;AAC/B;AAEO,SAAS,aAAa,KAAU,WAAsB;AAC3D,SAAO,UAAU;AAAA,IAAoB,IAAI;AAAA,IAAM,MAC7C,SAAS,IAAI,aAAa,UAAU,cAAc,GAAG,IAAI,IAAI,IAAI;AAAA,EACnE;AACF;AAEO,SAAS,cAAc,KAA2C;AACvE,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;AAEO,SAAS,aAAa,OAAkD;AAC7E,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEO,SAAS,YAAY,UAAmB,UAAkB;AAC/D,QAAM,QAAQ,eAAe,UAAU,cAAc,QAAQ,CAAC;AAC9D,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,wBAAwB,QAAQ,EAAE;AAAA,EACpD;AACA,SAAO;AACT;AAEO,SAAS,cACd,OACA,WACA;AACA,MAAI,OAAO;AACX,MAAI,SAAS;AACb,SAAO,MAAM,IAAI,GAAG;AAClB,WAAO,GAAG,SAAS,GAAG,QAAQ;AAAA,EAChC;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type IR, type ProcessingDocument } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the IR from a document the document-stage plugins have processed.
|
|
4
|
+
* This is the one place a raw operation becomes a {@link TunedOperationObject};
|
|
5
|
+
* an operation left untuned is a spec processing bug, so it throws.
|
|
6
|
+
*/
|
|
7
|
+
export declare function finalizeOperations(document: ProcessingDocument): IR;
|
|
8
|
+
//# sourceMappingURL=finalize-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize-operations.d.ts","sources":["../../src/lib/finalize-operations.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,EAAE,EAIP,KAAK,kBAAkB,EAKxB,MAAM,YAAY,CAAC;AAMpB;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,EAAE,CAgBnE"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { methods } from "@sdk-it/core/paths.js";
|
|
2
|
+
import { isRef } from "@sdk-it/core/ref.js";
|
|
3
|
+
import { isJsonObject } from "./external-documents.js";
|
|
4
|
+
import {
|
|
5
|
+
responseBodies
|
|
6
|
+
} from "./types.js";
|
|
7
|
+
function isResponseBody(value) {
|
|
8
|
+
return responseBodies.some((body) => body === value);
|
|
9
|
+
}
|
|
10
|
+
function finalizeOperations(document) {
|
|
11
|
+
const paths = {};
|
|
12
|
+
for (const [path, pathItem] of Object.entries(document.paths)) {
|
|
13
|
+
const operations = {};
|
|
14
|
+
for (const method of methods) {
|
|
15
|
+
const operation = pathItem[method];
|
|
16
|
+
if (operation) {
|
|
17
|
+
operations[method] = finalizeOperation(
|
|
18
|
+
`${method.toUpperCase()} ${path}`,
|
|
19
|
+
operation
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
paths[path] = operations;
|
|
24
|
+
}
|
|
25
|
+
return { ...document, paths };
|
|
26
|
+
}
|
|
27
|
+
function untuned(operation, field, problem) {
|
|
28
|
+
return new Error(
|
|
29
|
+
`Spec processing left ${operation} with an untuned ${field}: ${problem}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function finalizeOperation(name, operation) {
|
|
33
|
+
const {
|
|
34
|
+
operationId,
|
|
35
|
+
tags,
|
|
36
|
+
parameters,
|
|
37
|
+
responses,
|
|
38
|
+
requestBody,
|
|
39
|
+
security,
|
|
40
|
+
"x-tool": tool,
|
|
41
|
+
...rest
|
|
42
|
+
} = operation;
|
|
43
|
+
const fnName = operation["x-fn-name"];
|
|
44
|
+
const fnGroup = operation["x-fn-group"];
|
|
45
|
+
if (typeof operationId !== "string") {
|
|
46
|
+
throw untuned(name, "operationId", "it is not a string");
|
|
47
|
+
}
|
|
48
|
+
if (typeof fnName !== "string") {
|
|
49
|
+
throw untuned(name, "x-fn-name", "it is not a string");
|
|
50
|
+
}
|
|
51
|
+
if (typeof fnGroup !== "string") {
|
|
52
|
+
throw untuned(name, "x-fn-group", "it is not a string");
|
|
53
|
+
}
|
|
54
|
+
const [tag] = tags ?? [];
|
|
55
|
+
if (tags?.length !== 1 || tag === void 0) {
|
|
56
|
+
throw untuned(name, "tags", "it does not hold exactly one tag");
|
|
57
|
+
}
|
|
58
|
+
if (!parameters?.every(
|
|
59
|
+
(parameter) => !isRef(parameter)
|
|
60
|
+
)) {
|
|
61
|
+
throw untuned(name, "parameters", "a parameter is missing or a $ref");
|
|
62
|
+
}
|
|
63
|
+
if (!security) {
|
|
64
|
+
throw untuned(name, "security", "it is missing");
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...rest,
|
|
68
|
+
operationId,
|
|
69
|
+
tags: [tag],
|
|
70
|
+
parameters,
|
|
71
|
+
security,
|
|
72
|
+
"x-fn-name": fnName,
|
|
73
|
+
"x-fn-group": fnGroup,
|
|
74
|
+
responses: finalizeResponses(name, responses ?? {}),
|
|
75
|
+
requestBody: finalizeRequestBody(name, requestBody),
|
|
76
|
+
...operationTool(tool)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function operationTool(tool) {
|
|
80
|
+
if (!isJsonObject(tool)) {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
const { name, description } = tool;
|
|
84
|
+
return {
|
|
85
|
+
"x-tool": {
|
|
86
|
+
...typeof name === "string" ? { name } : {},
|
|
87
|
+
...typeof description === "string" ? { description } : {}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function finalizeResponses(name, responses) {
|
|
92
|
+
const tuned = {};
|
|
93
|
+
for (const [status, response] of Object.entries(responses)) {
|
|
94
|
+
const field = `responses.${status}`;
|
|
95
|
+
if (isRef(response)) {
|
|
96
|
+
throw untuned(name, field, "it is a $ref");
|
|
97
|
+
}
|
|
98
|
+
const { content } = response;
|
|
99
|
+
const body = response["x-body"];
|
|
100
|
+
if (!content) {
|
|
101
|
+
throw untuned(name, `${field}.content`, "it is missing");
|
|
102
|
+
}
|
|
103
|
+
if (!isResponseBody(body)) {
|
|
104
|
+
throw untuned(name, `${field}.x-body`, "it is not a response body kind");
|
|
105
|
+
}
|
|
106
|
+
tuned[status] = { ...response, content, "x-body": body };
|
|
107
|
+
}
|
|
108
|
+
return tuned;
|
|
109
|
+
}
|
|
110
|
+
function finalizeRequestBody(name, requestBody) {
|
|
111
|
+
if (!requestBody) {
|
|
112
|
+
throw untuned(name, "requestBody", "it is missing");
|
|
113
|
+
}
|
|
114
|
+
if (isRef(requestBody)) {
|
|
115
|
+
throw untuned(name, "requestBody", "it is a $ref");
|
|
116
|
+
}
|
|
117
|
+
const content = {};
|
|
118
|
+
for (const [contentType, media] of Object.entries(requestBody.content)) {
|
|
119
|
+
const { schema } = media;
|
|
120
|
+
if (!isRef(schema)) {
|
|
121
|
+
throw untuned(
|
|
122
|
+
name,
|
|
123
|
+
`requestBody.content.${contentType}.schema`,
|
|
124
|
+
"it is not a $ref to a request body schema"
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
content[contentType] = { ...media, schema };
|
|
128
|
+
}
|
|
129
|
+
return { ...requestBody, content };
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
finalizeOperations
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=finalize-operations.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/finalize-operations.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n OperationObject,\n ParameterObject,\n ReferenceObject,\n RequestBodyObject,\n ResponseObject,\n} from 'openapi3-ts/oas31';\n\nimport { methods } from '@sdk-it/core/paths.js';\nimport { isRef } from '@sdk-it/core/ref.js';\n\nimport { isJsonObject } from './external-documents.js';\nimport {\n type IR,\n type IRPaths,\n type OperationTool,\n type OurRequestBodyObject,\n type ProcessingDocument,\n type ResponseBody,\n type TunedOperationObject,\n type TunedResponseObject,\n responseBodies,\n} from './types.js';\n\nfunction isResponseBody(value: unknown): value is ResponseBody {\n return responseBodies.some((body) => body === value);\n}\n\n/**\n * Builds the IR from a document the document-stage plugins have processed.\n * This is the one place a raw operation becomes a {@link TunedOperationObject};\n * an operation left untuned is a spec processing bug, so it throws.\n */\nexport function finalizeOperations(document: ProcessingDocument): IR {\n const paths: IRPaths = {};\n for (const [path, pathItem] of Object.entries(document.paths)) {\n const operations: IRPaths[string] = {};\n for (const method of methods) {\n const operation = pathItem[method];\n if (operation) {\n operations[method] = finalizeOperation(\n `${method.toUpperCase()} ${path}`,\n operation,\n );\n }\n }\n paths[path] = operations;\n }\n return { ...document, paths };\n}\n\nfunction untuned(operation: string, field: string, problem: string) {\n return new Error(\n `Spec processing left ${operation} with an untuned ${field}: ${problem}`,\n );\n}\n\nfunction finalizeOperation(\n name: string,\n operation: OperationObject,\n): TunedOperationObject {\n const {\n operationId,\n tags,\n parameters,\n responses,\n requestBody,\n security,\n 'x-tool': tool,\n ...rest\n } = operation;\n const fnName: unknown = operation['x-fn-name'];\n const fnGroup: unknown = operation['x-fn-group'];\n if (typeof operationId !== 'string') {\n throw untuned(name, 'operationId', 'it is not a string');\n }\n if (typeof fnName !== 'string') {\n throw untuned(name, 'x-fn-name', 'it is not a string');\n }\n if (typeof fnGroup !== 'string') {\n throw untuned(name, 'x-fn-group', 'it is not a string');\n }\n const [tag] = tags ?? [];\n if (tags?.length !== 1 || tag === undefined) {\n throw untuned(name, 'tags', 'it does not hold exactly one tag');\n }\n if (\n !parameters?.every(\n (parameter): parameter is ParameterObject => !isRef(parameter),\n )\n ) {\n throw untuned(name, 'parameters', 'a parameter is missing or a $ref');\n }\n if (!security) {\n throw untuned(name, 'security', 'it is missing');\n }\n return {\n ...rest,\n operationId,\n tags: [tag],\n parameters,\n security,\n 'x-fn-name': fnName,\n 'x-fn-group': fnGroup,\n responses: finalizeResponses(name, responses ?? {}),\n requestBody: finalizeRequestBody(name, requestBody),\n ...operationTool(tool),\n };\n}\n\nfunction operationTool(tool: unknown): { 'x-tool'?: OperationTool } {\n if (!isJsonObject(tool)) {\n return {};\n }\n const { name, description } = tool;\n return {\n 'x-tool': {\n ...(typeof name === 'string' ? { name } : {}),\n ...(typeof description === 'string' ? { description } : {}),\n },\n };\n}\n\nfunction finalizeResponses(\n name: string,\n responses: Record<string, ResponseObject | ReferenceObject>,\n) {\n const tuned: Record<string, TunedResponseObject> = {};\n for (const [status, response] of Object.entries(responses)) {\n const field = `responses.${status}`;\n if (isRef(response)) {\n throw untuned(name, field, 'it is a $ref');\n }\n const { content } = response;\n const body: unknown = response['x-body'];\n if (!content) {\n throw untuned(name, `${field}.content`, 'it is missing');\n }\n if (!isResponseBody(body)) {\n throw untuned(name, `${field}.x-body`, 'it is not a response body kind');\n }\n tuned[status] = { ...response, content, 'x-body': body };\n }\n return tuned;\n}\n\nfunction finalizeRequestBody(\n name: string,\n requestBody: RequestBodyObject | ReferenceObject | undefined,\n): OurRequestBodyObject {\n if (!requestBody) {\n throw untuned(name, 'requestBody', 'it is missing');\n }\n if (isRef(requestBody)) {\n throw untuned(name, 'requestBody', 'it is a $ref');\n }\n const content: OurRequestBodyObject['content'] = {};\n for (const [contentType, media] of Object.entries(requestBody.content)) {\n const { schema } = media;\n if (!isRef(schema)) {\n throw untuned(\n name,\n `requestBody.content.${contentType}.schema`,\n 'it is not a $ref to a request body schema',\n );\n }\n content[contentType] = { ...media, schema };\n }\n return { ...requestBody, content };\n}\n"],
|
|
5
|
+
"mappings": "AAQA,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,SAAS,oBAAoB;AAC7B;AAAA,EASE;AAAA,OACK;AAEP,SAAS,eAAe,OAAuC;AAC7D,SAAO,eAAe,KAAK,CAAC,SAAS,SAAS,KAAK;AACrD;AAOO,SAAS,mBAAmB,UAAkC;AACnE,QAAM,QAAiB,CAAC;AACxB,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,SAAS,KAAK,GAAG;AAC7D,UAAM,aAA8B,CAAC;AACrC,eAAW,UAAU,SAAS;AAC5B,YAAM,YAAY,SAAS,MAAM;AACjC,UAAI,WAAW;AACb,mBAAW,MAAM,IAAI;AAAA,UACnB,GAAG,OAAO,YAAY,CAAC,IAAI,IAAI;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,UAAM,IAAI,IAAI;AAAA,EAChB;AACA,SAAO,EAAE,GAAG,UAAU,MAAM;AAC9B;AAEA,SAAS,QAAQ,WAAmB,OAAe,SAAiB;AAClE,SAAO,IAAI;AAAA,IACT,wBAAwB,SAAS,oBAAoB,KAAK,KAAK,OAAO;AAAA,EACxE;AACF;AAEA,SAAS,kBACP,MACA,WACsB;AACtB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,SAAkB,UAAU,WAAW;AAC7C,QAAM,UAAmB,UAAU,YAAY;AAC/C,MAAI,OAAO,gBAAgB,UAAU;AACnC,UAAM,QAAQ,MAAM,eAAe,oBAAoB;AAAA,EACzD;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,QAAQ,MAAM,aAAa,oBAAoB;AAAA,EACvD;AACA,M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AQ,IAAI;AACpB,UAAM,OAAgB,SAAS,QAAQ;AACvC,QAAI,CAAC,SAAS;AACZ,YAAM,QAAQ,MAAM,GAAG,KAAK,YAAY,eAAe;AAAA,IACzD;AACA,QAAI,CAAC,eAAe,IAAI,GAAG;AACzB,YAAM,QAAQ,MAAM,GAAG,KAAK,WAAW,gCAAgC;AAAA,IACzE;AACA,UAAM,MAAM,IAAI,EAAE,GAAG,UAAU,SAAS,UAAU,KAAK;AAAA,EACzD;AACA,SAAO;AACT;AAEA,SAAS,oBACP,MACA,aACsB;AACtB,MAAI,CAAC,aAAa;AAChB,UAAM,QAAQ,MAAM,eAAe,eAAe;AAAA,EACpD;AACA,MAAI,MAAM,WAAW,GAAG;AACtB,UAAM,QAAQ,MAAM,eAAe,cAAc;AAAA,EACnD;AACA,QAAM,UAA2C,CAAC;AAClD,aAAW,CAAC,aAAa,KAAK,KAAK,OAAO,QAAQ,YAAY,OAAO,GAAG;AACtE,UAAM,EAAE,OAAO,IAAI;AACnB,QAAI,CAAC,MAAM,MAAM,GAAG;AAClB,YAAM;AAAA,QACJ;AAAA,QACA,uBAAuB,WAAW;AAAA,QAClC;AAAA,MACF;AAAA,IACF;AACA,YAAQ,WAAW,IAAI,EAAE,GAAG,OAAO,OAAO;AAAA,EAC5C;AACA,SAAO,EAAE,GAAG,aAAa,QAAQ;AACnC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-polymorphic-varients.d.ts","
|
|
1
|
+
{"version":3,"file":"find-polymorphic-varients.d.ts","sources":["../../src/lib/find-polymorphic-varients.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AA0EF,wBAAgB,YAAY,CAC1B,IAAI,EAAE,EAAE,EACR,OAAO,EAAE,CAAC,YAAY,GAAG,eAAe,CAAC,EAAE,GAC1C,OAAO,EAAE,CA+PX;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,EAAE,EACR,OAAO,EAAE,CAAC,YAAY,GAAG,eAAe,CAAC,EAAE,GAC1C,OAAO,EAAE,CAQX"}
|
|
@@ -126,7 +126,7 @@ function findVarients(spec, schemas) {
|
|
|
126
126
|
varients.push({ name: "any", type: "array", position });
|
|
127
127
|
continue;
|
|
128
128
|
}
|
|
129
|
-
const [type] = coerceTypes(items);
|
|
129
|
+
const [type] = isRef(items) ? [] : coerceTypes(items);
|
|
130
130
|
if (type === "string") {
|
|
131
131
|
varients.push({
|
|
132
132
|
name: "textList",
|
|
@@ -213,7 +213,8 @@ function findVarients(spec, schemas) {
|
|
|
213
213
|
}
|
|
214
214
|
for (const key of ["properties", "x-properties"]) {
|
|
215
215
|
if (!schema[key]) continue;
|
|
216
|
-
const
|
|
216
|
+
const entries = Object.entries(schema[key]);
|
|
217
|
+
const list = entries.map(([name, schemaOrRef]) => {
|
|
217
218
|
const schema2 = resolveRef(spec, schemaOrRef);
|
|
218
219
|
name = schema2.const ?? schema2.enum?.[0] ?? name;
|
|
219
220
|
if (schema2.type === "string") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/find-polymorphic-varients.ts"],
|
|
4
|
-
"sourcesContent": ["import { groupBy, uniqBy } from 'lodash-es';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport { camelcase, isEmpty, isRef, resolveRef } from '@sdk-it/core';\n\nimport { coerceTypes } from './is.js';\nimport type { IR } from './types.js';\n\nexport type Varient = {\n name: string;\n type: string;\n position: number;\n priority?: number;\n description?: string;\n source?: string;\n static?: boolean;\n subtype?: SchemaObjectType;\n};\n\nconst groupSchemasByType = (\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n) => {\n const groups = schemas.reduce<\n Partial<{\n [\n K in SchemaObjectType | '$ref' | 'oneOf' | 'anyOf'\n ]: K extends SchemaObjectType\n ? { schema: SchemaObject; position: number }[]\n : K extends 'oneOf' | 'anyOf'\n ? { schema: (SchemaObject | ReferenceObject)[]; position: number }[]\n : { schema: ReferenceObject; position: number }[];\n }>\n >((acc, schema, index) => {\n if (isRef(schema)) {\n const referenced = resolveRef<SchemaObject>(spec, schema);\n const [type] = coerceTypes(referenced, false);\n acc[type] ??= [];\n acc[type].push({ schema: referenced, position: index });\n return acc;\n }\n\n if (isRef(schema.items)) {\n const referenced = resolveRef<SchemaObject>(spec, schema.items);\n acc.array ??= [];\n acc.array.push({\n schema: { ...schema, items: referenced },\n position: index,\n });\n return acc;\n }\n if (schema.oneOf) {\n acc['oneOf'] ??= [];\n acc['oneOf'].push({ schema: schema.oneOf, position: index });\n return acc;\n }\n if (schema.anyOf) {\n acc['oneOf'] ??= [];\n acc['oneOf'].push({ schema: schema.anyOf, position: index });\n return acc;\n }\n if (schema.const) {\n switch (typeof schema.const) {\n case 'string':\n acc.string ??= [];\n acc.string.push({ schema, position: index });\n return acc;\n case 'number':\n acc.number ??= [];\n acc.number.push({ schema, position: index });\n return acc;\n case 'boolean':\n acc.boolean ??= [];\n acc.boolean.push({ schema, position: index });\n return acc;\n default:\n throw new Error(\n `Unsupported const type: ${typeof schema.const} for ${schema.const}`,\n );\n }\n }\n\n const [type] = coerceTypes(schema, false);\n acc[type] ??= [];\n acc[type].push({ schema, position: index });\n return acc;\n }, {});\n\n return groups;\n};\n\nexport function findVarients(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n): Varient[] {\n let varients: Varient[] = [];\n const schemasByType = groupSchemasByType(spec, schemas);\n if (!isEmpty(schemasByType.string)) {\n for (const { schema, position } of schemasByType.string) {\n if (schema.const !== undefined) {\n varients.push({\n name: schema.const || 'empty',\n type: 'string',\n position,\n priority: 100 - varients.length,\n });\n continue;\n }\n\n if (schema.format) {\n varients.push({\n name: camelcase(schema.format),\n type: 'string',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n\n // if (!isEmpty(schema.enum)) {\n // for (const enumValue of schema.enum) {\n // if (enumValue === '') {\n // varients.push({\n // name: 'empty',\n // type: 'string',\n // position,\n // priority: 80 - varients.length,\n // });\n // continue;\n // }\n // varients.push({\n // name: enumValue,\n // type: 'string',\n // position,\n // priority: 80 - varients.length,\n // });\n // }\n // continue;\n // }\n\n varients.push({ name: 'text', type: 'string', position });\n }\n varients = uniqBy(varients, (it) => it.name);\n }\n\n if (!isEmpty(schemasByType.number) || !isEmpty(schemasByType.integer)) {\n const schemas = [\n ...(schemasByType.number ?? []),\n ...(schemasByType.integer ?? []),\n ];\n for (const { schema, position } of schemas) {\n if (schema.format === 'int64') {\n varients.push({\n name: 'integer',\n type: 'number',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n if (schema.format === 'float') {\n varients.push({\n name: 'float',\n type: 'number',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n if (schema.format === 'double') {\n varients.push({\n name: 'double',\n type: 'number',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n varients.push({ name: 'number', type: 'number', position });\n }\n }\n\n if (!isEmpty(schemasByType.array)) {\n for (const { schema, position } of schemasByType.array) {\n const items = schema.items;\n if (!items) {\n varients.push({ name: 'any', type: 'array', position });\n continue;\n }\n const [type] = coerceTypes(items as SchemaObject);\n if (type === 'string') {\n varients.push({\n name: 'textList',\n type: 'array',\n subtype: 'string',\n position,\n });\n continue;\n }\n if (type === 'number') {\n varients.push({\n name: 'numList',\n type: 'array',\n subtype: 'number',\n position,\n });\n continue;\n }\n if (type === 'integer') {\n varients.push({\n name: 'intList',\n type: 'array',\n subtype: 'integer',\n position,\n });\n continue;\n }\n if (type === 'object') {\n const subvarients = findVarients(spec, [items]);\n for (const subvarient of subvarients) {\n varients.push({\n ...subvarient,\n type: 'array',\n position,\n });\n }\n continue;\n }\n if (type === 'array') {\n const subvarients = findVarients(spec, [items]);\n for (const subvarient of subvarients) {\n varients.push({\n ...subvarient,\n name: `${subvarient.name}Matrix`,\n type: 'array',\n position,\n });\n }\n continue;\n }\n varients.push({ name: 'list', type: 'array', position });\n }\n }\n\n if (!isEmpty(schemasByType.$ref)) {\n const subvarients = findVarients(\n spec,\n schemasByType.$ref.map((it) => resolveRef(spec, it.schema)),\n );\n varients.push(\n ...subvarients.map((it) => ({\n ...it,\n })),\n );\n }\n\n if (!isEmpty(schemasByType.oneOf)) {\n for (const { schema, position } of schemasByType.oneOf) {\n const subvarients = findVarients(spec, schema);\n varients.push(\n ...subvarients.map((it) => ({\n ...it,\n position,\n })),\n );\n }\n }\n\n const matrix: Varient[][] = [];\n\n for (const { schema, position } of schemasByType.object ?? []) {\n if (schema.additionalProperties) {\n varients.push({ name: 'object', type: 'object', position });\n continue;\n }\n if (isEmpty({ ...schema.properties, ...schema['x-properties'] })) {\n continue;\n }\n\n for (const key of ['properties', 'x-properties'] as const) {\n if (!schema[key]) continue;\n const list = (\n Object.entries(schema[key]) as [\n string,\n SchemaObject | ReferenceObject,\n ][]\n ).map(([name, schemaOrRef]) => {\n const schema = resolveRef<SchemaObject>(spec, schemaOrRef);\n name = schema.const ?? schema.enum?.[0] ?? name;\n if (schema.type === 'string') {\n return {\n static: true,\n subtype: 'string',\n source: name,\n name: name,\n type: 'object',\n position,\n } satisfies Varient;\n }\n return {\n subtype: 'string',\n source: name,\n name: name,\n type: 'object',\n position,\n } satisfies Varient;\n });\n matrix.push([...new Set(list)].sort((a) => (a.static ? -1 : 1)));\n }\n if (matrix.length === 0) {\n throw new Error(\n 'No valid objects found. Please check your OpenAPI spec.',\n );\n }\n }\n\n for (const row of matrix) {\n for (const prop of row) {\n // check if this prop is unique across all rows\n const isUnique = matrix.every((it) =>\n it === row ? true : !it.some((p) => p.name === prop.name),\n );\n if (isUnique) {\n varients.push(prop);\n break;\n }\n }\n }\n\n // Sort all variants by priority (highest first), then by original position\n return varients.sort((a, b) => {\n const aHasPriority = a.priority !== undefined;\n const bHasPriority = b.priority !== undefined;\n\n if (aHasPriority && bHasPriority) {\n // Both have priority\n if (a.priority !== b.priority) {\n return b.priority! - a.priority!; // Higher priority first\n }\n // Priorities are equal, sort by original position as a tie-breaker\n return a.position - b.position;\n } else if (aHasPriority) {\n return -1; // 'a' comes first\n } else if (bHasPriority) {\n return 1; // 'b' comes first\n } else {\n // Neither has priority. Keep their relative order from before this sort.\n // This relies on a stable sort (standard in ES2019+).\n // Returning 0 preserves the order in which they were added to the 'varients' array.\n return 0;\n }\n });\n}\n\nexport function findPolymorphicVarients(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n): Varient[] {\n const varients = findVarients(spec, schemas);\n // prepend '-' to prevent key sortings\n return Object.values(groupBy(varients, (it) => '-' + it.position)).map(\n (group) => {\n return (group ?? [])[0];\n },\n );\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,cAAc;AAOhC,SAAS,WAAW,SAAS,OAAO,kBAAkB;AAEtD,SAAS,mBAAmB;AAc5B,MAAM,qBAAqB,CACzB,MACA,YACG;AACH,QAAM,SAAS,QAAQ,OAUrB,CAAC,KAAK,QAAQ,UAAU;AACxB,QAAI,MAAM,MAAM,GAAG;AACjB,YAAM,aAAa,WAAyB,MAAM,MAAM;AACxD,YAAM,CAACA,KAAI,IAAI,YAAY,YAAY,KAAK;AAC5C,UAAIA,KAAI,MAAM,CAAC;AACf,UAAIA,KAAI,EAAE,KAAK,EAA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AK,SAAS;AAAA,QAC1B,CAAC;AACD;AAAA,MACF;AACA,UAAI,OAAO,WAAW,UAAU;AAC9B,iBAAS,KAAK;AAAA,UACZ,MAAM;AAAA,UACN,MAAM;AAAA,UACN;AAAA,UACA,UAAU,KAAK,SAAS;AAAA,QAC1B,CAAC;AACD;AAAA,MACF;AACA,eAAS,KAAK,EAAE,MAAM,UAAU,MAAM,UAAU,SAAS,CAAC;AAAA,IAC5D;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,cAAc,KAAK,GAAG;AACjC,eAAW,EAAE,QAAQ,SAAS,KAAK,cAAc,OAAO;AACtD,YAAM,QAAQ,OAAO;AACrB,UAAI,CAAC,OAAO;AACV,iBAAS,KAAK,EAAE,MAAM,OAAO,MAAM,SAAS,SAAS,CAAC;AACtD;AAAA,MACF;AACA,YAAM,CAAC,IAAI,IAAI,YAAY,
|
|
4
|
+
"sourcesContent": ["import { groupBy, uniqBy } from 'lodash-es';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport { camelcase, isEmpty, isRef, resolveRef } from '@sdk-it/core';\n\nimport { coerceTypes } from './is.js';\nimport type { IR } from './types.js';\n\nexport type Varient = {\n name: string;\n type: string;\n position: number;\n priority?: number;\n description?: string;\n source?: string;\n static?: boolean;\n subtype?: SchemaObjectType;\n};\n\nconst groupSchemasByType = (\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n) => {\n const groups = schemas.reduce<\n Partial<{\n [\n K in SchemaObjectType | '$ref' | 'oneOf' | 'anyOf'\n ]: K extends SchemaObjectType\n ? { schema: SchemaObject; position: number }[]\n : K extends 'oneOf' | 'anyOf'\n ? { schema: (SchemaObject | ReferenceObject)[]; position: number }[]\n : { schema: ReferenceObject; position: number }[];\n }>\n >((acc, schema, index) => {\n if (isRef(schema)) {\n const referenced = resolveRef<SchemaObject>(spec, schema);\n const [type] = coerceTypes(referenced, false);\n acc[type] ??= [];\n acc[type].push({ schema: referenced, position: index });\n return acc;\n }\n\n if (isRef(schema.items)) {\n const referenced = resolveRef<SchemaObject>(spec, schema.items);\n acc.array ??= [];\n acc.array.push({\n schema: { ...schema, items: referenced },\n position: index,\n });\n return acc;\n }\n if (schema.oneOf) {\n acc['oneOf'] ??= [];\n acc['oneOf'].push({ schema: schema.oneOf, position: index });\n return acc;\n }\n if (schema.anyOf) {\n acc['oneOf'] ??= [];\n acc['oneOf'].push({ schema: schema.anyOf, position: index });\n return acc;\n }\n if (schema.const) {\n switch (typeof schema.const) {\n case 'string':\n acc.string ??= [];\n acc.string.push({ schema, position: index });\n return acc;\n case 'number':\n acc.number ??= [];\n acc.number.push({ schema, position: index });\n return acc;\n case 'boolean':\n acc.boolean ??= [];\n acc.boolean.push({ schema, position: index });\n return acc;\n default:\n throw new Error(\n `Unsupported const type: ${typeof schema.const} for ${schema.const}`,\n );\n }\n }\n\n const [type] = coerceTypes(schema, false);\n acc[type] ??= [];\n acc[type].push({ schema, position: index });\n return acc;\n }, {});\n\n return groups;\n};\n\nexport function findVarients(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n): Varient[] {\n let varients: Varient[] = [];\n const schemasByType = groupSchemasByType(spec, schemas);\n if (!isEmpty(schemasByType.string)) {\n for (const { schema, position } of schemasByType.string) {\n if (schema.const !== undefined) {\n varients.push({\n name: schema.const || 'empty',\n type: 'string',\n position,\n priority: 100 - varients.length,\n });\n continue;\n }\n\n if (schema.format) {\n varients.push({\n name: camelcase(schema.format),\n type: 'string',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n\n // if (!isEmpty(schema.enum)) {\n // for (const enumValue of schema.enum) {\n // if (enumValue === '') {\n // varients.push({\n // name: 'empty',\n // type: 'string',\n // position,\n // priority: 80 - varients.length,\n // });\n // continue;\n // }\n // varients.push({\n // name: enumValue,\n // type: 'string',\n // position,\n // priority: 80 - varients.length,\n // });\n // }\n // continue;\n // }\n\n varients.push({ name: 'text', type: 'string', position });\n }\n varients = uniqBy(varients, (it) => it.name);\n }\n\n if (!isEmpty(schemasByType.number) || !isEmpty(schemasByType.integer)) {\n const schemas = [\n ...(schemasByType.number ?? []),\n ...(schemasByType.integer ?? []),\n ];\n for (const { schema, position } of schemas) {\n if (schema.format === 'int64') {\n varients.push({\n name: 'integer',\n type: 'number',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n if (schema.format === 'float') {\n varients.push({\n name: 'float',\n type: 'number',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n if (schema.format === 'double') {\n varients.push({\n name: 'double',\n type: 'number',\n position,\n priority: 90 - varients.length,\n });\n continue;\n }\n varients.push({ name: 'number', type: 'number', position });\n }\n }\n\n if (!isEmpty(schemasByType.array)) {\n for (const { schema, position } of schemasByType.array) {\n const items = schema.items;\n if (!items) {\n varients.push({ name: 'any', type: 'array', position });\n continue;\n }\n const [type] = isRef(items) ? [] : coerceTypes(items);\n if (type === 'string') {\n varients.push({\n name: 'textList',\n type: 'array',\n subtype: 'string',\n position,\n });\n continue;\n }\n if (type === 'number') {\n varients.push({\n name: 'numList',\n type: 'array',\n subtype: 'number',\n position,\n });\n continue;\n }\n if (type === 'integer') {\n varients.push({\n name: 'intList',\n type: 'array',\n subtype: 'integer',\n position,\n });\n continue;\n }\n if (type === 'object') {\n const subvarients = findVarients(spec, [items]);\n for (const subvarient of subvarients) {\n varients.push({\n ...subvarient,\n type: 'array',\n position,\n });\n }\n continue;\n }\n if (type === 'array') {\n const subvarients = findVarients(spec, [items]);\n for (const subvarient of subvarients) {\n varients.push({\n ...subvarient,\n name: `${subvarient.name}Matrix`,\n type: 'array',\n position,\n });\n }\n continue;\n }\n varients.push({ name: 'list', type: 'array', position });\n }\n }\n\n if (!isEmpty(schemasByType.$ref)) {\n const subvarients = findVarients(\n spec,\n schemasByType.$ref.map((it) => resolveRef(spec, it.schema)),\n );\n varients.push(\n ...subvarients.map((it) => ({\n ...it,\n })),\n );\n }\n\n if (!isEmpty(schemasByType.oneOf)) {\n for (const { schema, position } of schemasByType.oneOf) {\n const subvarients = findVarients(spec, schema);\n varients.push(\n ...subvarients.map((it) => ({\n ...it,\n position,\n })),\n );\n }\n }\n\n const matrix: Varient[][] = [];\n\n for (const { schema, position } of schemasByType.object ?? []) {\n if (schema.additionalProperties) {\n varients.push({ name: 'object', type: 'object', position });\n continue;\n }\n if (isEmpty({ ...schema.properties, ...schema['x-properties'] })) {\n continue;\n }\n\n for (const key of ['properties', 'x-properties'] as const) {\n if (!schema[key]) continue;\n const entries: [string, SchemaObject | ReferenceObject][] =\n Object.entries(schema[key]);\n const list = entries.map(([name, schemaOrRef]) => {\n const schema = resolveRef<SchemaObject>(spec, schemaOrRef);\n name = schema.const ?? schema.enum?.[0] ?? name;\n if (schema.type === 'string') {\n return {\n static: true,\n subtype: 'string',\n source: name,\n name: name,\n type: 'object',\n position,\n } satisfies Varient;\n }\n return {\n subtype: 'string',\n source: name,\n name: name,\n type: 'object',\n position,\n } satisfies Varient;\n });\n matrix.push([...new Set(list)].sort((a) => (a.static ? -1 : 1)));\n }\n if (matrix.length === 0) {\n throw new Error(\n 'No valid objects found. Please check your OpenAPI spec.',\n );\n }\n }\n\n for (const row of matrix) {\n for (const prop of row) {\n // check if this prop is unique across all rows\n const isUnique = matrix.every((it) =>\n it === row ? true : !it.some((p) => p.name === prop.name),\n );\n if (isUnique) {\n varients.push(prop);\n break;\n }\n }\n }\n\n // Sort all variants by priority (highest first), then by original position\n return varients.sort((a, b) => {\n const aHasPriority = a.priority !== undefined;\n const bHasPriority = b.priority !== undefined;\n\n if (aHasPriority && bHasPriority) {\n // Both have priority\n if (a.priority !== b.priority) {\n return b.priority! - a.priority!; // Higher priority first\n }\n // Priorities are equal, sort by original position as a tie-breaker\n return a.position - b.position;\n } else if (aHasPriority) {\n return -1; // 'a' comes first\n } else if (bHasPriority) {\n return 1; // 'b' comes first\n } else {\n // Neither has priority. Keep their relative order from before this sort.\n // This relies on a stable sort (standard in ES2019+).\n // Returning 0 preserves the order in which they were added to the 'varients' array.\n return 0;\n }\n });\n}\n\nexport function findPolymorphicVarients(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n): Varient[] {\n const varients = findVarients(spec, schemas);\n // prepend '-' to prevent key sortings\n return Object.values(groupBy(varients, (it) => '-' + it.position)).map(\n (group) => {\n return (group ?? [])[0];\n },\n );\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,cAAc;AAOhC,SAAS,WAAW,SAAS,OAAO,kBAAkB;AAEtD,SAAS,mBAAmB;AAc5B,MAAM,qBAAqB,CACzB,MACA,YACG;AACH,QAAM,SAAS,QAAQ,OAUrB,CAAC,KAAK,QAAQ,UAAU;AACxB,QAAI,MAAM,MAAM,GAAG;AACjB,YAAM,aAAa,WAAyB,MAAM,MAAM;AACxD,YAAM,CAACA,KAAI,IAAI,YAAY,YAAY,KAAK;AAC5C,UAAIA,KAAI,MAAM,CAAC;AACf,UAAIA,KAAI,EAAE,KAAK,EAAE,QAAQ,YAAY,UAAU,MAAM,CAAC;AACtD,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,OAAO,KAAK,GAAG;AACvB,YAAM,aAAa,WAAyB,MAAM,OAAO,KAAK;AAC9D,UAAI,UAAU,CAAC;AACf,UAAI,MAAM,KAAK;AAAA,QACb,QAAQ,EAAE,GAAG,QAAQ,OAAO,WAAW;AAAA,QACvC,UAAU;AAAA,MACZ,CAAC;AACD,aAAO;AAAA,IACT;AACA,QAAI,OAAO,OAAO;AAChB,UAAI,OAAO,MAAM,CAAC;AAClB,UAAI,OAAO,EAAE,KAAK,EAAE,QAAQ,OAAO,OAAO,UAAU,MAAM,CAAC;AAC3D,aAAO;AAAA,IACT;AACA,QAAI,OAAO,OAAO;AAChB,UAAI,OAAO,MAAM,CAAC;AAClB,UAAI,OAAO,EAAE,KAAK,EAAE,QAAQ,OAAO,OAAO,UAAU,MAAM,CAAC;AAC3D,aAAO;AAAA,IACT;AACA,QAAI,OAAO,OAAO;AAChB,cAAQ,OAAO,O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ACF;AAEA,aAAW,OAAO,QAAQ;AACxB,eAAW,QAAQ,KAAK;AAEtB,YAAM,WAAW,OAAO;AAAA,QAAM,CAAC,OAC7B,OAAO,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI;AAAA,MAC1D;AACA,UAAI,UAAU;AACZ,iBAAS,KAAK,IAAI;AAClB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,SAAO,SAAS,KAAK,CAAC,GAAG,MAAM;AAC7B,UAAM,eAAe,EAAE,aAAa;AACpC,UAAM,eAAe,EAAE,aAAa;AAEpC,QAAI,gBAAgB,cAAc;AAEhC,UAAI,EAAE,aAAa,EAAE,UAAU;AAC7B,eAAO,EAAE,WAAY,EAAE;AAAA,MACzB;AAEA,aAAO,EAAE,WAAW,EAAE;AAAA,IACxB,WAAW,cAAc;AACvB,aAAO;AAAA,IACT,WAAW,cAAc;AACvB,aAAO;AAAA,IACT,OAAO;AAIL,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAEO,SAAS,wBACd,MACA,SACW;AACX,QAAM,WAAW,aAAa,MAAM,OAAO;AAE3C,SAAO,OAAO,OAAO,QAAQ,UAAU,CAAC,OAAO,MAAM,GAAG,QAAQ,CAAC,EAAE;AAAA,IACjE,CAAC,UAAU;AACT,cAAQ,SAAS,CAAC,GAAG,CAAC;AAAA,IACxB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["type", "schemas", "schema"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-unique-schema-name.d.ts","
|
|
1
|
+
{"version":3,"file":"find-unique-schema-name.d.ts","sources":["../../src/lib/find-unique-schema-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAA8B,MAAM,cAAc,CAAC;AAIhF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,MAAM,EACnB,mBAAmB,EAAE,MAAM,EAAE,EAC7B,QAAQ,CAAC,EAAE,MAAM,UAUlB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OperationObject, PathItemObject } from 'openapi3-ts/oas31';
|
|
2
2
|
import { type Method } from '@sdk-it/core/paths.js';
|
|
3
|
-
import type { IR, OperationEntry, TunedOperationObject } from './types.js';
|
|
3
|
+
import type { IR, OperationEntry, ProcessingDocument, TunedOperationObject } from './types.js';
|
|
4
4
|
export interface IteratedOperation {
|
|
5
5
|
entry: Omit<OperationEntry, 'method' | 'tag'> & {
|
|
6
6
|
method: Method;
|
|
@@ -9,6 +9,7 @@ export interface IteratedOperation {
|
|
|
9
9
|
operation: OperationObject;
|
|
10
10
|
pathItem: PathItemObject;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
/** Iterates the raw operations a document-stage plugin rewrites. */
|
|
13
|
+
export declare function iterateOperations(spec: Pick<ProcessingDocument, 'paths'>): Generator<IteratedOperation>;
|
|
13
14
|
export declare function forEachOperation<T>(spec: IR, callback: (entry: OperationEntry, operation: TunedOperationObject) => T): T[];
|
|
14
15
|
//# sourceMappingURL=for-each-operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"for-each-operation.d.ts","
|
|
1
|
+
{"version":3,"file":"for-each-operation.d.ts","sources":["../../src/lib/for-each-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,uBAAuB,CAAC;AAE7D,OAAO,KAAK,EACV,EAAE,EACF,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,KAAK,CAAC,GAAG;QAC9C,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE,eAAe,CAAC;IAC3B,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,oEAAoE;AACpE,wBAAiB,iBAAiB,CAChC,IAAI,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,GACtC,SAAS,CAAC,iBAAiB,CAAC,CAmB9B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,EAAE,EACR,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,oBAAoB,KAAK,CAAC,OAcxE"}
|
|
@@ -20,10 +20,15 @@ function* iterateOperations(spec) {
|
|
|
20
20
|
}
|
|
21
21
|
function forEachOperation(spec, callback) {
|
|
22
22
|
const result = [];
|
|
23
|
-
for (const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
24
|
+
for (const method of methods) {
|
|
25
|
+
const operation = pathItem[method];
|
|
26
|
+
if (!operation) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const [tag] = operation.tags;
|
|
30
|
+
result.push(callback({ method, path, tag }, operation));
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
return result;
|
|
29
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/for-each-operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OperationObject, PathItemObject } from 'openapi3-ts/oas31';\n\nimport { type Method, methods } from '@sdk-it/core/paths.js';\n\nimport type {
|
|
5
|
-
"mappings": "AAEA,SAAsB,eAAe;
|
|
4
|
+
"sourcesContent": ["import type { OperationObject, PathItemObject } from 'openapi3-ts/oas31';\n\nimport { type Method, methods } from '@sdk-it/core/paths.js';\n\nimport type {\n IR,\n OperationEntry,\n ProcessingDocument,\n TunedOperationObject,\n} from './types.js';\n\nexport interface IteratedOperation {\n entry: Omit<OperationEntry, 'method' | 'tag'> & {\n method: Method;\n tag?: string;\n };\n operation: OperationObject;\n pathItem: PathItemObject;\n}\n\n/** Iterates the raw operations a document-stage plugin rewrites. */\nexport function* iterateOperations(\n spec: Pick<ProcessingDocument, 'paths'>,\n): Generator<IteratedOperation> {\n for (const [path, pathItem] of Object.entries(spec.paths)) {\n for (const method of methods) {\n const operation = pathItem[method];\n if (!operation) {\n continue;\n }\n\n yield {\n entry: {\n method,\n path,\n tag: operation.tags?.[0],\n },\n operation,\n pathItem,\n };\n }\n }\n}\n\nexport function forEachOperation<T>(\n spec: IR,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(spec.paths)) {\n for (const method of methods) {\n const operation = pathItem[method];\n if (!operation) {\n continue;\n }\n const [tag] = operation.tags;\n result.push(callback({ method, path, tag }, operation));\n }\n }\n return result;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAsB,eAAe;AAmB9B,UAAU,kBACf,MAC8B;AAC9B,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,KAAK,KAAK,GAAG;AACzD,eAAW,UAAU,SAAS;AAC5B,YAAM,YAAY,SAAS,MAAM;AACjC,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AAEA,YAAM;AAAA,QACJ,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA,KAAK,UAAU,OAAO,CAAC;AAAA,QACzB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,iBACd,MACA,UACA;AACA,QAAM,SAAc,CAAC;AACrB,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,KAAK,KAAK,GAAG;AACzD,eAAW,UAAU,SAAS;AAC5B,YAAM,YAAY,SAAS,MAAM;AACjC,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AACA,YAAM,CAAC,GAAG,IAAI,UAAU;AACxB,aAAO,KAAK,SAAS,EAAE,QAAQ,MAAM,IAAI,GAAG,SAAS,CAAC;AAAA,IACxD;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-name.d.ts","
|
|
1
|
+
{"version":3,"file":"format-name.d.ts","sources":["../../src/lib/format-name.ts"],"names":[],"mappings":"AAwDA,eAAO,MAAM,UAAU,OAAQ,GAAG,KAAG,MAuCpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ref-usage.d.ts","
|
|
1
|
+
{"version":3,"file":"get-ref-usage.d.ts","sources":["../../src/lib/get-ref-usage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAgB,WAAW,CACzB,IAAI,EAAE,EAAE,EACR,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,MAAM,EAAO,GAClB,MAAM,EAAE,CAmDV"}
|
|
@@ -21,10 +21,9 @@ function getRefUsage(spec, schemaName, list = []) {
|
|
|
21
21
|
if (schema.type === "object") {
|
|
22
22
|
const properties = schema.properties;
|
|
23
23
|
if (!isEmpty(properties)) {
|
|
24
|
-
let found = false;
|
|
25
24
|
let propertyName = "";
|
|
26
25
|
for (const [key, it] of Object.entries(properties)) {
|
|
27
|
-
found = checkSchema(it, false);
|
|
26
|
+
const found = checkSchema(it, false);
|
|
28
27
|
if (found) {
|
|
29
28
|
propertyName = key;
|
|
30
29
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/get-ref-usage.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, parseRef, pascalcase } from '@sdk-it/core';\n\nimport type { IR } from './types.js';\n\nexport function getRefUsage(\n spec: IR,\n schemaName: string,\n list: string[] = [],\n): string[] {\n const checkSchema = (\n schema: SchemaObject | ReferenceObject,\n withRefCheck = false,\n ): any => {\n if (isRef(schema)) {\n if (!withRefCheck) return false;\n const { model } = parseRef(schema.$ref);\n return model === schemaName;\n }\n if (!isEmpty(schema.oneOf)) {\n return schema.oneOf.some((it) => checkSchema(it, true));\n }\n if (schema.type === 'array' && schema.items) {\n if (isRef(schema.items)) {\n return checkSchema(schema.items, withRefCheck);\n }\n if (schema.items.oneOf) {\n return schema.items.oneOf.some((it) => checkSchema(it, true));\n }\n return checkSchema(schema.items, withRefCheck);\n }\n\n if (schema.type === 'object') {\n const properties = schema.properties;\n if (!isEmpty(properties)) {\n let
|
|
5
|
-
"mappings": "AAEA,SAAS,SAAS,OAAO,UAAU,kBAAkB;AAI9C,SAAS,YACd,MACA,YACA,OAAiB,CAAC,GACR;AACV,QAAM,cAAc,CAClB,QACA,eAAe,UACP;AACR,QAAI,MAAM,MAAM,GAAG;AACjB,UAAI,CAAC,aAAc,QAAO;AAC1B,YAAM,EAAE,MAAM,IAAI,SAAS,OAAO,IAAI;AACtC,aAAO,UAAU;AAAA,IACnB;AACA,QAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,aAAO,OAAO,MAAM,KAAK,CAAC,OAAO,YAAY,IAAI,IAAI,CAAC;AAAA,IACxD;AACA,QAAI,OAAO,SAAS,WAAW,OAAO,OAAO;AAC3C,UAAI,MAAM,OAAO,KAAK,GAAG;AACvB,eAAO,YAAY,OAAO,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,MAAM,OAAO;AACtB,eAAO,OAAO,MAAM,MAAM,KAAK,CAAC,OAAO,YAAY,IAAI,IAAI,CAAC;AAAA,MAC9D;AACA,aAAO,YAAY,OAAO,OAAO,YAAY;AAAA,IAC/C;AAEA,QAAI,OAAO,SAAS,UAAU;AAC5B,YAAM,aAAa,OAAO;AAC1B,UAAI,CAAC,QAAQ,UAAU,GAAG;AACxB,YAAI,
|
|
4
|
+
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, parseRef, pascalcase } from '@sdk-it/core';\n\nimport type { IR } from './types.js';\n\nexport function getRefUsage(\n spec: IR,\n schemaName: string,\n list: string[] = [],\n): string[] {\n const checkSchema = (\n schema: SchemaObject | ReferenceObject,\n withRefCheck = false,\n ): any => {\n if (isRef(schema)) {\n if (!withRefCheck) return false;\n const { model } = parseRef(schema.$ref);\n return model === schemaName;\n }\n if (!isEmpty(schema.oneOf)) {\n return schema.oneOf.some((it) => checkSchema(it, true));\n }\n if (schema.type === 'array' && schema.items) {\n if (isRef(schema.items)) {\n return checkSchema(schema.items, withRefCheck);\n }\n if (schema.items.oneOf) {\n return schema.items.oneOf.some((it) => checkSchema(it, true));\n }\n return checkSchema(schema.items, withRefCheck);\n }\n\n if (schema.type === 'object') {\n const properties = schema.properties;\n if (!isEmpty(properties)) {\n let propertyName = '';\n for (const [key, it] of Object.entries(properties)) {\n const found = checkSchema(it, false);\n if (found) {\n propertyName = key;\n }\n }\n return propertyName;\n }\n }\n return false;\n };\n\n for (const [key, value] of Object.entries(spec.components.schemas)) {\n const thisWouldBeTheObjectPropertyKeyName = checkSchema(value);\n if (thisWouldBeTheObjectPropertyKeyName) {\n if (typeof thisWouldBeTheObjectPropertyKeyName === 'string') {\n list.push(pascalcase(`${key} ${thisWouldBeTheObjectPropertyKeyName}`));\n } else {\n list.push(pascalcase(key));\n }\n }\n }\n\n return list;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,SAAS,OAAO,UAAU,kBAAkB;AAI9C,SAAS,YACd,MACA,YACA,OAAiB,CAAC,GACR;AACV,QAAM,cAAc,CAClB,QACA,eAAe,UACP;AACR,QAAI,MAAM,MAAM,GAAG;AACjB,UAAI,CAAC,aAAc,QAAO;AAC1B,YAAM,EAAE,MAAM,IAAI,SAAS,OAAO,IAAI;AACtC,aAAO,UAAU;AAAA,IACnB;AACA,QAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,aAAO,OAAO,MAAM,KAAK,CAAC,OAAO,YAAY,IAAI,IAAI,CAAC;AAAA,IACxD;AACA,QAAI,OAAO,SAAS,WAAW,OAAO,OAAO;AAC3C,UAAI,MAAM,OAAO,KAAK,GAAG;AACvB,eAAO,YAAY,OAAO,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,MAAM,OAAO;AACtB,eAAO,OAAO,MAAM,MAAM,KAAK,CAAC,OAAO,YAAY,IAAI,IAAI,CAAC;AAAA,MAC9D;AACA,aAAO,YAAY,OAAO,OAAO,YAAY;AAAA,IAC/C;AAEA,QAAI,OAAO,SAAS,UAAU;AAC5B,YAAM,aAAa,OAAO;AAC1B,UAAI,CAAC,QAAQ,UAAU,GAAG;AACxB,YAAI,eAAe;AACnB,mBAAW,CAAC,KAAK,EAAE,KAAK,OAAO,QAAQ,UAAU,GAAG;AAClD,gBAAM,QAAQ,YAAY,IAAI,KAAK;AACnC,cAAI,OAAO;AACT,2BAAe;AAAA,UACjB;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,WAAW,OAAO,GAAG;AAClE,UAAM,sCAAsC,YAAY,KAAK;AAC7D,QAAI,qCAAqC;AACvC,UAAI,OAAO,wCAAwC,UAAU;AAC3D,aAAK,KAAK,WAAW,GAAG,GAAG,IAAI,mCAAmC,EAAE,CAAC;AAAA,MACvE,OAAO;AACL,aAAK,KAAK,WAAW,GAAG,CAAC;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guess-resource.d.ts","
|
|
1
|
+
{"version":3,"file":"guess-resource.d.ts","sources":["../../../src/lib/guess/guess-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA+GpD,wBAAgB,UAAU,CACxB,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;UAjCL,MAAM;WAAS,MAAM;EA8C/B"}
|