@ir-kit/openapi 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- 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/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/dispatch.d.ts +36 -64
- package/dist/type/dispatch.d.ts.map +1 -1
- package/dist/type/dispatch.js +31 -54
- package/dist/type/dispatch.js.map +1 -1
- package/package.json +3 -2
- 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/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 { assertNoEnumCollisions, classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isNullable, isPrimitive, isRefOnly, isSchemaObject, isUnionShape, iterateObjectProperties, primitiveTag, refName, typeList, } 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";
|
|
@@ -12,15 +15,9 @@ 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
17
|
export { normalizeSpec, SAFE_NORMALIZE } from "./spec/normalize/index.js";
|
|
15
|
-
export { isMeaningless
|
|
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
22
|
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";
|
|
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":[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,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,KAAK,UAAU,EACf,aAAa,EACb,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,MAAM,EACN,eAAe,EACf,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,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,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { assertNoEnumCollisions, classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isNullable, isPrimitive, isRefOnly, isSchemaObject, isUnionShape, iterateObjectProperties, primitiveTag, refName, typeList, } 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";
|
|
@@ -6,10 +8,7 @@ export { deriveBaseName, operationDocLine, splitPathSegments, } from "./operatio
|
|
|
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
10
|
export { normalizeSpec, SAFE_NORMALIZE } from "./spec/normalize/index.js";
|
|
9
|
-
export { isMeaningless
|
|
11
|
+
export { isMeaningless } from "./spec/ref.js";
|
|
10
12
|
export { extractSecuritySchemeNames, securityKey } from "./spec/security.js";
|
|
11
13
|
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";
|
|
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,sBAAsB,EACtB,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,GACT,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,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,YAAY,EAAE,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
|
+
{"version":3,"file":"body.js","source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AC5D,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"}
|
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"}
|
package/dist/type/dispatch.d.ts
CHANGED
|
@@ -1,86 +1,58 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ObjectProperty, type Schema } from "@ir-kit/schema";
|
|
2
2
|
import type { TypeCtx } from "./context.js";
|
|
3
|
-
import { assertNoEnumCollisions } from "./enum.js";
|
|
4
|
-
import { classifyObjectShape, iterateObjectProperties, type ObjectProperty } from "./object.js";
|
|
5
|
-
import { classifyUnion } from "./union.js";
|
|
6
3
|
/**
|
|
7
|
-
* Per-target leaf operations the shared dispatchers (schemaToType
|
|
8
|
-
* unionToType
|
|
9
|
-
*
|
|
10
|
-
* decl type (GoDecl / KtDecl / SwDecl).
|
|
4
|
+
* Per-target leaf operations the shared dispatchers (`schemaToType`,
|
|
5
|
+
* `unionToType`, `inlineObjectType`) call into. `T` is the emitter's
|
|
6
|
+
* target type (`GoType` / `KtType` / `SwType`), `D` its decl type.
|
|
11
7
|
*
|
|
12
|
-
* Each emitter writes one of these records.
|
|
13
|
-
* (pointer vs nullable, naming conventions, synthName joiner,
|
|
14
|
-
*
|
|
15
|
-
* stay neutral.
|
|
8
|
+
* Each emitter writes one of these records. All per-target rendering
|
|
9
|
+
* (pointer vs nullable, naming conventions, synthName joiner, decl
|
|
10
|
+
* construction) lives here; the dispatchers stay neutral.
|
|
16
11
|
*/
|
|
17
12
|
export interface SchemaToTypeOps<T, D> {
|
|
18
|
-
/** `$ref` → named target type. */
|
|
19
13
|
refType(name: string): T;
|
|
20
|
-
/** Array element → target array/slice/list type. */
|
|
21
14
|
arrayType(elem: T): T;
|
|
22
|
-
/** Open object's value type — target map's value-of-Any. */
|
|
23
15
|
mapType(valueType: T): T;
|
|
24
|
-
/** "
|
|
16
|
+
/** Caller's "no return" analog — `goAny` (drops the result slot),
|
|
25
17
|
* `ktUnit`, `swVoid`. */
|
|
26
18
|
voidType(): T;
|
|
27
|
-
/**
|
|
19
|
+
/** Caller's untyped fallback — `goAny` / `ktAny` / `swAny`. */
|
|
28
20
|
anyType(): T;
|
|
29
|
-
/** Standalone nullable-any — what `null`-typed primitives become.
|
|
30
|
-
* Go wraps any in pointer; Kotlin / Swift wrap in nullable/optional. */
|
|
21
|
+
/** Standalone nullable-any — what `null`-typed primitives become. */
|
|
31
22
|
nullableAnyType(): T;
|
|
32
|
-
/** Wrap a known type in the target's optional wrapper for the
|
|
33
|
-
*
|
|
34
|
-
* (`isPointerable`
|
|
35
|
-
*
|
|
23
|
+
/** Wrap a known type in the target's optional wrapper for the union
|
|
24
|
+
* "single + nullable" path. Go's choice is conditional
|
|
25
|
+
* (`isPointerable`), so the hook receives both the inner type and
|
|
26
|
+
* the nullable bit. */
|
|
36
27
|
wrapForUnionSingle(inner: T, nullable: boolean): T;
|
|
37
|
-
/** Fallback type for unions with 2+ non-null branches.
|
|
38
|
-
*
|
|
39
|
-
* Swift wrap if nullable. */
|
|
28
|
+
/** Fallback type for unions with 2+ non-null branches. Go ignores
|
|
29
|
+
* `nullable` (interface already holds nil); Kotlin / Swift wrap. */
|
|
40
30
|
unionFallback(nullable: boolean): T;
|
|
41
|
-
/** Primitive dispatch
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* Swift / TypeScript use `"_"`. */
|
|
31
|
+
/** Primitive dispatch. Returns `undefined` for non-primitive schemas
|
|
32
|
+
* so the outer dispatcher can fall through. */
|
|
33
|
+
primitiveType(schema: Schema): T | undefined;
|
|
34
|
+
/** Build a synth name from `ctx.ownerName` + `propPath`. Joiner is
|
|
35
|
+
* per-target — Go uses `""` to keep `go vet` quiet, Kotlin / Swift
|
|
36
|
+
* use `"_"`. */
|
|
48
37
|
synthName(ownerName: string, propPath: ReadonlyArray<string>): string;
|
|
49
|
-
|
|
50
|
-
* property list. Per-target work: property identifier transform,
|
|
51
|
-
* optional wrapping, target field construction, annotation /
|
|
52
|
-
* coding-key emission. Returns the decl; the caller chooses to
|
|
53
|
-
* `emit` it (dispatcher does this; schema.ts also calls this
|
|
54
|
-
* directly for top-level component schemas). */
|
|
55
|
-
buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): D;
|
|
56
|
-
/** Emit a string-typed enum decl and return a ref. Per-target work:
|
|
57
|
-
* case-identifier transform (Go `<Type><Raw>`, Kotlin
|
|
58
|
-
* `SCREAMING_SNAKE`, Swift `camel`), decl construction, runtime
|
|
59
|
-
* bookkeeping (`@SerialName`, `Codable` conformance). */
|
|
38
|
+
buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): D;
|
|
60
39
|
emitStringEnum(name: string, raws: ReadonlyArray<string>, emit: (d: D) => void): T;
|
|
61
|
-
/** Same for integer-typed enums. */
|
|
62
40
|
emitIntegerEnum(name: string, raws: ReadonlyArray<number>, emit: (d: D) => void): T;
|
|
63
41
|
}
|
|
42
|
+
export declare function unionToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
|
|
43
|
+
export declare function inlineObjectType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
|
|
64
44
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Resolve an inline object schema to a target type. Three-way
|
|
71
|
-
* dispatch via `classifyObjectShape`, then per-target rendering:
|
|
45
|
+
* Top-level dispatch from a canonical {@link Schema} to a target type.
|
|
46
|
+
* Routes each schema shape to the appropriate handler (`unionToType` /
|
|
47
|
+
* `inlineObjectType` / per-target enum emitter / target leaf constructor).
|
|
48
|
+
* Per-target leaf decisions live in `ops`.
|
|
72
49
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* Top-level dispatch from `IR.SchemaObject` to a target type. Routes
|
|
80
|
-
* each schema shape to the appropriate handler (`unionToType` /
|
|
81
|
-
* `inlineObjectType` / per-target enum emitter / target leaf
|
|
82
|
-
* constructor). The per-target leaf decisions live in `ops`.
|
|
50
|
+
* Dispatch order:
|
|
51
|
+
* 1. `$ref` → named ref
|
|
52
|
+
* 2. enum (`enum: [...]` or `oneOf`-of-consts)
|
|
53
|
+
* 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
|
|
54
|
+
* 4. primitive (per-target hook decides)
|
|
55
|
+
* 5. compound by `type` (array / object / null)
|
|
83
56
|
*/
|
|
84
|
-
export declare function schemaToType<T, D>(schema:
|
|
85
|
-
export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
|
|
57
|
+
export declare function schemaToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
|
|
86
58
|
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EAEnB,KAAK,MAAM,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC;IACnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;IACzB;8BAC0B;IAC1B,QAAQ,IAAI,CAA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CAAC,CAAC,KAAK,CAAC,GACxC,CAAC,CAYH;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EACnC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EACf,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GACxC,CAAC,CAcH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EACf,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,CAAC,CA0CH"}
|
package/dist/type/dispatch.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { refName } from "
|
|
2
|
-
import { assertNoEnumCollisions, classifyEnumLiterals, } from "./enum.js";
|
|
3
|
-
import { classifyObjectShape, iterateObjectProperties, } from "./object.js";
|
|
4
|
-
import { classifyUnion } from "./union.js";
|
|
5
|
-
/**
|
|
6
|
-
* Resolve a union-shaped `IR.SchemaObject` to a target type. Wraps
|
|
7
|
-
* `classifyUnion` with per-target hooks for each branch.
|
|
8
|
-
*/
|
|
1
|
+
import { classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isSchemaObject, isUnionShape, iterateObjectProperties, refName, } from "@ir-kit/schema";
|
|
9
2
|
export function unionToType(schema, ctx, ops, dispatch) {
|
|
10
3
|
const shape = classifyUnion(schema);
|
|
11
4
|
switch (shape.kind) {
|
|
@@ -19,16 +12,8 @@ export function unionToType(schema, ctx, ops, dispatch) {
|
|
|
19
12
|
return ops.unionFallback(shape.nullable);
|
|
20
13
|
}
|
|
21
14
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Resolve an inline object schema to a target type. Three-way
|
|
24
|
-
* dispatch via `classifyObjectShape`, then per-target rendering:
|
|
25
|
-
*
|
|
26
|
-
* - named-struct → synth a name, build + emit struct, return ref
|
|
27
|
-
* - map → wrap value type in the target's map
|
|
28
|
-
* - open-map → map<string, any>
|
|
29
|
-
*/
|
|
30
15
|
export function inlineObjectType(schema, ctx, ops, dispatch) {
|
|
31
|
-
const shape =
|
|
16
|
+
const shape = classifyObject(schema);
|
|
32
17
|
switch (shape.kind) {
|
|
33
18
|
case "named-struct": {
|
|
34
19
|
const name = ops.synthName(ctx.ownerName, ctx.propPath);
|
|
@@ -43,60 +28,52 @@ export function inlineObjectType(schema, ctx, ops, dispatch) {
|
|
|
43
28
|
}
|
|
44
29
|
}
|
|
45
30
|
/**
|
|
46
|
-
* Top-level dispatch from
|
|
47
|
-
* each schema shape to the appropriate handler (`unionToType` /
|
|
48
|
-
* `inlineObjectType` / per-target enum emitter / target leaf
|
|
49
|
-
*
|
|
31
|
+
* Top-level dispatch from a canonical {@link Schema} to a target type.
|
|
32
|
+
* Routes each schema shape to the appropriate handler (`unionToType` /
|
|
33
|
+
* `inlineObjectType` / per-target enum emitter / target leaf constructor).
|
|
34
|
+
* Per-target leaf decisions live in `ops`.
|
|
35
|
+
*
|
|
36
|
+
* Dispatch order:
|
|
37
|
+
* 1. `$ref` → named ref
|
|
38
|
+
* 2. enum (`enum: [...]` or `oneOf`-of-consts)
|
|
39
|
+
* 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
|
|
40
|
+
* 4. primitive (per-target hook decides)
|
|
41
|
+
* 5. compound by `type` (array / object / null)
|
|
50
42
|
*/
|
|
51
43
|
export function schemaToType(schema, ctx, ops) {
|
|
52
44
|
const dispatch = (s, c) => schemaToType(s, c, ops);
|
|
53
45
|
if (schema.$ref)
|
|
54
46
|
return ops.refType(refName(schema.$ref));
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
47
|
+
const enumValues = extractEnumValues(schema);
|
|
48
|
+
if (enumValues && enumValues.length > 0) {
|
|
49
|
+
const name = ops.synthName(ctx.ownerName, ctx.propPath);
|
|
50
|
+
const filtered = enumValues.filter((v) => typeof v === "string" ||
|
|
51
|
+
typeof v === "number" ||
|
|
52
|
+
typeof v === "boolean");
|
|
53
|
+
const kind = classifyEnumLiterals(filtered, name);
|
|
54
|
+
if (kind === "integer")
|
|
55
|
+
return ops.emitIntegerEnum(name, filtered, ctx.emit);
|
|
56
|
+
return ops.emitStringEnum(name, filtered, ctx.emit);
|
|
58
57
|
}
|
|
58
|
+
if (isUnionShape(schema))
|
|
59
|
+
return unionToType(schema, ctx, ops, dispatch);
|
|
59
60
|
const primitive = ops.primitiveType(schema);
|
|
60
61
|
if (primitive !== undefined)
|
|
61
62
|
return primitive;
|
|
62
|
-
|
|
63
|
+
const t = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
64
|
+
switch (t) {
|
|
63
65
|
case "array": {
|
|
64
|
-
const
|
|
65
|
-
return ops.arrayType(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return ops.arrayType(ops.anyType());
|
|
69
|
-
case "enum": {
|
|
70
|
-
const name = ops.synthName(ctx.ownerName, ctx.propPath);
|
|
71
|
-
// Caller's emit walks the schema's `items[].const`; we surface
|
|
72
|
-
// the typed list via the helper rather than re-defining the
|
|
73
|
-
// literal-extraction here (lives in @ir-kit/openapi-tools).
|
|
74
|
-
const rawValues = (schema.items ?? [])
|
|
75
|
-
.map((i) => i.const)
|
|
76
|
-
.filter((v) => typeof v === "string" ||
|
|
77
|
-
typeof v === "number" ||
|
|
78
|
-
typeof v === "boolean");
|
|
79
|
-
// Collision enforcement is per-target (the identifiers differ),
|
|
80
|
-
// so we hand off to the target's emitStringEnum / emitIntegerEnum
|
|
81
|
-
// hook with the raw values; they call assertNoEnumCollisions
|
|
82
|
-
// internally after computing their identifiers.
|
|
83
|
-
const kind = classifyEnumLiterals(rawValues, name);
|
|
84
|
-
if (kind === "integer")
|
|
85
|
-
return ops.emitIntegerEnum(name, rawValues, ctx.emit);
|
|
86
|
-
return ops.emitStringEnum(name, rawValues, ctx.emit);
|
|
66
|
+
const items = schema.items;
|
|
67
|
+
return ops.arrayType(items && isSchemaObject(items)
|
|
68
|
+
? dispatch(items, ctx)
|
|
69
|
+
: ops.anyType());
|
|
87
70
|
}
|
|
88
71
|
case "object":
|
|
89
72
|
return inlineObjectType(schema, ctx, ops, dispatch);
|
|
90
73
|
case "null":
|
|
91
74
|
return ops.nullableAnyType();
|
|
92
|
-
case "never":
|
|
93
|
-
case "void":
|
|
94
|
-
case "undefined":
|
|
95
|
-
return ops.voidType();
|
|
96
75
|
default:
|
|
97
76
|
return ops.anyType();
|
|
98
77
|
}
|
|
99
78
|
}
|
|
100
|
-
// Re-export so emitters can import everything from one place.
|
|
101
|
-
export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
|
|
102
79
|
//# sourceMappingURL=dispatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,aAAa,EAEb,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,uBAAuB,EAEvB,OAAO,GAER,MAAM,gBAAgB,CAAC;AAyDxB,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,GAAe,EACf,GAA0B,EAC1B,QAAyC;IAEzC,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,8BAA8B;YACjC,OAAO,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACtD,KAAK,oBAAoB;YACvB,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;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AAC,MAAM,CAAC,IAAI,CAAC;IACpE,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YAC3B,OAAO,GAAG,CAAC,SAAS,CAClB,KAAK,IAAI,cAAc,CAAC,KAAK,CAAC;gBAC5B,CAAC,CAAC,QAAQ,CAAC,KAAe,EAAE,GAAG,CAAC;gBAChC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAClB,CAAC;QACJ,CAAC;QACD,KAAK,QAAQ;YACX,OAAO,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACtD,KAAK,MAAM;YACT,OAAO,GAAG,CAAC,eAAe,EAAE,CAAC;QAC/B;YACE,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ir-kit/openapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Language-agnostic OpenAPI IR-walking primitives shared by the native-SDK generators. Each helper consumes @hey-api/shared's IR and returns target-neutral data — parameter locations, response categories, body media-type classifications — so per-language emitters can stay focused on rendering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -55,7 +55,8 @@
|
|
|
55
55
|
"node": ">=20.19.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@ir-kit/codegen-core": "0.1.0"
|
|
58
|
+
"@ir-kit/codegen-core": "0.1.0",
|
|
59
|
+
"@ir-kit/schema": "0.2.0"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
62
|
"build": "tsc -p tsconfig.build.json",
|
package/dist/type/enum.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The supported leaf shape for `IR.SchemaObject` enum values. Mirrors
|
|
3
|
-
* `EnumLiteral` from `@ir-kit/openapi-tools` — re-declared here to keep
|
|
4
|
-
* the package's dependency footprint minimal (this is a 3-word union;
|
|
5
|
-
* a workspace dep just to import it would be heavyweight).
|
|
6
|
-
*/
|
|
7
|
-
export type EnumLiteral = string | number | boolean;
|
|
8
|
-
export type EnumKind = "string" | "integer";
|
|
9
|
-
/**
|
|
10
|
-
* Classify a set of enum literals as all-string or all-integer. Throws
|
|
11
|
-
* on mixed (or otherwise unsupported) shapes. Each emitter then picks
|
|
12
|
-
* its target rendering — Go emits `type ... string` + typed-consts,
|
|
13
|
-
* Kotlin emits an `enum class(val raw: String)` or a typealias to
|
|
14
|
-
* `Int`, Swift emits a raw-typed `enum: String, Codable`.
|
|
15
|
-
*
|
|
16
|
-
* `name` is woven into the thrown error message so the caller doesn't
|
|
17
|
-
* have to re-wrap; emitter call-sites previously open-coded the same
|
|
18
|
-
* `throw new Error(\`Enum ${name}: members must all be strings or all
|
|
19
|
-
* integers; got ...\`)` line.
|
|
20
|
-
*/
|
|
21
|
-
export declare function classifyEnumLiterals(values: ReadonlyArray<EnumLiteral>, name: string): EnumKind;
|
|
22
|
-
export interface EnumEntryIdent<T extends string | number> {
|
|
23
|
-
/** The identifier emitted into the target source (Go `StatusAvailable`,
|
|
24
|
-
* Kotlin `available`, Swift `available`). */
|
|
25
|
-
identifier: string;
|
|
26
|
-
/** The raw enum value the identifier was derived from. */
|
|
27
|
-
raw: T;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Detect emitter-side identifier collisions across enum entries and
|
|
31
|
-
* throw a descriptive error. Each emitter normalises raw enum values
|
|
32
|
-
* to its own identifier convention (Go `enumEntrySuffix`, Kotlin
|
|
33
|
-
* `enumEntryIdent`, Swift `safeCaseName`); when two raw values
|
|
34
|
-
* normalise to the same identifier the emitted source won't compile,
|
|
35
|
-
* so we throw early with the offending name and the colliding raws.
|
|
36
|
-
*
|
|
37
|
-
* `noun` is the label used in the error message — kept per-emitter to
|
|
38
|
-
* preserve historical wording (Go / Kotlin say `entry name`, Swift
|
|
39
|
-
* says `case name`); tests pin the exact phrase.
|
|
40
|
-
*/
|
|
41
|
-
export declare function assertNoEnumCollisions<T extends string | number>(schemaName: string, entries: Iterable<EnumEntryIdent<T>>, noun?: "entry name" | "case name"): void;
|
|
42
|
-
//# sourceMappingURL=enum.d.ts.map
|
package/dist/type/enum.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/type/enum.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,EAClC,IAAI,EAAE,MAAM,GACX,QAAQ,CAWV;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACvD;kDAC8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,GAAG,EAAE,CAAC,CAAC;CACR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC9D,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACpC,IAAI,GAAE,YAAY,GAAG,WAA0B,GAC9C,IAAI,CAiBN"}
|
package/dist/type/enum.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Classify a set of enum literals as all-string or all-integer. Throws
|
|
3
|
-
* on mixed (or otherwise unsupported) shapes. Each emitter then picks
|
|
4
|
-
* its target rendering — Go emits `type ... string` + typed-consts,
|
|
5
|
-
* Kotlin emits an `enum class(val raw: String)` or a typealias to
|
|
6
|
-
* `Int`, Swift emits a raw-typed `enum: String, Codable`.
|
|
7
|
-
*
|
|
8
|
-
* `name` is woven into the thrown error message so the caller doesn't
|
|
9
|
-
* have to re-wrap; emitter call-sites previously open-coded the same
|
|
10
|
-
* `throw new Error(\`Enum ${name}: members must all be strings or all
|
|
11
|
-
* integers; got ...\`)` line.
|
|
12
|
-
*/
|
|
13
|
-
export function classifyEnumLiterals(values, name) {
|
|
14
|
-
const allStrings = values.every((v) => typeof v === "string");
|
|
15
|
-
const allIntegers = values.every((v) => typeof v === "number" && Number.isInteger(v));
|
|
16
|
-
if (!allStrings && !allIntegers) {
|
|
17
|
-
throw new Error(`Enum ${name}: members must all be strings or all integers; got ${JSON.stringify(values)}`);
|
|
18
|
-
}
|
|
19
|
-
return allIntegers ? "integer" : "string";
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Detect emitter-side identifier collisions across enum entries and
|
|
23
|
-
* throw a descriptive error. Each emitter normalises raw enum values
|
|
24
|
-
* to its own identifier convention (Go `enumEntrySuffix`, Kotlin
|
|
25
|
-
* `enumEntryIdent`, Swift `safeCaseName`); when two raw values
|
|
26
|
-
* normalise to the same identifier the emitted source won't compile,
|
|
27
|
-
* so we throw early with the offending name and the colliding raws.
|
|
28
|
-
*
|
|
29
|
-
* `noun` is the label used in the error message — kept per-emitter to
|
|
30
|
-
* preserve historical wording (Go / Kotlin say `entry name`, Swift
|
|
31
|
-
* says `case name`); tests pin the exact phrase.
|
|
32
|
-
*/
|
|
33
|
-
export function assertNoEnumCollisions(schemaName, entries, noun = "entry name") {
|
|
34
|
-
const collisions = new Map();
|
|
35
|
-
for (const { identifier, raw } of entries) {
|
|
36
|
-
const list = collisions.get(identifier) ?? [];
|
|
37
|
-
list.push(raw);
|
|
38
|
-
collisions.set(identifier, list);
|
|
39
|
-
}
|
|
40
|
-
for (const [identifier, raws] of collisions) {
|
|
41
|
-
if (raws.length > 1) {
|
|
42
|
-
const formatted = raws
|
|
43
|
-
.map((r) => (typeof r === "string" ? `"${r}"` : String(r)))
|
|
44
|
-
.join(", ");
|
|
45
|
-
throw new Error(`Enum ${schemaName}: ${noun} "${identifier}" collides for raw values [${formatted}]`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=enum.js.map
|
package/dist/type/enum.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/type/enum.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAkC,EAClC,IAAY;IAEZ,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CACpD,CAAC;IACF,IAAI,CAAC,UAAU,IAAI,CAAC,WAAW,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,QAAQ,IAAI,sDAAsD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAC3F,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC5C,CAAC;AAUD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAAkB,EAClB,OAAoC,EACpC,OAAmC,YAAY;IAE/C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAe,CAAC;IAC1C,KAAK,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,OAAO,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IACD,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;QAC5C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,SAAS,GAAG,IAAI;iBACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,MAAM,IAAI,KAAK,CACb,QAAQ,UAAU,KAAK,IAAI,KAAK,UAAU,8BAA8B,SAAS,GAAG,CACrF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/type/object.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { IR } from "@hey-api/shared";
|
|
2
|
-
/**
|
|
3
|
-
* High-level dispatch for inline object schemas. Each emitter then
|
|
4
|
-
* picks its target rendering:
|
|
5
|
-
*
|
|
6
|
-
* - `named-struct` → synth a name, emit a struct/data-class/struct,
|
|
7
|
-
* return a ref to it
|
|
8
|
-
* - `map` → render as `map[string]V` / `Map<String, V>` /
|
|
9
|
-
* `[String: V]` over the inner value schema
|
|
10
|
-
* - `open-map` → same map, but value is `any` / `Any` / `Any`
|
|
11
|
-
* since `additionalProperties` was missing or
|
|
12
|
-
* `true`/empty
|
|
13
|
-
*/
|
|
14
|
-
export type ObjectShape = {
|
|
15
|
-
kind: "named-struct";
|
|
16
|
-
} | {
|
|
17
|
-
kind: "map";
|
|
18
|
-
valueSchema: IR.SchemaObject;
|
|
19
|
-
} | {
|
|
20
|
-
kind: "open-map";
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Classify an object-shaped schema by its property layout. Used by
|
|
24
|
-
* each emitter's `inlineObjectType` to drive the same three-way
|
|
25
|
-
* dispatch identically.
|
|
26
|
-
*/
|
|
27
|
-
export declare function classifyObjectShape(schema: IR.SchemaObject): ObjectShape;
|
|
28
|
-
export interface ObjectProperty {
|
|
29
|
-
jsonKey: string;
|
|
30
|
-
schema: IR.SchemaObject;
|
|
31
|
-
/** True when the property name appears in `schema.required`. */
|
|
32
|
-
required: boolean;
|
|
33
|
-
/** True when the property is `string` + `format: "binary"`. Common
|
|
34
|
-
* enough across emitters (multipart-binary handling) to surface
|
|
35
|
-
* alongside the basic iteration. */
|
|
36
|
-
isBinary: boolean;
|
|
37
|
-
/** The propPath segment for this property, ready to plug into a
|
|
38
|
-
* recursive `schemaToType(propSchema, { ...ctx, propPath: [segment] })`
|
|
39
|
-
* call. Pre-computed as `pascal(jsonKey)` since both `synthName`
|
|
40
|
-
* variants (codegen-core's `_`-joined and Go's `""`-joined) expect
|
|
41
|
-
* PascalCase parts. */
|
|
42
|
-
propPathSegment: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Walk `schema.properties` in declaration order and yield one
|
|
46
|
-
* `ObjectProperty` per entry, with the `required` membership,
|
|
47
|
-
* binary-format detection, and pre-computed propPath segment
|
|
48
|
-
* surfaced. Used by every emitter's `type/object.ts`
|
|
49
|
-
* (struct/data-class/struct field generation) and `operation/body.ts`
|
|
50
|
-
* (multipart / urlencoded flat-param expansion).
|
|
51
|
-
*/
|
|
52
|
-
export declare function iterateObjectProperties(schema: IR.SchemaObject): Generator<ObjectProperty>;
|
|
53
|
-
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/type/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAG1C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,EAAE,CAAC,YAAY,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAEzB;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,GAAG,WAAW,CAMxE;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC;IACxB,gEAAgE;IAChE,QAAQ,EAAE,OAAO,CAAC;IAClB;;yCAEqC;IACrC,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;4BAIwB;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAiB,uBAAuB,CACtC,MAAM,EAAE,EAAE,CAAC,YAAY,GACtB,SAAS,CAAC,cAAc,CAAC,CAW3B"}
|
package/dist/type/object.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { pascal } from "@ir-kit/codegen-core";
|
|
2
|
-
/**
|
|
3
|
-
* Classify an object-shaped schema by its property layout. Used by
|
|
4
|
-
* each emitter's `inlineObjectType` to drive the same three-way
|
|
5
|
-
* dispatch identically.
|
|
6
|
-
*/
|
|
7
|
-
export function classifyObjectShape(schema) {
|
|
8
|
-
const hasNamedProperties = Object.keys(schema.properties ?? {}).length > 0;
|
|
9
|
-
if (hasNamedProperties)
|
|
10
|
-
return { kind: "named-struct" };
|
|
11
|
-
const ap = schema.additionalProperties;
|
|
12
|
-
if (ap && typeof ap === "object")
|
|
13
|
-
return { kind: "map", valueSchema: ap };
|
|
14
|
-
return { kind: "open-map" };
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Walk `schema.properties` in declaration order and yield one
|
|
18
|
-
* `ObjectProperty` per entry, with the `required` membership,
|
|
19
|
-
* binary-format detection, and pre-computed propPath segment
|
|
20
|
-
* surfaced. Used by every emitter's `type/object.ts`
|
|
21
|
-
* (struct/data-class/struct field generation) and `operation/body.ts`
|
|
22
|
-
* (multipart / urlencoded flat-param expansion).
|
|
23
|
-
*/
|
|
24
|
-
export function* iterateObjectProperties(schema) {
|
|
25
|
-
const required = new Set(schema.required ?? []);
|
|
26
|
-
for (const [jsonKey, propSchema] of Object.entries(schema.properties ?? {})) {
|
|
27
|
-
yield {
|
|
28
|
-
jsonKey,
|
|
29
|
-
schema: propSchema,
|
|
30
|
-
required: required.has(jsonKey),
|
|
31
|
-
isBinary: propSchema.type === "string" && propSchema.format === "binary",
|
|
32
|
-
propPathSegment: pascal(jsonKey),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=object.js.map
|
package/dist/type/object.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/type/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAmB9C;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAuB;IACzD,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3E,IAAI,kBAAkB;QAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IACxD,MAAM,EAAE,GAAG,MAAM,CAAC,oBAAoB,CAAC;IACvC,IAAI,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAC1E,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9B,CAAC;AAmBD;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,uBAAuB,CACtC,MAAuB;IAEvB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAChD,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,CAAC;QAC5E,MAAM;YACJ,OAAO;YACP,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;YAC/B,QAAQ,EAAE,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,QAAQ;YACxE,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC;SACjC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/type/union.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { IR } from "@hey-api/shared";
|
|
2
|
-
/**
|
|
3
|
-
* Outcome of inspecting a union-shaped schema. Pure structural —
|
|
4
|
-
* caller still needs to decide how to render each kind in its target
|
|
5
|
-
* language (Go pointer vs Kotlin nullable vs Swift optional, fall-back
|
|
6
|
-
* to `any` vs `Any` vs language equivalents).
|
|
7
|
-
*/
|
|
8
|
-
export type UnionShape = {
|
|
9
|
-
kind: "intersection-with-properties";
|
|
10
|
-
} | {
|
|
11
|
-
kind: "intersection-empty";
|
|
12
|
-
} | {
|
|
13
|
-
kind: "single";
|
|
14
|
-
inner: IR.SchemaObject;
|
|
15
|
-
nullable: boolean;
|
|
16
|
-
} | {
|
|
17
|
-
kind: "multi";
|
|
18
|
-
nullable: boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Classify a union-shaped schema (`logicalOperator: "or" | "and"`)
|
|
22
|
-
* into one of the cases each emitter handles. hey-api represents
|
|
23
|
-
* OpenAPI 3.1 nullables as `or` unions with a `{type:"null"}` branch;
|
|
24
|
-
* `allOf` folds become `and`.
|
|
25
|
-
*
|
|
26
|
-
* - `and` + properties → caller dispatches to its inline-object path.
|
|
27
|
-
* - `and` empty → caller renders its `any` analog.
|
|
28
|
-
* - 1 non-null branch → caller renders the inner, applying its own
|
|
29
|
-
* nullable wrapper iff `nullable === true`.
|
|
30
|
-
* - 2+ non-null → caller falls back to its `any`; `nullable`
|
|
31
|
-
* is reported but caller decides whether to
|
|
32
|
-
* apply it (Go drops it, KT/Swift wrap).
|
|
33
|
-
*/
|
|
34
|
-
export declare function classifyUnion(schema: IR.SchemaObject): UnionShape;
|
|
35
|
-
//# sourceMappingURL=union.d.ts.map
|
package/dist/type/union.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/type/union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,8BAA8B,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,GAAG,UAAU,CAajE"}
|
package/dist/type/union.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Classify a union-shaped schema (`logicalOperator: "or" | "and"`)
|
|
3
|
-
* into one of the cases each emitter handles. hey-api represents
|
|
4
|
-
* OpenAPI 3.1 nullables as `or` unions with a `{type:"null"}` branch;
|
|
5
|
-
* `allOf` folds become `and`.
|
|
6
|
-
*
|
|
7
|
-
* - `and` + properties → caller dispatches to its inline-object path.
|
|
8
|
-
* - `and` empty → caller renders its `any` analog.
|
|
9
|
-
* - 1 non-null branch → caller renders the inner, applying its own
|
|
10
|
-
* nullable wrapper iff `nullable === true`.
|
|
11
|
-
* - 2+ non-null → caller falls back to its `any`; `nullable`
|
|
12
|
-
* is reported but caller decides whether to
|
|
13
|
-
* apply it (Go drops it, KT/Swift wrap).
|
|
14
|
-
*/
|
|
15
|
-
export function classifyUnion(schema) {
|
|
16
|
-
if (schema.logicalOperator === "and") {
|
|
17
|
-
return schema.properties
|
|
18
|
-
? { kind: "intersection-with-properties" }
|
|
19
|
-
: { kind: "intersection-empty" };
|
|
20
|
-
}
|
|
21
|
-
const items = schema.items ?? [];
|
|
22
|
-
const nonNull = items.filter((i) => i.type !== "null");
|
|
23
|
-
const nullable = nonNull.length < items.length;
|
|
24
|
-
if (nonNull.length === 1) {
|
|
25
|
-
return { kind: "single", inner: nonNull[0], nullable };
|
|
26
|
-
}
|
|
27
|
-
return { kind: "multi", nullable };
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=union.js.map
|
package/dist/type/union.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/type/union.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,MAAuB;IACnD,IAAI,MAAM,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC,UAAU;YACtB,CAAC,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE;YAC1C,CAAC,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;IACrC,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,QAAQ,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}
|