@ir-kit/openapi 0.2.0 → 0.4.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 +1 -1
- package/dist/index.d.ts +7 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/operation/body.d.ts +23 -30
- package/dist/operation/body.d.ts.map +1 -1
- package/dist/operation/body.js +23 -15
- package/dist/operation/body.js.map +1 -1
- package/dist/operation/responses.d.ts +14 -34
- package/dist/operation/responses.d.ts.map +1 -1
- package/dist/operation/responses.js +20 -20
- package/dist/operation/responses.js.map +1 -1
- package/dist/spec/normalize/index.d.ts +1 -0
- package/dist/spec/normalize/index.d.ts.map +1 -1
- package/dist/spec/normalize/index.js +1 -0
- package/dist/spec/normalize/index.js.map +1 -1
- package/dist/spec/normalize/refs.d.ts +8 -0
- package/dist/spec/normalize/refs.d.ts.map +1 -0
- package/dist/spec/normalize/refs.js +98 -0
- package/dist/spec/normalize/refs.js.map +1 -0
- package/dist/spec/ref.d.ts +4 -14
- package/dist/spec/ref.d.ts.map +1 -1
- package/dist/spec/ref.js +8 -22
- package/dist/spec/ref.js.map +1 -1
- package/dist/type/context.d.ts +6 -0
- package/dist/type/context.d.ts.map +1 -1
- package/dist/type/dispatch.d.ts +51 -64
- package/dist/type/dispatch.d.ts.map +1 -1
- package/dist/type/dispatch.js +71 -56
- package/dist/type/dispatch.js.map +1 -1
- package/package.json +6 -5
- package/dist/type/enum.d.ts +0 -42
- package/dist/type/enum.d.ts.map +0 -1
- package/dist/type/enum.js +0 -49
- package/dist/type/enum.js.map +0 -1
- package/dist/type/object.d.ts +0 -53
- package/dist/type/object.d.ts.map +0 -1
- package/dist/type/object.js +0 -36
- package/dist/type/object.js.map +0 -1
- package/dist/type/union.d.ts +0 -35
- package/dist/type/union.d.ts.map +0 -1
- package/dist/type/union.js +0 -29
- package/dist/type/union.js.map +0 -1
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ When you spot duplication in `@ir-kit/openapi-{go,kotlin,swift}`:
|
|
|
119
119
|
|
|
120
120
|
1. Identify the **pre-work** (what does the IR walk produce that's target-neutral?) vs the **render** (what's the target-specific shape it gets wrapped in?).
|
|
121
121
|
2. Add the pre-work helper to this package — pure function, generator, or classifier.
|
|
122
|
-
3. Update each emitter to consume it. Verify the petstore SDK regen is byte-identical (the repo's `examples/
|
|
122
|
+
3. Update each emitter to consume it. Verify the petstore SDK regen is byte-identical (the repo's `examples/openapi-sdk-petstore/` is the canonical fixture).
|
|
123
123
|
4. Land in one commit per emitter pass for clean git history.
|
|
124
124
|
|
|
125
125
|
If the duplication is in render — different code paths producing structurally-different target code — it stays per-emitter. Push back on consolidating principled language differences just because they look similar.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { EnumEntryIdent, EnumKind, EnumLiteral, ObjectProperty, ObjectShape, Schema, SchemaDiscriminator, SchemaOrBool, SchemaPrimitiveType, UnionShape, } from "@ir-kit/schema";
|
|
2
|
+
export { classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isNullable, isPrimitive, isRefOnly, isSchemaObject, isUnionShape, iterateObjectProperties, primitiveTag, refName, typeList, uniqueEnumEntries, } from "@ir-kit/schema";
|
|
3
|
+
export { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
|
|
4
|
+
export type { BodyShape, ClassifiedBody } from "./operation/body.js";
|
|
2
5
|
export { classifyBody, isOpaqueJsonBody } from "./operation/body.js";
|
|
3
6
|
export type { IteratedOperation } from "./operation/iter.js";
|
|
4
7
|
export { iterOperations } from "./operation/iter.js";
|
|
@@ -11,16 +14,10 @@ export type { TemplatePart } from "./operation/template.js";
|
|
|
11
14
|
export { parseTemplatedSegment } from "./operation/template.js";
|
|
12
15
|
export { FORM_URLENCODED_MEDIA, HTTP_METHOD_LITERAL, HTTP_METHODS, type HttpMethod, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "./spec/constants.js";
|
|
13
16
|
export type { Casing, EnumPassOptions, NamingConfig, NamingRule, NormalizeOptions, ObjectPassOptions, } from "./spec/normalize/index.js";
|
|
14
|
-
export { normalizeSpec, SAFE_NORMALIZE } from "./spec/normalize/index.js";
|
|
15
|
-
export { isMeaningless
|
|
17
|
+
export { hoistForeignSchemaRefs, normalizeSpec, SAFE_NORMALIZE, } from "./spec/normalize/index.js";
|
|
18
|
+
export { isMeaningless } from "./spec/ref.js";
|
|
16
19
|
export { extractSecuritySchemeNames, securityKey } from "./spec/security.js";
|
|
17
20
|
export type { TypeCtx } from "./type/context.js";
|
|
18
21
|
export type { SchemaToTypeOps } from "./type/dispatch.js";
|
|
19
|
-
export { schemaToType } from "./type/dispatch.js";
|
|
20
|
-
export type { EnumEntryIdent, EnumKind, EnumLiteral } from "./type/enum.js";
|
|
21
|
-
export { assertNoEnumCollisions, classifyEnumLiterals, } from "./type/enum.js";
|
|
22
|
-
export type { ObjectProperty, ObjectShape } from "./type/object.js";
|
|
23
|
-
export { classifyObjectShape, iterateObjectProperties, } from "./type/object.js";
|
|
24
|
-
export type { UnionShape } from "./type/union.js";
|
|
25
|
-
export { classifyUnion } from "./type/union.js";
|
|
22
|
+
export { enumType, schemaToType, schemaTypeName, synthTypeName, } from "./type/dispatch.js";
|
|
26
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,QAAQ,EACR,WAAW,EACX,cAAc,EACd,WAAW,EACX,MAAM,EACN,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,U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BAAsB,EACtB,aAAa,EACb,cAAc,GACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,aAAa,GACd,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isNullable, isPrimitive, isRefOnly, isSchemaObject, isUnionShape, iterateObjectProperties, primitiveTag, refName, typeList, uniqueEnumEntries, } from "@ir-kit/schema";
|
|
2
|
+
export { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
|
|
1
3
|
export { classifyBody, isOpaqueJsonBody } from "./operation/body.js";
|
|
2
4
|
export { iterOperations } from "./operation/iter.js";
|
|
3
5
|
export { collectLocatedParams, PARAM_LOCATIONS, paramsAt, } from "./operation/params.js";
|
|
@@ -5,11 +7,8 @@ export { classifyReturnShape, isSuccessStatus, successResponses, } from "./opera
|
|
|
5
7
|
export { deriveBaseName, operationDocLine, splitPathSegments, } from "./operation/signature.js";
|
|
6
8
|
export { parseTemplatedSegment } from "./operation/template.js";
|
|
7
9
|
export { FORM_URLENCODED_MEDIA, HTTP_METHOD_LITERAL, HTTP_METHODS, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "./spec/constants.js";
|
|
8
|
-
export { normalizeSpec, SAFE_NORMALIZE } from "./spec/normalize/index.js";
|
|
9
|
-
export { isMeaningless
|
|
10
|
+
export { hoistForeignSchemaRefs, normalizeSpec, SAFE_NORMALIZE, } from "./spec/normalize/index.js";
|
|
11
|
+
export { isMeaningless } from "./spec/ref.js";
|
|
10
12
|
export { extractSecuritySchemeNames, securityKey } from "./spec/security.js";
|
|
11
|
-
export { schemaToType } from "./type/dispatch.js";
|
|
12
|
-
export { assertNoEnumCollisions, classifyEnumLiterals, } from "./type/enum.js";
|
|
13
|
-
export { classifyObjectShape, iterateObjectProperties, } from "./type/object.js";
|
|
14
|
-
export { classifyUnion } from "./type/union.js";
|
|
13
|
+
export { enumType, schemaToType, schemaTypeName, synthTypeName, } from "./type/dispatch.js";
|
|
15
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EAEZ,aAAa,EACb,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,cAAc,GACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,aAAa,GACd,MAAM,oBAAoB,CAAC"}
|
package/dist/operation/body.d.ts
CHANGED
|
@@ -1,44 +1,37 @@
|
|
|
1
1
|
import type { IR } from "@hey-api/shared";
|
|
2
|
+
import { type Schema } from "@ir-kit/schema";
|
|
2
3
|
/**
|
|
3
|
-
* `true` when a JSON-typed body has no concrete `type` but carries
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `true` when a JSON-typed body has no concrete `type` but carries
|
|
5
|
+
* `oneOf`/`anyOf` branches — there's no cleanly-typed structure to
|
|
6
|
+
* bind to, so each emitter falls back to a raw byte buffer (`[]byte` /
|
|
7
|
+
* `ByteArray` / `Data`).
|
|
7
8
|
*/
|
|
8
|
-
export declare function isOpaqueJsonBody(schema:
|
|
9
|
+
export declare function isOpaqueJsonBody(schema: Schema): boolean;
|
|
9
10
|
/**
|
|
10
|
-
* Outcome of inspecting
|
|
11
|
-
*
|
|
11
|
+
* Outcome of inspecting a body's media type + schema shape. Each
|
|
12
|
+
* emitter switches on `kind` to pick its body-param strategy.
|
|
12
13
|
*/
|
|
13
|
-
export type BodyShape =
|
|
14
|
-
/** `application/json` with a meaningful schema. */
|
|
15
|
-
{
|
|
14
|
+
export type BodyShape = {
|
|
16
15
|
kind: "json-typed";
|
|
17
|
-
}
|
|
18
|
-
/** `application/json` whose schema collapses to opaque (oneOf/anyOf
|
|
19
|
-
* without a single shared shape). Each emitter falls back to bytes. */
|
|
20
|
-
| {
|
|
16
|
+
} | {
|
|
21
17
|
kind: "json-opaque";
|
|
22
|
-
}
|
|
23
|
-
/** `multipart/form-data` whose schema is an object — flatten props
|
|
24
|
-
* into one func param each. */
|
|
25
|
-
| {
|
|
18
|
+
} | {
|
|
26
19
|
kind: "multipart-object";
|
|
27
|
-
}
|
|
28
|
-
/** `application/x-www-form-urlencoded` whose schema is an object —
|
|
29
|
-
* flatten props into one func param each. */
|
|
30
|
-
| {
|
|
20
|
+
} | {
|
|
31
21
|
kind: "form-urlencoded-object";
|
|
32
|
-
}
|
|
33
|
-
/** Empty / octet-stream / image/* / unknown — caller pre-encodes a
|
|
34
|
-
* single bytes param. */
|
|
35
|
-
| {
|
|
22
|
+
} | {
|
|
36
23
|
kind: "opaque";
|
|
37
24
|
};
|
|
25
|
+
export interface ClassifiedBody {
|
|
26
|
+
shape: BodyShape;
|
|
27
|
+
/** The body's schema in canonical form, ready to feed `schemaToType`
|
|
28
|
+
* or `iterateObjectProperties`. */
|
|
29
|
+
schema: Schema;
|
|
30
|
+
}
|
|
38
31
|
/**
|
|
39
|
-
* Classify a body by
|
|
40
|
-
*
|
|
41
|
-
*
|
|
32
|
+
* Classify a body by media type + schema shape and return the schema
|
|
33
|
+
* pre-converted to canonical form so each emitter can dispatch on
|
|
34
|
+
* `shape.kind` without re-converting.
|
|
42
35
|
*/
|
|
43
|
-
export declare function classifyBody(body: IR.BodyObject):
|
|
36
|
+
export declare function classifyBody(body: IR.BodyObject): ClassifiedBody;
|
|
44
37
|
//# sourceMappingURL=body.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/operation/body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/operation/body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAS7C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,wBAAwB,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB;wCACoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,cAAc,CAkBhE"}
|
package/dist/operation/body.js
CHANGED
|
@@ -1,33 +1,41 @@
|
|
|
1
|
+
import {} from "@ir-kit/schema";
|
|
2
|
+
import { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
|
|
1
3
|
import { FORM_URLENCODED_MEDIA, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "../spec/constants.js";
|
|
2
4
|
/**
|
|
3
|
-
* `true` when a JSON-typed body has no concrete `type` but carries
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* `true` when a JSON-typed body has no concrete `type` but carries
|
|
6
|
+
* `oneOf`/`anyOf` branches — there's no cleanly-typed structure to
|
|
7
|
+
* bind to, so each emitter falls back to a raw byte buffer (`[]byte` /
|
|
8
|
+
* `ByteArray` / `Data`).
|
|
7
9
|
*/
|
|
8
10
|
export function isOpaqueJsonBody(schema) {
|
|
9
|
-
|
|
11
|
+
if (schema.type)
|
|
12
|
+
return false;
|
|
13
|
+
return Boolean(schema.oneOf?.length || schema.anyOf?.length);
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
|
-
* Classify a body by
|
|
13
|
-
*
|
|
14
|
-
*
|
|
16
|
+
* Classify a body by media type + schema shape and return the schema
|
|
17
|
+
* pre-converted to canonical form so each emitter can dispatch on
|
|
18
|
+
* `shape.kind` without re-converting.
|
|
15
19
|
*/
|
|
16
20
|
export function classifyBody(body) {
|
|
17
21
|
const mt = (body.mediaType ?? "").toLowerCase();
|
|
18
|
-
const schema = body.schema;
|
|
22
|
+
const schema = fromHeyApi(body.schema);
|
|
19
23
|
const isObject = schema.type === "object" && Boolean(schema.properties);
|
|
24
|
+
let shape;
|
|
20
25
|
if (mt && JSON_MEDIA_RE.test(mt)) {
|
|
21
|
-
|
|
26
|
+
shape = isOpaqueJsonBody(schema)
|
|
22
27
|
? { kind: "json-opaque" }
|
|
23
28
|
: { kind: "json-typed" };
|
|
24
29
|
}
|
|
25
|
-
if (mt.startsWith(MULTIPART_FORM_MEDIA) && isObject) {
|
|
26
|
-
|
|
30
|
+
else if (mt.startsWith(MULTIPART_FORM_MEDIA) && isObject) {
|
|
31
|
+
shape = { kind: "multipart-object" };
|
|
27
32
|
}
|
|
28
|
-
if (mt.startsWith(FORM_URLENCODED_MEDIA) && isObject) {
|
|
29
|
-
|
|
33
|
+
else if (mt.startsWith(FORM_URLENCODED_MEDIA) && isObject) {
|
|
34
|
+
shape = { kind: "form-urlencoded-object" };
|
|
30
35
|
}
|
|
31
|
-
|
|
36
|
+
else {
|
|
37
|
+
shape = { kind: "opaque" };
|
|
38
|
+
}
|
|
39
|
+
return { shape, schema };
|
|
32
40
|
}
|
|
33
41
|
//# sourceMappingURL=body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/operation/body.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,
|
|
1
|
+
{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AAQ,EAAE,CAAC;QAC5D,KAAK,GAAG,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC7B,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -1,58 +1,38 @@
|
|
|
1
1
|
import type { IR } from "@hey-api/shared";
|
|
2
|
-
|
|
3
|
-
* Match a 3-digit HTTP status code in the 2xx range. Treats string
|
|
4
|
-
* codes only (matching hey-api's IR shape) so `"default"` and `"4XX"`
|
|
5
|
-
* style buckets don't accidentally classify as success.
|
|
6
|
-
*/
|
|
2
|
+
import type { Schema } from "@ir-kit/schema";
|
|
7
3
|
export declare const isSuccessStatus: (code: string) => boolean;
|
|
8
4
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Common pattern across emitters: 0 → no return, 1 → decode straight,
|
|
13
|
-
* 2+ → emit a sum-type return that dispatches on the status code.
|
|
5
|
+
* Operation's 2xx responses as `[code, response]` tuples, sorted by
|
|
6
|
+
* code for stable per-target emission order.
|
|
14
7
|
*/
|
|
15
8
|
export declare function successResponses(op: IR.OperationObject): Array<readonly [string, IR.ResponseObject]>;
|
|
16
9
|
/**
|
|
17
|
-
* One arm of a multi-2xx sum-type return.
|
|
18
|
-
*
|
|
19
|
-
* decoded payload. `payloadType` is omitted for empty bodies (e.g. 204).
|
|
10
|
+
* One arm of a multi-2xx sum-type return. Status code + payload
|
|
11
|
+
* schema (canonical, already converted from hey-api).
|
|
20
12
|
*/
|
|
21
|
-
export interface ResponseCase
|
|
13
|
+
export interface ResponseCase {
|
|
22
14
|
statusCode: string;
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
/** `undefined` for empty / meaningless responses (e.g. `204`). */
|
|
16
|
+
schema: Schema | undefined;
|
|
25
17
|
}
|
|
26
18
|
/**
|
|
27
19
|
* Shape of an operation's success return, normalised so each emitter
|
|
28
|
-
* can switch on `kind
|
|
29
|
-
* (no successes, single empty, single typed, multi-case) from the
|
|
30
|
-
* `successResponses` array.
|
|
20
|
+
* can switch on `kind`. Schemas are canonical {@link Schema}.
|
|
31
21
|
*/
|
|
32
22
|
export type ReturnShape =
|
|
33
|
-
/**
|
|
34
|
-
* empty / meaningless. Caller renders its Unit / Void analog. */
|
|
23
|
+
/** No 2xx responses, or a single 2xx with empty schema. */
|
|
35
24
|
{
|
|
36
25
|
kind: "void";
|
|
37
26
|
}
|
|
38
|
-
/** Single 2xx
|
|
39
|
-
* `schemaToType(schema)` and uses the result as the return. */
|
|
27
|
+
/** Single 2xx with non-empty schema. */
|
|
40
28
|
| {
|
|
41
29
|
kind: "single";
|
|
42
|
-
schema:
|
|
30
|
+
schema: Schema;
|
|
43
31
|
}
|
|
44
|
-
/** Multiple 2xx
|
|
45
|
-
* Kotlin sealed class, Swift enum) and dispatches on status. */
|
|
32
|
+
/** Multiple 2xx — emitter renders a sum type. */
|
|
46
33
|
| {
|
|
47
34
|
kind: "multi";
|
|
48
|
-
cases: ReadonlyArray<
|
|
35
|
+
cases: ReadonlyArray<ResponseCase>;
|
|
49
36
|
};
|
|
50
|
-
/**
|
|
51
|
-
* Classify the success-path return for an operation. Folds the
|
|
52
|
-
* "0 success → void / 1 success with empty schema → void / 1 success
|
|
53
|
-
* with schema → single / 2+ success → multi" decision tree into one
|
|
54
|
-
* tagged union so each emitter just switches on `kind` and applies
|
|
55
|
-
* its target rendering.
|
|
56
|
-
*/
|
|
57
37
|
export declare function classifyReturnShape(op: IR.OperationObject): ReturnShape;
|
|
58
38
|
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7C,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,OAA+B,CAAC;AAE/E;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,EAAE,CAAC,eAAe,GACrB,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAM7C;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW;AACrB,2DAA2D;AACzD;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;AAClB,wCAAwC;GACtC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AACpC,iDAAiD;GAC/C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;CAAE,CAAC;AAE1D,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,GAAG,WAAW,CAqBvE"}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
+
import { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
|
|
1
2
|
import { isMeaningless } from "../spec/ref.js";
|
|
2
|
-
/**
|
|
3
|
-
* Match a 3-digit HTTP status code in the 2xx range. Treats string
|
|
4
|
-
* codes only (matching hey-api's IR shape) so `"default"` and `"4XX"`
|
|
5
|
-
* style buckets don't accidentally classify as success.
|
|
6
|
-
*/
|
|
7
3
|
export const isSuccessStatus = (code) => /^2\d\d$/.test(code);
|
|
8
4
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Common pattern across emitters: 0 → no return, 1 → decode straight,
|
|
13
|
-
* 2+ → emit a sum-type return that dispatches on the status code.
|
|
5
|
+
* Operation's 2xx responses as `[code, response]` tuples, sorted by
|
|
6
|
+
* code for stable per-target emission order.
|
|
14
7
|
*/
|
|
15
8
|
export function successResponses(op) {
|
|
16
9
|
return Object.entries(op.responses ?? {})
|
|
17
10
|
.filter(([k]) => isSuccessStatus(k))
|
|
18
11
|
.sort(([a], [b]) => a.localeCompare(b));
|
|
19
12
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Classify the success-path return for an operation. Folds the
|
|
22
|
-
* "0 success → void / 1 success with empty schema → void / 1 success
|
|
23
|
-
* with schema → single / 2+ success → multi" decision tree into one
|
|
24
|
-
* tagged union so each emitter just switches on `kind` and applies
|
|
25
|
-
* its target rendering.
|
|
26
|
-
*/
|
|
27
13
|
export function classifyReturnShape(op) {
|
|
28
14
|
const success = successResponses(op);
|
|
29
15
|
if (success.length === 0)
|
|
30
16
|
return { kind: "void" };
|
|
31
17
|
if (success.length === 1) {
|
|
32
18
|
const [, resp] = success[0];
|
|
33
|
-
if (!resp?.schema
|
|
19
|
+
if (!resp?.schema)
|
|
20
|
+
return { kind: "void" };
|
|
21
|
+
const schema = fromHeyApi(resp.schema);
|
|
22
|
+
if (isMeaningless(schema))
|
|
34
23
|
return { kind: "void" };
|
|
35
|
-
return { kind: "single", schema
|
|
24
|
+
return { kind: "single", schema };
|
|
36
25
|
}
|
|
37
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
kind: "multi",
|
|
28
|
+
cases: success.map(([statusCode, resp]) => {
|
|
29
|
+
if (!resp?.schema)
|
|
30
|
+
return { statusCode, schema: undefined };
|
|
31
|
+
const schema = fromHeyApi(resp.schema);
|
|
32
|
+
return {
|
|
33
|
+
statusCode,
|
|
34
|
+
schema: isMeaningless(schema) ? undefined : schema,
|
|
35
|
+
};
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
38
|
}
|
|
39
39
|
//# sourceMappingURL=responses.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE/E;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,EAAsB;IAEtB,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC;SACtC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;SACnC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAEvC,CAAC;AACJ,CAAC;AAwBD,MAAM,UAAU,mBAAmB,CAAC,EAAsB;IACxD,MAAM,OAAO,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QAC7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,aAAa,CAAC,MAAM,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;YACxC,IAAI,CAAC,IAAI,EAAE,MAAM;gBAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;YAC5D,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvC,OAAO;gBACL,UAAU;gBACV,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;aACnD,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -3,6 +3,7 @@ import type { ObjectPassOptions } from "./objects.js";
|
|
|
3
3
|
export type { EnumPassOptions } from "./enums.js";
|
|
4
4
|
export type { Casing, NamingConfig, NamingRule } from "./name.js";
|
|
5
5
|
export type { ObjectPassOptions } from "./objects.js";
|
|
6
|
+
export { hoistForeignSchemaRefs } from "./refs.js";
|
|
6
7
|
export interface NormalizeOptions {
|
|
7
8
|
/** Hoist identical inline enums to `components.schemas`. */
|
|
8
9
|
enums?: boolean | EnumPassOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spec/normalize/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAClE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spec/normalize/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAClE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IAClC,oDAAoD;IACpD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qFAAqF;IACrF,OAAO,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IACtC,yGAAyG;IACzG,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,CAmBxE;AAED,0EAA0E;AAC1E,eAAO,MAAM,cAAc,EAAE,gBAI5B,CAAC"}
|
|
@@ -9,6 +9,7 @@ import { collapseSingleAllOf } from "./allOf.js";
|
|
|
9
9
|
import { dedupeInlineEnums } from "./enums.js";
|
|
10
10
|
import { dedupeInlineObjects } from "./objects.js";
|
|
11
11
|
import { pruneUnusedSchemas } from "./prune.js";
|
|
12
|
+
export { hoistForeignSchemaRefs } from "./refs.js";
|
|
12
13
|
/** Apply enabled passes to `spec` in place. Returns the same reference. */
|
|
13
14
|
export function normalizeSpec(spec, opts = {}) {
|
|
14
15
|
if (opts.allOf)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/spec/normalize/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/spec/normalize/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAanD,2EAA2E;AAC3E,MAAM,UAAU,aAAa,CAAI,IAAO,EAAE,OAAyB,EAAE;IACnE,IAAI,IAAI,CAAC,KAAK;QAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,GAAG,iBAAiB,CAC7B,IAAI,EACJ,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CACtC,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,mBAAmB,CAC/B,IAAI,EACJ,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAC1C,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,IAAI,CAAC,KAAK;QAAE,kBAAkB,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAqB;IAC9C,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;CACZ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Give every schema that is `$ref`'d from outside the components section
|
|
3
|
+
* (e.g. `#/paths/~1apps/get/responses/200/.../properties/cors`) a home in
|
|
4
|
+
* `components.schemas`, and point those refs at it. Generators then only
|
|
5
|
+
* ever see refs to declared components. Returns the added schema names.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hoistForeignSchemaRefs(spec: unknown): Set<string>;
|
|
8
|
+
//# sourceMappingURL=refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../src/spec/normalize/refs.ts"],"names":[],"mappings":"AAsDA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAoCjE"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { uniqueComponentName } from "./name.js";
|
|
2
|
+
import { getSchemasObject, schemasPointerPrefix } from "./walk.js";
|
|
3
|
+
const STRUCTURAL = new Set([
|
|
4
|
+
"additionalProperties",
|
|
5
|
+
"allOf",
|
|
6
|
+
"anyOf",
|
|
7
|
+
"content",
|
|
8
|
+
"items",
|
|
9
|
+
"not",
|
|
10
|
+
"oneOf",
|
|
11
|
+
"properties",
|
|
12
|
+
"schema",
|
|
13
|
+
]);
|
|
14
|
+
function decodePointer(ref) {
|
|
15
|
+
return ref
|
|
16
|
+
.slice(2)
|
|
17
|
+
.split("/")
|
|
18
|
+
.map((s) => decodeURIComponent(s).replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
19
|
+
}
|
|
20
|
+
function resolvePointer(spec, segments) {
|
|
21
|
+
let node = spec;
|
|
22
|
+
for (const seg of segments) {
|
|
23
|
+
if (!node || typeof node !== "object")
|
|
24
|
+
return undefined;
|
|
25
|
+
node = node[seg];
|
|
26
|
+
}
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
function visitRefs(node, visit) {
|
|
30
|
+
if (!node || typeof node !== "object")
|
|
31
|
+
return;
|
|
32
|
+
if (Array.isArray(node)) {
|
|
33
|
+
for (const item of node)
|
|
34
|
+
visitRefs(item, visit);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const obj = node;
|
|
38
|
+
if (typeof obj.$ref === "string")
|
|
39
|
+
visit(obj, obj.$ref);
|
|
40
|
+
for (const v of Object.values(obj))
|
|
41
|
+
visitRefs(v, visit);
|
|
42
|
+
}
|
|
43
|
+
function nameFor(segments) {
|
|
44
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
45
|
+
const seg = segments[i];
|
|
46
|
+
if (!STRUCTURAL.has(seg) && !/^\d+$/.test(seg) && !seg.includes("/"))
|
|
47
|
+
return seg;
|
|
48
|
+
}
|
|
49
|
+
return "Schema";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Give every schema that is `$ref`'d from outside the components section
|
|
53
|
+
* (e.g. `#/paths/~1apps/get/responses/200/.../properties/cors`) a home in
|
|
54
|
+
* `components.schemas`, and point those refs at it. Generators then only
|
|
55
|
+
* ever see refs to declared components. Returns the added schema names.
|
|
56
|
+
*/
|
|
57
|
+
export function hoistForeignSchemaRefs(spec) {
|
|
58
|
+
const added = new Set();
|
|
59
|
+
const schemas = getSchemasObject(spec);
|
|
60
|
+
const prefix = schemasPointerPrefix(spec);
|
|
61
|
+
if (!schemas || !prefix)
|
|
62
|
+
return added;
|
|
63
|
+
const isForeign = (ref) => {
|
|
64
|
+
if (!ref.startsWith("#/") || ref.startsWith("#/components/"))
|
|
65
|
+
return false;
|
|
66
|
+
if (ref.startsWith("#/definitions/"))
|
|
67
|
+
return false;
|
|
68
|
+
return decodePointer(ref).some((s) => s === "schema" || s === "schemas");
|
|
69
|
+
};
|
|
70
|
+
const targets = new Map();
|
|
71
|
+
visitRefs(spec, (_, ref) => {
|
|
72
|
+
if (!isForeign(ref) || targets.has(ref))
|
|
73
|
+
return;
|
|
74
|
+
const segments = decodePointer(ref);
|
|
75
|
+
let target = resolvePointer(spec, segments);
|
|
76
|
+
if (!target || typeof target !== "object")
|
|
77
|
+
return;
|
|
78
|
+
const inner = target.$ref;
|
|
79
|
+
if (typeof inner === "string" && !isForeign(inner)) {
|
|
80
|
+
targets.set(ref, inner);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const name = uniqueComponentName(nameFor(segments), schemas, added);
|
|
84
|
+
target = structuredClone(target);
|
|
85
|
+
schemas[name] = target;
|
|
86
|
+
added.add(name);
|
|
87
|
+
targets.set(ref, `${prefix}${name}`);
|
|
88
|
+
});
|
|
89
|
+
if (targets.size === 0)
|
|
90
|
+
return added;
|
|
91
|
+
visitRefs(spec, (holder, ref) => {
|
|
92
|
+
const next = targets.get(ref);
|
|
93
|
+
if (next)
|
|
94
|
+
holder.$ref = next;
|
|
95
|
+
});
|
|
96
|
+
return added;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=refs.js.map
|
|
@@ -0,0 +1 @@
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MAAM,EAAE,GAAG,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI;YAAE,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/spec/ref.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Schema } from "@ir-kit/schema";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* the caller can decide how to surface them; in practice generators
|
|
6
|
-
* only see schema refs because hey-api's ref-parser inlines other
|
|
7
|
-
* pointer types (parameters, requestBodies, responses) before the IR
|
|
8
|
-
* stage.
|
|
3
|
+
* Empty / unknown / void schemas — short-circuits a 2xx response to a
|
|
4
|
+
* no-payload return (Kotlin `Unit`, Swift `Void`, Go's absent return).
|
|
9
5
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
/**
|
|
12
|
-
* Empty / unknown / void schemas — used to short-circuit a 2xx response
|
|
13
|
-
* to a no-payload return type (Kotlin `Unit`, Swift `Void`, Go's
|
|
14
|
-
* absence of a return type).
|
|
15
|
-
*/
|
|
16
|
-
export declare function isMeaningless(s: IR.SchemaObject): boolean;
|
|
6
|
+
export declare function isMeaningless(s: Schema): boolean;
|
|
17
7
|
//# sourceMappingURL=ref.d.ts.map
|
package/dist/spec/ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAOhD"}
|
package/dist/spec/ref.js
CHANGED
|
@@ -1,32 +1,18 @@
|
|
|
1
|
-
const REF_SCHEMA_PREFIX = "#/components/schemas/";
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* the caller can decide how to surface them; in practice generators
|
|
6
|
-
* only see schema refs because hey-api's ref-parser inlines other
|
|
7
|
-
* pointer types (parameters, requestBodies, responses) before the IR
|
|
8
|
-
* stage.
|
|
9
|
-
*/
|
|
10
|
-
export function refName(ref) {
|
|
11
|
-
return ref.startsWith(REF_SCHEMA_PREFIX)
|
|
12
|
-
? ref.slice(REF_SCHEMA_PREFIX.length)
|
|
13
|
-
: ref;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Empty / unknown / void schemas — used to short-circuit a 2xx response
|
|
17
|
-
* to a no-payload return type (Kotlin `Unit`, Swift `Void`, Go's
|
|
18
|
-
* absence of a return type).
|
|
2
|
+
* Empty / unknown / void schemas — short-circuits a 2xx response to a
|
|
3
|
+
* no-payload return (Kotlin `Unit`, Swift `Void`, Go's absent return).
|
|
19
4
|
*/
|
|
20
5
|
export function isMeaningless(s) {
|
|
21
6
|
if (s.$ref || s.const !== undefined)
|
|
22
7
|
return false;
|
|
23
|
-
if (s.items
|
|
8
|
+
if (s.items)
|
|
24
9
|
return false;
|
|
25
10
|
if (s.properties && Object.keys(s.properties).length > 0)
|
|
26
11
|
return false;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
if (s.oneOf?.length || s.anyOf?.length || s.allOf?.length)
|
|
13
|
+
return false;
|
|
14
|
+
if (s.enum && s.enum.length > 0)
|
|
15
|
+
return false;
|
|
16
|
+
return s.type === undefined;
|
|
31
17
|
}
|
|
32
18
|
//# sourceMappingURL=ref.js.map
|
package/dist/spec/ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,CAAS;IACrC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,CAAC,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM;QAAE,OAAO,KAAK,CAAC;IACxE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AAC9B,CAAC"}
|