@ir-kit/openapi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +131 -0
  3. package/dist/index.d.ts +21 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +11 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/operation/body.d.ts +45 -0
  8. package/dist/operation/body.d.ts.map +1 -0
  9. package/dist/operation/body.js +34 -0
  10. package/dist/operation/body.js.map +1 -0
  11. package/dist/operation/iter.d.ts +22 -0
  12. package/dist/operation/iter.d.ts.map +1 -0
  13. package/dist/operation/iter.js +27 -0
  14. package/dist/operation/iter.js.map +1 -0
  15. package/dist/operation/params.d.ts +27 -0
  16. package/dist/operation/params.d.ts.map +1 -0
  17. package/dist/operation/params.js +38 -0
  18. package/dist/operation/params.js.map +1 -0
  19. package/dist/operation/responses.d.ts +58 -0
  20. package/dist/operation/responses.d.ts.map +1 -0
  21. package/dist/operation/responses.js +39 -0
  22. package/dist/operation/responses.js.map +1 -0
  23. package/dist/operation/signature.d.ts +29 -0
  24. package/dist/operation/signature.d.ts.map +1 -0
  25. package/dist/operation/signature.js +41 -0
  26. package/dist/operation/signature.js.map +1 -0
  27. package/dist/operation/template.d.ts +30 -0
  28. package/dist/operation/template.d.ts.map +1 -0
  29. package/dist/operation/template.js +33 -0
  30. package/dist/operation/template.js.map +1 -0
  31. package/dist/type/context.d.ts +17 -0
  32. package/dist/type/context.d.ts.map +1 -0
  33. package/dist/type/context.js +2 -0
  34. package/dist/type/context.js.map +1 -0
  35. package/dist/type/dispatch.d.ts +86 -0
  36. package/dist/type/dispatch.d.ts.map +1 -0
  37. package/dist/type/dispatch.js +102 -0
  38. package/dist/type/dispatch.js.map +1 -0
  39. package/dist/type/enum.d.ts +42 -0
  40. package/dist/type/enum.d.ts.map +1 -0
  41. package/dist/type/enum.js +49 -0
  42. package/dist/type/enum.js.map +1 -0
  43. package/dist/type/object.d.ts +53 -0
  44. package/dist/type/object.d.ts.map +1 -0
  45. package/dist/type/object.js +36 -0
  46. package/dist/type/object.js.map +1 -0
  47. package/dist/type/union.d.ts +35 -0
  48. package/dist/type/union.d.ts.map +1 -0
  49. package/dist/type/union.js +29 -0
  50. package/dist/type/union.js.map +1 -0
  51. package/package.json +67 -0
@@ -0,0 +1,30 @@
1
+ import type { IR } from "@hey-api/shared";
2
+ /**
3
+ * One part of a parsed URL path template segment.
4
+ * - `literal` — a literal substring with no `{...}` placeholder
5
+ * - `param` — a `{name}` placeholder, with the matched
6
+ * `ParameterObject` if found in the supplied path
7
+ * params (callers typically need the schema to decide
8
+ * stringification, plus the raw name to feed their
9
+ * language-specific identifier transform).
10
+ */
11
+ export type TemplatePart = {
12
+ kind: "literal";
13
+ text: string;
14
+ } | {
15
+ kind: "param";
16
+ name: string;
17
+ param: IR.ParameterObject | undefined;
18
+ };
19
+ /**
20
+ * Split a single path segment containing zero or more `{name}` template
21
+ * placeholders into ordered literal/param parts. The regex (`/\{([^}]+)\}/g`)
22
+ * + lastEnd cursor walk was open-coded identically in every emitter's
23
+ * `impl/url.ts`; here once, in one place.
24
+ *
25
+ * `pathParams` is the operation's path-located params; resolved
26
+ * placeholders carry the matched `ParameterObject` so emitters can
27
+ * read its schema (e.g. for stringification decisions).
28
+ */
29
+ export declare function parseTemplatedSegment(seg: string, pathParams: ReadonlyArray<IR.ParameterObject>): TemplatePart[];
30
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/operation/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,EAAE,CAAC,eAAe,GAAG,SAAS,CAAA;CAAE,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,GAC5C,YAAY,EAAE,CAqBhB"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Split a single path segment containing zero or more `{name}` template
3
+ * placeholders into ordered literal/param parts. The regex (`/\{([^}]+)\}/g`)
4
+ * + lastEnd cursor walk was open-coded identically in every emitter's
5
+ * `impl/url.ts`; here once, in one place.
6
+ *
7
+ * `pathParams` is the operation's path-located params; resolved
8
+ * placeholders carry the matched `ParameterObject` so emitters can
9
+ * read its schema (e.g. for stringification decisions).
10
+ */
11
+ export function parseTemplatedSegment(seg, pathParams) {
12
+ const re = /\{([^}]+)\}/g;
13
+ const parts = [];
14
+ let lastEnd = 0;
15
+ let m;
16
+ while ((m = re.exec(seg)) !== null) {
17
+ if (m.index > lastEnd) {
18
+ parts.push({ kind: "literal", text: seg.slice(lastEnd, m.index) });
19
+ }
20
+ const name = m[1];
21
+ parts.push({
22
+ kind: "param",
23
+ name,
24
+ param: pathParams.find((p) => p.name === name),
25
+ });
26
+ lastEnd = m.index + m[0].length;
27
+ }
28
+ if (lastEnd < seg.length) {
29
+ parts.push({ kind: "literal", text: seg.slice(lastEnd) });
30
+ }
31
+ return parts;
32
+ }
33
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/operation/template.ts"],"names":[],"mappings":"AAeA;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,GAAW,EACX,UAA6C;IAE7C,MAAM,EAAE,GAAG,cAAc,CAAC;IAC1B,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,CAAC,KAAK,GAAG,OAAO,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,OAAO;YACb,IAAI;YACJ,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;SAC/C,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAClC,CAAC;IACD,IAAI,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Shared type-walker context, generic over the per-target Decl type.
3
+ * Each emitter narrows `D` to its own AST node — `GoDecl`, `KtDecl`,
4
+ * `SwDecl`, etc. — and re-exports a concrete alias.
5
+ *
6
+ * The walker uses `emit` to promote synthesised inline types
7
+ * (objects, enums) to top-level declarations; `ownerName` and
8
+ * `propPath` drive deterministic names for those synthesised types
9
+ * (e.g. `Owner_Path`).
10
+ */
11
+ export interface TypeCtx<D> {
12
+ emit: (d: D) => void;
13
+ /** Used to synthesise names for inline objects/enums: `Owner_Path`. */
14
+ ownerName: string;
15
+ propPath: ReadonlyArray<string>;
16
+ }
17
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/type/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IACrB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/type/context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,86 @@
1
+ import type { IR } from "@hey-api/shared";
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
+ /**
7
+ * Per-target leaf operations the shared dispatchers (schemaToType,
8
+ * unionToType, inlineObjectType, buildEnumFromIR) call into. `T` is
9
+ * the emitter's target type (GoType / KtType / SwType), `D` is its
10
+ * decl type (GoDecl / KtDecl / SwDecl).
11
+ *
12
+ * Each emitter writes one of these records. Per-target rendering
13
+ * (pointer vs nullable, naming conventions, synthName joiner,
14
+ * decl-construction call shape) lives entirely here; the dispatchers
15
+ * stay neutral.
16
+ */
17
+ export interface SchemaToTypeOps<T, D> {
18
+ /** `$ref` → named target type. */
19
+ refType(name: string): T;
20
+ /** Array element → target array/slice/list type. */
21
+ arrayType(elem: T): T;
22
+ /** Open object's value type — target map's value-of-Any. */
23
+ mapType(valueType: T): T;
24
+ /** "No return" analog — `goAny` (Go callers drop the result slot),
25
+ * `ktUnit`, `swVoid`. */
26
+ voidType(): T;
27
+ /** Untyped fallback — `goAny` / `ktAny` / `swAny`. */
28
+ anyType(): T;
29
+ /** Standalone nullable-any — what `null`-typed primitives become.
30
+ * Go wraps any in pointer; Kotlin / Swift wrap in nullable/optional. */
31
+ nullableAnyType(): T;
32
+ /** Wrap a known type in the target's optional wrapper for the
33
+ * union "single + nullable" path. Go's choice is conditional
34
+ * (`isPointerable` check), so this hook receives both `nullable`
35
+ * and the bare inner type and decides. */
36
+ wrapForUnionSingle(inner: T, nullable: boolean): T;
37
+ /** Fallback type for unions with 2+ non-null branches. Go ignores
38
+ * the nullable bit (`interface{}` already holds nil); Kotlin /
39
+ * Swift wrap if nullable. */
40
+ unionFallback(nullable: boolean): T;
41
+ /** Primitive dispatch (string, integer, number, boolean). Returns
42
+ * `undefined` for non-primitive schemas so the outer dispatcher
43
+ * can fall through to compound handling. */
44
+ primitiveType(schema: IR.SchemaObject): T | undefined;
45
+ /** Build a synth name from ctx.ownerName + propPath. Joiner is
46
+ * per-target — Go uses `""` to keep `go vet` quiet, Kotlin /
47
+ * Swift / TypeScript use `"_"`. */
48
+ synthName(ownerName: string, propPath: ReadonlyArray<string>): string;
49
+ /** Build a named struct/data-class/struct decl from an iterated
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). */
60
+ emitStringEnum(name: string, raws: ReadonlyArray<string>, emit: (d: D) => void): T;
61
+ /** Same for integer-typed enums. */
62
+ emitIntegerEnum(name: string, raws: ReadonlyArray<number>, emit: (d: D) => void): T;
63
+ }
64
+ /**
65
+ * Resolve a union-shaped `IR.SchemaObject` to a target type. Wraps
66
+ * `classifyUnion` with per-target hooks for each branch.
67
+ */
68
+ export declare function unionToType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): T;
69
+ /**
70
+ * Resolve an inline object schema to a target type. Three-way
71
+ * dispatch via `classifyObjectShape`, then per-target rendering:
72
+ *
73
+ * - named-struct → synth a name, build + emit struct, return ref
74
+ * - map → wrap value type in the target's map
75
+ * - open-map → map<string, any>
76
+ */
77
+ export declare function inlineObjectType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): T;
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`.
83
+ */
84
+ export declare function schemaToType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
85
+ export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
86
+ //# sourceMappingURL=dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,sBAAsB,EAGvB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,KAAK,cAAc,EACpB,MAAM,aAAa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iterals, } 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
+ */
9
+ export function unionToType(schema, ctx, ops, dispatch) {
10
+ const shape = classifyUnion(schema);
11
+ switch (shape.kind) {
12
+ case "intersection-with-properties":
13
+ return inlineObjectType(schema, ctx, ops, dispatch);
14
+ case "intersection-empty":
15
+ return ops.anyType();
16
+ case "single":
17
+ return ops.wrapForUnionSingle(dispatch(shape.inner, ctx), shape.nullable);
18
+ case "multi":
19
+ return ops.unionFallback(shape.nullable);
20
+ }
21
+ }
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
+ export function inlineObjectType(schema, ctx, ops, dispatch) {
31
+ const shape = classifyObjectShape(schema);
32
+ switch (shape.kind) {
33
+ case "named-struct": {
34
+ const name = ops.synthName(ctx.ownerName, ctx.propPath);
35
+ const properties = Array.from(iterateObjectProperties(schema));
36
+ ctx.emit(ops.buildStructDecl(name, properties, ctx, dispatch));
37
+ return ops.refType(name);
38
+ }
39
+ case "map":
40
+ return ops.mapType(dispatch(shape.valueSchema, ctx));
41
+ case "open-map":
42
+ return ops.mapType(ops.anyType());
43
+ }
44
+ }
45
+ /**
46
+ * Top-level dispatch from `IR.SchemaObject` to a target type. Routes
47
+ * each schema shape to the appropriate handler (`unionToType` /
48
+ * `inlineObjectType` / per-target enum emitter / target leaf
49
+ * constructor). The per-target leaf decisions live in `ops`.
50
+ */
51
+ export function schemaToType(schema, ctx, ops) {
52
+ const dispatch = (s, c) => schemaToType(s, c, ops);
53
+ if (schema.$ref)
54
+ return ops.refType(refName(schema.$ref));
55
+ // Untyped item-bearing schema → union (oneOf/anyOf, possibly nullable).
56
+ if (schema.items && schema.items.length > 0 && !schema.type) {
57
+ return unionToType(schema, ctx, ops, dispatch);
58
+ }
59
+ const primitive = ops.primitiveType(schema);
60
+ if (primitive !== undefined)
61
+ return primitive;
62
+ switch (schema.type) {
63
+ case "array": {
64
+ const elem = schema.items?.[0];
65
+ return ops.arrayType(elem ? dispatch(elem, ctx) : ops.anyType());
66
+ }
67
+ case "tuple":
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);
87
+ }
88
+ case "object":
89
+ return inlineObjectType(schema, ctx, ops, dispatch);
90
+ case "null":
91
+ return ops.nullableAnyType();
92
+ case "never":
93
+ case "void":
94
+ case "undefined":
95
+ return ops.voidType();
96
+ default:
97
+ return ops.anyType();
98
+ }
99
+ }
100
+ // Re-export so emitters can import everything from one place.
101
+ export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
102
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/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ACb,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW;YACd,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;QACxB;YACE,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,GACxB,CAAC"}
@@ -0,0 +1,42 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,49 @@
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
@@ -0,0 +1 @@
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,G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,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"}
@@ -0,0 +1,53 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,36 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,35 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,29 @@
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
@@ -0,0 +1 @@
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"}