@ir-kit/openapi 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +7 -10
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +5 -6
  5. package/dist/index.js.map +1 -1
  6. package/dist/operation/body.d.ts +23 -30
  7. package/dist/operation/body.d.ts.map +1 -1
  8. package/dist/operation/body.js +23 -15
  9. package/dist/operation/body.js.map +1 -1
  10. package/dist/operation/responses.d.ts +14 -34
  11. package/dist/operation/responses.d.ts.map +1 -1
  12. package/dist/operation/responses.js +20 -20
  13. package/dist/operation/responses.js.map +1 -1
  14. package/dist/spec/normalize/index.d.ts +1 -0
  15. package/dist/spec/normalize/index.d.ts.map +1 -1
  16. package/dist/spec/normalize/index.js +1 -0
  17. package/dist/spec/normalize/index.js.map +1 -1
  18. package/dist/spec/normalize/refs.d.ts +8 -0
  19. package/dist/spec/normalize/refs.d.ts.map +1 -0
  20. package/dist/spec/normalize/refs.js +98 -0
  21. package/dist/spec/normalize/refs.js.map +1 -0
  22. package/dist/spec/ref.d.ts +4 -14
  23. package/dist/spec/ref.d.ts.map +1 -1
  24. package/dist/spec/ref.js +8 -22
  25. package/dist/spec/ref.js.map +1 -1
  26. package/dist/type/context.d.ts +6 -0
  27. package/dist/type/context.d.ts.map +1 -1
  28. package/dist/type/dispatch.d.ts +51 -64
  29. package/dist/type/dispatch.d.ts.map +1 -1
  30. package/dist/type/dispatch.js +71 -56
  31. package/dist/type/dispatch.js.map +1 -1
  32. package/package.json +6 -5
  33. package/dist/type/enum.d.ts +0 -42
  34. package/dist/type/enum.d.ts.map +0 -1
  35. package/dist/type/enum.js +0 -49
  36. package/dist/type/enum.js.map +0 -1
  37. package/dist/type/object.d.ts +0 -53
  38. package/dist/type/object.d.ts.map +0 -1
  39. package/dist/type/object.js +0 -36
  40. package/dist/type/object.js.map +0 -1
  41. package/dist/type/union.d.ts +0 -35
  42. package/dist/type/union.d.ts.map +0 -1
  43. package/dist/type/union.js +0 -29
  44. package/dist/type/union.js.map +0 -1
@@ -8,8 +8,14 @@
8
8
  * `propPath` drive deterministic names for those synthesised types
9
9
  * (e.g. `Owner_Path`).
10
10
  */
11
+ import type { Namespace } from "@ir-kit/codegen-core";
11
12
  export interface TypeCtx<D> {
12
13
  emit: (d: D) => void;
14
+ /** Owns every top-level type name for one generation run. Component
15
+ * schemas, `$ref`s and synthesized inline types all resolve through
16
+ * it, so a name is spelled the same at every site and never declared
17
+ * twice. */
18
+ names: Namespace;
13
19
  /** Used to synthesise names for inline objects/enums: `Owner_Path`. */
14
20
  ownerName: string;
15
21
  propPath: ReadonlyArray<string>;
@@ -1 +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"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/type/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IACrB;;;iBAGa;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACjC"}
@@ -1,86 +1,73 @@
1
- import type { IR } from "@hey-api/shared";
1
+ import type { Namespace } from "@ir-kit/codegen-core";
2
+ import { type EnumLiteral, type ObjectProperty, type Schema } from "@ir-kit/schema";
2
3
  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
4
  /**
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).
5
+ * Per-target leaf operations the shared dispatchers (`schemaToType`,
6
+ * `unionToType`, `inlineObjectType`) call into. `T` is the emitter's
7
+ * target type (`GoType` / `KtType` / `SwType`), `D` its decl type.
11
8
  *
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.
9
+ * Each emitter writes one of these records. All per-target rendering
10
+ * (pointer vs nullable, naming conventions, synthName joiner, decl
11
+ * construction) lives here; the dispatchers stay neutral.
16
12
  */
17
13
  export interface SchemaToTypeOps<T, D> {
18
- /** `$ref` → named target type. */
19
14
  refType(name: string): T;
20
- /** Array element → target array/slice/list type. */
21
15
  arrayType(elem: T): T;
22
- /** Open object's value type — target map's value-of-Any. */
23
16
  mapType(valueType: T): T;
24
- /** "No return" analog — `goAny` (Go callers drop the result slot),
17
+ /** Caller's "no return" analog — `goAny` (drops the result slot),
25
18
  * `ktUnit`, `swVoid`. */
26
19
  voidType(): T;
27
- /** Untyped fallback — `goAny` / `ktAny` / `swAny`. */
20
+ /** Caller's untyped fallback — `goAny` / `ktAny` / `swAny`. */
28
21
  anyType(): T;
29
- /** Standalone nullable-any — what `null`-typed primitives become.
30
- * Go wraps any in pointer; Kotlin / Swift wrap in nullable/optional. */
22
+ /** Standalone nullable-any — what `null`-typed primitives become. */
31
23
  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. */
24
+ /** Wrap a known type in the target's optional wrapper for the union
25
+ * "single + nullable" path. Go's choice is conditional
26
+ * (`isPointerable`), so the hook receives both the inner type and
27
+ * the nullable bit. */
36
28
  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. */
29
+ /** Fallback type for unions with 2+ non-null branches. Go ignores
30
+ * `nullable` (interface already holds nil); Kotlin / Swift wrap. */
40
31
  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 `"_"`. */
32
+ /** Primitive dispatch. Returns `undefined` for non-primitive schemas
33
+ * so the outer dispatcher can fall through. */
34
+ primitiveType(schema: Schema): T | undefined;
35
+ /** Build a synth name from `ctx.ownerName` + `propPath`. Joiner is
36
+ * per-target — Go uses `""` to keep `go vet` quiet, Kotlin / Swift
37
+ * use `"_"`. */
48
38
  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;
39
+ buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): D;
40
+ emitStringEnum(name: string, raws: ReadonlyArray<string>, emit: (d: D) => void, names: Namespace): T;
41
+ emitIntegerEnum(name: string, raws: ReadonlyArray<number>, emit: (d: D) => void, names: Namespace): T;
63
42
  }
43
+ export declare function unionToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
44
+ export declare function inlineObjectType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
64
45
  /**
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:
46
+ * Top-level dispatch from a canonical {@link Schema} to a target type.
47
+ * Routes each schema shape to the appropriate handler (`unionToType` /
48
+ * `inlineObjectType` / per-target enum emitter / target leaf constructor).
49
+ * Per-target leaf decisions live in `ops`.
72
50
  *
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>
51
+ * Dispatch order:
52
+ * 1. `$ref` → named ref
53
+ * 2. enum (`enum: [...]` or `oneOf`-of-consts)
54
+ * 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
55
+ * 4. primitive (per-target hook decides)
56
+ * 5. compound by `type` (array / object / null)
76
57
  */
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;
58
+ export declare function schemaToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
59
+ /** Type name for the component schema `rawName` (`#/components/schemas/<rawName>`). */
60
+ export declare function schemaTypeName(names: Namespace, rawName: string): string;
61
+ /** Type name for the inline schema at `ctx.ownerName` + `ctx.propPath`. */
62
+ export declare function synthTypeName<T, D>(ctx: TypeCtx<D>, ops: Pick<SchemaToTypeOps<T, D>, "synthName">, path?: ReadonlyArray<string>): string;
78
63
  /**
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`.
64
+ * Map enum literals onto a target type. String / integer domains emit a
65
+ * named enum (`named: true`); number / boolean domains become the
66
+ * matching primitive and mixed domains the untyped fallback — those
67
+ * leave `name` unused so the caller decides whether to alias it.
83
68
  */
84
- export declare function schemaToType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
85
- export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
69
+ export declare function enumType<T, D>(name: string, literals: ReadonlyArray<EnumLiteral>, ops: SchemaToTypeOps<T, D>, { emit, names }: Pick<TypeCtx<D>, "emit" | "names">): {
70
+ type: T;
71
+ named: boolean;
72
+ };
86
73
  //# sourceMappingURL=dispatch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AA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CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,CAAC,CA0CH;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAChC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EACf,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,EAC7C,IAAI,GAAE,aAAa,CAAC,MAAM,CAAgB,GACzC,MAAM,CAKR;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,CAAC,WAAW,CAAC,EACpC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAClD;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAyB7B"}
@@ -1,11 +1,4 @@
1
- import { refName } from "../spec/ref.js";
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,19 +12,11 @@ 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 = classifyObjectShape(schema);
16
+ const shape = classifyObject(schema);
32
17
  switch (shape.kind) {
33
18
  case "named-struct": {
34
- const name = ops.synthName(ctx.ownerName, ctx.propPath);
19
+ const name = synthTypeName(ctx, ops);
35
20
  const properties = Array.from(iterateObjectProperties(schema));
36
21
  ctx.emit(ops.buildStructDecl(name, properties, ctx, dispatch));
37
22
  return ops.refType(name);
@@ -43,60 +28,90 @@ export function inlineObjectType(schema, ctx, ops, dispatch) {
43
28
  }
44
29
  }
45
30
  /**
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`.
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
- 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);
46
+ return ops.refType(schemaTypeName(ctx.names, refName(schema.$ref)));
47
+ const enumValues = extractEnumValues(schema);
48
+ if (enumValues && enumValues.length > 0) {
49
+ const literals = enumValues.filter((v) => typeof v === "string" ||
50
+ typeof v === "number" ||
51
+ typeof v === "boolean");
52
+ const kind = classifyEnumLiterals(literals);
53
+ const name = kind === "string" || kind === "integer" ? synthTypeName(ctx, ops) : "";
54
+ return enumType(name, literals, ops, ctx).type;
58
55
  }
56
+ if (isUnionShape(schema))
57
+ return unionToType(schema, ctx, ops, dispatch);
59
58
  const primitive = ops.primitiveType(schema);
60
59
  if (primitive !== undefined)
61
60
  return primitive;
62
- switch (schema.type) {
61
+ const t = Array.isArray(schema.type) ? schema.type[0] : schema.type;
62
+ switch (t) {
63
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);
64
+ const items = schema.items;
65
+ return ops.arrayType(items && isSchemaObject(items)
66
+ ? dispatch(items, ctx)
67
+ : ops.anyType());
87
68
  }
88
69
  case "object":
89
70
  return inlineObjectType(schema, ctx, ops, dispatch);
90
71
  case "null":
91
72
  return ops.nullableAnyType();
92
- case "never":
93
- case "void":
94
- case "undefined":
95
- return ops.voidType();
96
73
  default:
97
74
  return ops.anyType();
98
75
  }
99
76
  }
100
- // Re-export so emitters can import everything from one place.
101
- export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
77
+ /** Type name for the component schema `rawName` (`#/components/schemas/<rawName>`). */
78
+ export function schemaTypeName(names, rawName) {
79
+ return names.claim(`schema:${rawName}`, rawName);
80
+ }
81
+ /** Type name for the inline schema at `ctx.ownerName` + `ctx.propPath`. */
82
+ export function synthTypeName(ctx, ops, path = ctx.propPath) {
83
+ return ctx.names.claim(`synth:${ctx.ownerName}/${path.join("/")}`, ops.synthName(ctx.ownerName, path));
84
+ }
85
+ /**
86
+ * Map enum literals onto a target type. String / integer domains emit a
87
+ * named enum (`named: true`); number / boolean domains become the
88
+ * matching primitive and mixed domains the untyped fallback — those
89
+ * leave `name` unused so the caller decides whether to alias it.
90
+ */
91
+ export function enumType(name, literals, ops, { emit, names }) {
92
+ switch (classifyEnumLiterals(literals)) {
93
+ case "string":
94
+ return {
95
+ type: ops.emitStringEnum(name, literals, emit, names),
96
+ named: true,
97
+ };
98
+ case "integer":
99
+ return {
100
+ type: ops.emitIntegerEnum(name, literals, emit, names),
101
+ named: true,
102
+ };
103
+ case "number":
104
+ return {
105
+ type: ops.primitiveType({ type: "number" }) ?? ops.anyType(),
106
+ named: false,
107
+ };
108
+ case "boolean":
109
+ return {
110
+ type: ops.primitiveType({ type: "boolean" }) ?? ops.anyType(),
111
+ named: false,
112
+ };
113
+ case "mixed":
114
+ return { type: ops.anyType(), named: false };
115
+ }
116
+ }
102
117
  //# sourceMappingURL=dispatch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EACL,sBAAsB,EACtB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IAAI,EAAE,SAAS,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE;gBAC7D,KAAK,EAAE,KAAK;aACb,CAAC;QACJ,KAAK,OAAO;YACV,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACjD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ir-kit/openapi",
3
- "version": "0.2.0",
3
+ "version": "0.4.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",
@@ -8,9 +8,9 @@
8
8
  "codegen",
9
9
  "sdk"
10
10
  ],
11
- "homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/openapi/ir",
11
+ "homepage": "https://github.com/ahmedrowaihi/ir-kit/tree/main/packages/openapi/ir",
12
12
  "bugs": {
13
- "url": "https://github.com/ir-kit/ir-kit/issues"
13
+ "url": "https://github.com/ahmedrowaihi/ir-kit/issues"
14
14
  },
15
15
  "license": "MIT",
16
16
  "author": {
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "git+https://github.com/ir-kit/ir-kit.git",
22
+ "url": "git+https://github.com/ahmedrowaihi/ir-kit.git",
23
23
  "directory": "packages/openapi/ir"
24
24
  },
25
25
  "type": "module",
@@ -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.2.0",
59
+ "@ir-kit/schema": "0.3.0"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "tsc -p tsconfig.build.json",
@@ -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
@@ -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
@@ -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"}
@@ -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"}
@@ -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
@@ -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"}