@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
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ahmed Rowaihi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # `@ir-kit/openapi`
2
+
3
+ Language-agnostic IR-walking primitives for OpenAPI codegen. This package owns all the **pre-work** every native-SDK emitter needs (parsing the spec into shape, classifying schemas / responses / bodies, iterating paths × methods, deriving canonical names, walking template strings). Per-language emitters (`@ir-kit/openapi-{go,kotlin,swift}`) consume these primitives + provide their own **render** layer, never re-walking the spec themselves.
4
+
5
+ The shape of the consolidation:
6
+
7
+ ```
8
+ IR.SchemaObject / IR.OperationObject (hey-api shared types)
9
+ │
10
+ ▼
11
+ @ir-kit/openapi (this package)
12
+ ┌────────────────────────────┐
13
+ │ pure walks: │
14
+ │ iterOperations │
15
+ │ collectLocatedParams │
16
+ │ classifyBody │
17
+ │ classifyReturnShape │
18
+ │ classifyUnion │
19
+ │ classifyObjectShape │
20
+ │ classifyEnumLiterals │
21
+ │ iterateObjectProperties │
22
+ │ parseTemplatedSegment │
23
+ │ splitPathSegments │
24
+ │ deriveBaseName │
25
+ │ ... │
26
+ │ │
27
+ │ generic dispatchers: │
28
+ │ schemaToType<T,D>(...) │
29
+ │ unionToType<T,D>(...) │
30
+ │ inlineObjectType<T,D>(.) │
31
+ └────────────┬───────────────┘
32
+ │ ops: SchemaToTypeOps<T, D>
33
+ ┌─────────────────────┼─────────────────────┐
34
+ ▼ ▼ ▼
35
+ @ir-kit/openapi-go @ir-kit/openapi-kotlin @ir-kit/openapi-swift
36
+ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
37
+ │ goOps (renders): │ │ ktOps (renders): │ │ swOps (renders): │
38
+ │ • goPtr/goSlice │ │ • ktNullable │ │ • swOptional │
39
+ │ • goStruct │ │ • ktDataClass │ │ • swStruct │
40
+ │ • const blocks │ │ • @Serializable │ │ • CodingKeys │
41
+ │ • net/http │ │ • OkHttp │ │ • URLSession │
42
+ └──────────────────┘ └──────────────────┘ └──────────────────┘
43
+ ```
44
+
45
+ ## Why a shared dispatcher
46
+
47
+ Before this package existed, each of the three native emitters had a full copy of `schemaToType`, `unionToType`, `inlineObjectType`, `buildEnumFromIR`, `typeForPrimitive` — plus their own walks over the spec. About 900 LOC of nearly-identical control flow per emitter (~2.7k total) drifted constantly: one emitter would gain a fix the others missed; one would use `pascal(jsonKey)` and another would use `safeIdent(jsonKey)` for the same role.
48
+
49
+ Consolidating into `@ir-kit/openapi` + a per-emitter `SchemaToTypeOps<T, D>` record means:
50
+
51
+ - **One source of truth for spec walks.** Adding a new OpenAPI feature (e.g. handling `discriminator`) lands in one file; all emitters pick it up.
52
+ - **Per-target rendering stays per-target.** Go's pointer-wrap is in `goOps.wrapForUnionSingle`; Kotlin's nullable wrap is in `ktOps.wrapForUnionSingle`. Neither leaks into the other; the dispatcher doesn't care which one is "right".
53
+ - **Type-safety on the contract.** `SchemaToTypeOps<T, D>` is generic over the target type `T` (`GoType` / `KtType` / `SwType`) and decl type `D`. Each emitter gets type errors at compile time if it omits a hook or returns the wrong shape.
54
+
55
+ ## The `SchemaToTypeOps<T, D>` interface
56
+
57
+ Every emitter implements ~13 hooks in one record (`packages/openapi/<lang>/src/ir/type-ops.ts`):
58
+
59
+ ```ts
60
+ interface SchemaToTypeOps<T, D> {
61
+ // Leaf constructors
62
+ refType(name: string): T;
63
+ arrayType(elem: T): T;
64
+ mapType(value: T): T;
65
+ voidType(): T;
66
+ anyType(): T;
67
+ nullableAnyType(): T;
68
+ wrapForUnionSingle(inner: T, nullable: boolean): T;
69
+ unionFallback(nullable: boolean): T;
70
+ primitiveType(schema: IR.SchemaObject): T | undefined;
71
+
72
+ // Naming
73
+ synthName(ownerName: string, propPath: ReadonlyArray<string>): string;
74
+
75
+ // Composites (the dispatcher calls these when it sees the matching shape)
76
+ buildStructDecl(
77
+ name: string,
78
+ properties: ReadonlyArray<ObjectProperty>,
79
+ ctx: TypeCtx<D>,
80
+ dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T,
81
+ ): D;
82
+ emitStringEnum(
83
+ name: string,
84
+ raws: ReadonlyArray<string>,
85
+ emit: (d: D) => void,
86
+ ): T;
87
+ emitIntegerEnum(
88
+ name: string,
89
+ raws: ReadonlyArray<number>,
90
+ emit: (d: D) => void,
91
+ ): T;
92
+ }
93
+ ```
94
+
95
+ Hooks receive `dispatch` so they can recurse back into `schemaToType` when they need an inner type — e.g. `buildStructDecl` calls `dispatch(propSchema, childCtx)` for every property.
96
+
97
+ ## Reading order
98
+
99
+ If you're picking up this package for the first time:
100
+
101
+ 1. **`src/type/dispatch.ts`** — the `schemaToType<T, D>` function and the `SchemaToTypeOps<T, D>` interface. Start here.
102
+ 2. **`packages/openapi/go/src/ir/type-ops.ts`** — concrete implementation of every hook. Smallest of the three emitters; the simplest read.
103
+ 3. **`src/type/{union,object,enum}.ts`** — the classifiers the dispatcher uses (`classifyUnion`, `classifyObjectShape`, `classifyEnumLiterals`, `iterateObjectProperties`, `assertNoEnumCollisions`). Pure functions over hey-api's IR.
104
+ 4. **`src/operation/*`** — operation-level walks (`iterOperations`, `collectLocatedParams`, `successResponses`, `classifyReturnShape`, `parseTemplatedSegment`, `deriveBaseName`, etc.). Each emitter's per-tag method generation calls into these.
105
+
106
+ ## Conventions
107
+
108
+ - **Pre-work belongs here. Render belongs per-emitter.** When you find a `Object.entries(schema.properties).filter(...)` chain open-coded in two emitters, it goes here. When you find a `goPtr` / `ktNullable` / `swOptional` choice, it stays per-emitter.
109
+
110
+ - **Classifiers return tagged-union shapes.** `classifyBody(body) → BodyShape`, `classifyUnion(schema) → UnionShape`, `classifyReturnShape(op) → ReturnShape`. Callers switch on `kind`. Adding a new variant ripples through the type checker so every consumer either handles it or fails to compile.
111
+
112
+ - **Walks are generators, not arrays.** `iterOperations`, `iterateObjectProperties`. Lets callers short-circuit or filter without paying for a full list build. Callers that need an array do `Array.from(...)`.
113
+
114
+ - **No target imports.** This package depends on `@hey-api/shared` (for IR types), `@ir-kit/openapi-core` (for ref / security / constants), and `@ir-kit/codegen-core` (for `pascal`, `synthName`). It does NOT depend on any go-dsl / kt-dsl / sw-dsl module.
115
+
116
+ ## Adding a new shared walk
117
+
118
+ When you spot duplication in `@ir-kit/openapi-{go,kotlin,swift}`:
119
+
120
+ 1. Identify the **pre-work** (what does the IR walk produce that's target-neutral?) vs the **render** (what's the target-specific shape it gets wrapped in?).
121
+ 2. Add the pre-work helper to this package — pure function, generator, or classifier.
122
+ 3. Update each emitter to consume it. Verify the petstore SDK regen is byte-identical (the repo's `examples/petstore-sdk/` is the canonical fixture).
123
+ 4. Land in one commit per emitter pass for clean git history.
124
+
125
+ If the duplication is in render — different code paths producing structurally-different target code — it stays per-emitter. Push back on consolidating principled language differences just because they look similar.
126
+
127
+ ## Status
128
+
129
+ `0.1.0` ships the dispatcher + ~16 pre-work helpers + the `SchemaToTypeOps` interface. The three native SDK emitters (`@ir-kit/openapi-{go,kotlin,swift}`) consume it; the TypeScript emitter (`@ir-kit/openapi-typescript`) wraps `@hey-api/openapi-ts` and bypasses the dispatcher entirely (hey-api owns its own IR walk).
130
+
131
+ Petstore SDK output for go + swift is byte-identical pre- and post-consolidation across all dispatcher migrations — this is the regression bar.
@@ -0,0 +1,21 @@
1
+ export type { BodyShape } from "./operation/body.js";
2
+ export { classifyBody, isOpaqueJsonBody } from "./operation/body.js";
3
+ export type { IteratedOperation } from "./operation/iter.js";
4
+ export { iterOperations } from "./operation/iter.js";
5
+ export type { LocatedParam, ParamLocation } from "./operation/params.js";
6
+ export { collectLocatedParams, PARAM_LOCATIONS, paramsAt, } from "./operation/params.js";
7
+ export type { ResponseCase, ReturnShape } from "./operation/responses.js";
8
+ export { classifyReturnShape, isSuccessStatus, successResponses, } from "./operation/responses.js";
9
+ export { deriveBaseName, operationDocLine, splitPathSegments, } from "./operation/signature.js";
10
+ export type { TemplatePart } from "./operation/template.js";
11
+ export { parseTemplatedSegment } from "./operation/template.js";
12
+ export type { TypeCtx } from "./type/context.js";
13
+ export type { SchemaToTypeOps } from "./type/dispatch.js";
14
+ export { schemaToType } from "./type/dispatch.js";
15
+ export type { EnumEntryIdent, EnumKind, EnumLiteral } from "./type/enum.js";
16
+ export { assertNoEnumCollisions, classifyEnumLiterals, } from "./type/enum.js";
17
+ export type { ObjectProperty, ObjectShape } from "./type/object.js";
18
+ export { classifyObjectShape, iterateObjectProperties, } from "./type/object.js";
19
+ export type { UnionShape } from "./type/union.js";
20
+ export { classifyUnion } from "./type/union.js";
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { classifyBody, isOpaqueJsonBody } from "./operation/body.js";
2
+ export { iterOperations } from "./operation/iter.js";
3
+ export { collectLocatedParams, PARAM_LOCATIONS, paramsAt, } from "./operation/params.js";
4
+ export { classifyReturnShape, isSuccessStatus, successResponses, } from "./operation/responses.js";
5
+ export { deriveBaseName, operationDocLine, splitPathSegments, } from "./operation/signature.js";
6
+ export { parseTemplatedSegment } from "./operation/template.js";
7
+ export { schemaToType } from "./type/dispatch.js";
8
+ export { assertNoEnumCollisions, classifyEnumLiterals, } from "./type/enum.js";
9
+ export { classifyObjectShape, iterateObjectProperties, } from "./type/object.js";
10
+ export { classifyUnion } from "./type/union.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,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;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { IR } from "@hey-api/shared";
2
+ /**
3
+ * `true` when a JSON-typed body has no concrete `type` but carries an
4
+ * `items[]` (typical of bare `oneOf`/`anyOf` schemas) — there's no
5
+ * cleanly-typed structure to bind to, so each emitter falls back to a
6
+ * raw byte buffer (`[]byte` / `ByteArray` / `Data`).
7
+ */
8
+ export declare function isOpaqueJsonBody(schema: IR.SchemaObject): boolean;
9
+ /**
10
+ * Outcome of inspecting `IR.BodyObject`'s media type + schema shape.
11
+ * Each emitter switches on `kind` to pick its body-param strategy.
12
+ */
13
+ export type BodyShape =
14
+ /** `application/json` with a meaningful schema. */
15
+ {
16
+ 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
+ | {
21
+ kind: "json-opaque";
22
+ }
23
+ /** `multipart/form-data` whose schema is an object — flatten props
24
+ * into one func param each. */
25
+ | {
26
+ kind: "multipart-object";
27
+ }
28
+ /** `application/x-www-form-urlencoded` whose schema is an object —
29
+ * flatten props into one func param each. */
30
+ | {
31
+ kind: "form-urlencoded-object";
32
+ }
33
+ /** Empty / octet-stream / image/* / unknown — caller pre-encodes a
34
+ * single bytes param. */
35
+ | {
36
+ kind: "opaque";
37
+ };
38
+ /**
39
+ * Classify a body by its media type + schema shape so emitters can
40
+ * dispatch identically on `kind`. The media-type matching rules are
41
+ * the same ones the generators agreed on (`@ir-kit/openapi-core`
42
+ * constants) — single source of truth.
43
+ */
44
+ export declare function classifyBody(body: IR.BodyObject): BodyShape;
45
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +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;AAO1C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,GAAG,OAAO,CAEjE;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS;AACnB,mDAAmD;AACjD;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE;AACxB;wEACwE;GACtE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE;AACzB;gCACgC;GAC9B;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE;AAC9B;8CAC8C;GAC5C;IAAE,IAAI,EAAE,wBAAwB,CAAA;CAAE;AACpC;0BAC0B;GACxB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS,CAiB3D"}
@@ -0,0 +1,34 @@
1
+ import { FORM_URLENCODED_MEDIA, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "@ir-kit/openapi-core";
2
+ /**
3
+ * `true` when a JSON-typed body has no concrete `type` but carries an
4
+ * `items[]` (typical of bare `oneOf`/`anyOf` schemas) — there's no
5
+ * cleanly-typed structure to bind to, so each emitter falls back to a
6
+ * raw byte buffer (`[]byte` / `ByteArray` / `Data`).
7
+ */
8
+ export function isOpaqueJsonBody(schema) {
9
+ return !schema.type && Array.isArray(schema.items) && schema.items.length > 0;
10
+ }
11
+ /**
12
+ * Classify a body by its media type + schema shape so emitters can
13
+ * dispatch identically on `kind`. The media-type matching rules are
14
+ * the same ones the generators agreed on (`@ir-kit/openapi-core`
15
+ * constants) — single source of truth.
16
+ */
17
+ export function classifyBody(body) {
18
+ const mt = (body.mediaType ?? "").toLowerCase();
19
+ const schema = body.schema;
20
+ const isObject = schema.type === "object" && Boolean(schema.properties);
21
+ if (mt && JSON_MEDIA_RE.test(mt)) {
22
+ return isOpaqueJsonBody(schema)
23
+ ? { kind: "json-opaque" }
24
+ : { kind: "json-typed" };
25
+ }
26
+ if (mt.startsWith(MULTIPART_FORM_MEDIA) && isObject) {
27
+ return { kind: "multipart-object" };
28
+ }
29
+ if (mt.startsWith(FORM_URLENCODED_MEDIA) && isObject) {
30
+ return { kind: "form-urlencoded-object" };
31
+ }
32
+ return { kind: "opaque" };
33
+ }
34
+ //# sourceMappingURL=body.js.map
@@ -0,0 +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,MAAuB;IACtD,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAChF,CAAC;AAsBD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC9C,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAExE,IAAI,EAAE,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACjC,OAAO,gBAAgB,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE;YACzB,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAC7B,CAAC;IACD,IAAI,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,IAAI,QAAQ,EAAE,CAAC;QACpD,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;IACtC,CAAC;IACD,IAAI,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,IAAI,QAAQ,EAAE,CAAC;QACrD,OAAO,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { IR } from "@hey-api/shared";
2
+ import { type HttpMethod } from "@ir-kit/openapi-core";
3
+ export interface IteratedOperation {
4
+ pathStr: string;
5
+ method: HttpMethod;
6
+ op: IR.OperationObject;
7
+ /** Security-scheme names resolved for this operation. Empty when no
8
+ * `schemeNames` map was passed or no entry matches `securityKey`. */
9
+ schemeNames: ReadonlyArray<string>;
10
+ }
11
+ /**
12
+ * Walk `IR.PathsObject` and yield one entry per `(path, method)` that
13
+ * carries an operation, with security-scheme names resolved up-front.
14
+ *
15
+ * Centralises the path × method nested loop, the `op = pathItem[method]`
16
+ * narrowing, and the `securityKey(pathStr, method)` lookup that every
17
+ * emitter (`operations.ts` in go / kotlin / swift) was open-coding
18
+ * identically. Order is `Object.entries(paths)` → `HTTP_METHODS` —
19
+ * stable and matches the existing emit order.
20
+ */
21
+ export declare function iterOperations(paths: IR.PathsObject | undefined, schemeNames?: ReadonlyMap<string, ReadonlyArray<string>>): Generator<IteratedOperation>;
22
+ //# sourceMappingURL=iter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iter.d.ts","sourceRoot":"","sources":["../../src/operation/iter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAEL,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC;IACvB;0EACsE;IACtE,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,wBAAiB,cAAc,CAC7B,KAAK,EAAE,EAAE,CAAC,WAAW,GAAG,SAAS,EACjC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,GACvD,SAAS,CAAC,iBAAiB,CAAC,CAa9B"}
@@ -0,0 +1,27 @@
1
+ import { HTTP_METHODS, securityKey, } from "@ir-kit/openapi-core";
2
+ /**
3
+ * Walk `IR.PathsObject` and yield one entry per `(path, method)` that
4
+ * carries an operation, with security-scheme names resolved up-front.
5
+ *
6
+ * Centralises the path × method nested loop, the `op = pathItem[method]`
7
+ * narrowing, and the `securityKey(pathStr, method)` lookup that every
8
+ * emitter (`operations.ts` in go / kotlin / swift) was open-coding
9
+ * identically. Order is `Object.entries(paths)` → `HTTP_METHODS` —
10
+ * stable and matches the existing emit order.
11
+ */
12
+ export function* iterOperations(paths, schemeNames) {
13
+ for (const [pathStr, pathItem] of Object.entries(paths ?? {})) {
14
+ for (const method of HTTP_METHODS) {
15
+ const op = pathItem[method];
16
+ if (!op)
17
+ continue;
18
+ yield {
19
+ pathStr,
20
+ method: method,
21
+ op,
22
+ schemeNames: schemeNames?.get(securityKey(pathStr, method)) ?? [],
23
+ };
24
+ }
25
+ }
26
+ }
27
+ //# sourceMappingURL=iter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iter.js","sourceRoot":"","sources":["../../src/operation/iter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAEZ,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAW9B;;;;;;;;;GASG;AACH,MAAM,SAAS,CAAC,CAAC,cAAc,CAC7B,KAAiC,EACjC,WAAwD;IAExD,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QAC9D,KAAK,MAAM,MAAM,IAAI,YAAY,EAAE,CAAC;YAClC,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAmC,CAAC;YAC9D,IAAI,CAAC,EAAE;gBAAE,SAAS;YAClB,MAAM;gBACJ,OAAO;gBACP,MAAM,EAAE,MAAoB;gBAC5B,EAAE;gBACF,WAAW,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE;aAClE,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { IR } from "@hey-api/shared";
2
+ export type ParamLocation = "path" | "query" | "header" | "cookie";
3
+ export declare const PARAM_LOCATIONS: ReadonlyArray<ParamLocation>;
4
+ export interface LocatedParam {
5
+ param: IR.ParameterObject;
6
+ loc: ParamLocation;
7
+ }
8
+ /**
9
+ * Flatten `op.parameters.{path,query,header,cookie}` into a single
10
+ * array, preserving the location each came from. Result order follows
11
+ * `PARAM_LOCATIONS` (path → query → header → cookie), and within each
12
+ * bucket follows `Object.values` iteration order.
13
+ *
14
+ * Emitters typically further filter (e.g. Go drops cookies) and sort
15
+ * (required-first); those decisions stay per-target.
16
+ */
17
+ export declare function collectLocatedParams(op: IR.OperationObject): LocatedParam[];
18
+ /**
19
+ * Extract just the `IR.ParameterObject`s at a given location from a
20
+ * pre-collected `LocatedParam[]` (typically the `located` from
21
+ * `operationSignature`'s return value). The pattern
22
+ * `located.filter((l) => l.loc === "<loc>").map((l) => l.param)`
23
+ * appeared in every emitter's `impl/url.ts` (path + query) and
24
+ * `impl/headers.ts` (header) — 9 callsites total.
25
+ */
26
+ export declare function paramsAt(located: ReadonlyArray<LocatedParam>, loc: ParamLocation): IR.ParameterObject[];
27
+ //# sourceMappingURL=params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/operation/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnE,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,aAAa,CAKxD,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,GAAG,YAAY,EAAE,CAQ3E;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,EACpC,GAAG,EAAE,aAAa,GACjB,EAAE,CAAC,eAAe,EAAE,CAEtB"}
@@ -0,0 +1,38 @@
1
+ export const PARAM_LOCATIONS = [
2
+ "path",
3
+ "query",
4
+ "header",
5
+ "cookie",
6
+ ];
7
+ /**
8
+ * Flatten `op.parameters.{path,query,header,cookie}` into a single
9
+ * array, preserving the location each came from. Result order follows
10
+ * `PARAM_LOCATIONS` (path → query → header → cookie), and within each
11
+ * bucket follows `Object.values` iteration order.
12
+ *
13
+ * Emitters typically further filter (e.g. Go drops cookies) and sort
14
+ * (required-first); those decisions stay per-target.
15
+ */
16
+ export function collectLocatedParams(op) {
17
+ const out = [];
18
+ for (const loc of PARAM_LOCATIONS) {
19
+ const bucket = op.parameters?.[loc];
20
+ if (!bucket)
21
+ continue;
22
+ for (const param of Object.values(bucket))
23
+ out.push({ param, loc });
24
+ }
25
+ return out;
26
+ }
27
+ /**
28
+ * Extract just the `IR.ParameterObject`s at a given location from a
29
+ * pre-collected `LocatedParam[]` (typically the `located` from
30
+ * `operationSignature`'s return value). The pattern
31
+ * `located.filter((l) => l.loc === "<loc>").map((l) => l.param)`
32
+ * appeared in every emitter's `impl/url.ts` (path + query) and
33
+ * `impl/headers.ts` (header) — 9 callsites total.
34
+ */
35
+ export function paramsAt(located, loc) {
36
+ return located.filter((l) => l.loc === loc).map((l) => l.param);
37
+ }
38
+ //# sourceMappingURL=params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/operation/params.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,eAAe,GAAiC;IAC3D,MAAM;IACN,OAAO;IACP,QAAQ;IACR,QAAQ;CACT,CAAC;AAOF;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAsB;IACzD,MAAM,GAAG,GAAmB,EAAE,CAAC;IAC/B,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM;YAAE,SAAS;QACtB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAoC,EACpC,GAAkB;IAElB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,58 @@
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
+ */
7
+ export declare const isSuccessStatus: (code: string) => boolean;
8
+ /**
9
+ * Return the operation's 2xx responses as `[code, response]` tuples,
10
+ * sorted by code for stable per-target emission order.
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.
14
+ */
15
+ export declare function successResponses(op: IR.OperationObject): Array<readonly [string, IR.ResponseObject]>;
16
+ /**
17
+ * One arm of a multi-2xx sum-type return. Each emitter parameterises
18
+ * `T` with its own target type (`GoType`, `KtType`, `SwType`) for the
19
+ * decoded payload. `payloadType` is omitted for empty bodies (e.g. 204).
20
+ */
21
+ export interface ResponseCase<T> {
22
+ statusCode: string;
23
+ caseName: string;
24
+ payloadType?: T;
25
+ }
26
+ /**
27
+ * Shape of an operation's success return, normalised so each emitter
28
+ * can switch on `kind` instead of re-deriving the same 4-way logic
29
+ * (no successes, single empty, single typed, multi-case) from the
30
+ * `successResponses` array.
31
+ */
32
+ export type ReturnShape =
33
+ /** Either no 2xx responses at all, or a single 2xx whose schema is
34
+ * empty / meaningless. Caller renders its Unit / Void analog. */
35
+ {
36
+ kind: "void";
37
+ }
38
+ /** Single 2xx response with a non-empty schema. Caller calls
39
+ * `schemaToType(schema)` and uses the result as the return. */
40
+ | {
41
+ kind: "single";
42
+ schema: IR.SchemaObject;
43
+ }
44
+ /** Multiple 2xx responses. Caller emits a sum-type (Go interface,
45
+ * Kotlin sealed class, Swift enum) and dispatches on status. */
46
+ | {
47
+ kind: "multi";
48
+ cases: ReadonlyArray<readonly [string, IR.ResponseObject]>;
49
+ };
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
+ export declare function classifyReturnShape(op: IR.OperationObject): ReturnShape;
58
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +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;AAG1C;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,OAA+B,CAAC;AAE/E;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,EAAE,CAAC,eAAe,GACrB,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAM7C;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,CAAC,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW;AACrB;kEACkE;AAChE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;AAClB;gEACgE;GAC9D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAA;CAAE;AAC7C;iEACiE;GAC/D;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;CAC5D,CAAC;AAEN;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,GAAG,WAAW,CASvE"}
@@ -0,0 +1,39 @@
1
+ import { isMeaningless } from "@ir-kit/openapi-core";
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
+ export const isSuccessStatus = (code) => /^2\d\d$/.test(code);
8
+ /**
9
+ * Return the operation's 2xx responses as `[code, response]` tuples,
10
+ * sorted by code for stable per-target emission order.
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.
14
+ */
15
+ export function successResponses(op) {
16
+ return Object.entries(op.responses ?? {})
17
+ .filter(([k]) => isSuccessStatus(k))
18
+ .sort(([a], [b]) => a.localeCompare(b));
19
+ }
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
+ export function classifyReturnShape(op) {
28
+ const success = successResponses(op);
29
+ if (success.length === 0)
30
+ return { kind: "void" };
31
+ if (success.length === 1) {
32
+ const [, resp] = success[0];
33
+ if (!resp?.schema || isMeaningless(resp.schema))
34
+ return { kind: "void" };
35
+ return { kind: "single", schema: resp.schema };
36
+ }
37
+ return { kind: "multi", cases: success };
38
+ }
39
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE/E;;;;;;GAMG;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;AAiCD;;;;;;GAMG;AACH,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,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACzE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { IR } from "@hey-api/shared";
2
+ import { type HttpMethod } from "@ir-kit/openapi-core";
3
+ /**
4
+ * Derive the canonical *base* name for an operation — the unstyled
5
+ * identifier each emitter then runs through its own case transform
6
+ * (`exportedIdent` for Go, `camel` + `pascal` for Kotlin / Swift).
7
+ *
8
+ * - When `op.operationId` is present, prefer it verbatim. Producers
9
+ * are expected to write it in a sensible casing already; let the
10
+ * emitter normalise.
11
+ * - Otherwise, derive from `<method>_<segments...>` with curly braces
12
+ * stripped from path templates. Underscore form is the lowest
13
+ * common denominator: PascalCase / camelCase / snake_case can all
14
+ * be re-derived from it.
15
+ */
16
+ export declare function deriveBaseName(op: IR.OperationObject, method: HttpMethod, path: string): string;
17
+ /**
18
+ * Standard one-line doc comment every emitter puts on a generated
19
+ * operation method: `<METHOD> <path>`.
20
+ */
21
+ export declare function operationDocLine(method: HttpMethod, pathStr: string): string;
22
+ /**
23
+ * Split a templated OpenAPI path (`/pets/{id}/photos`) into its
24
+ * non-empty segments (`["pets", "{id}", "photos"]`), trimming a
25
+ * leading `/`. Each emitter's URL builder iterates these to append
26
+ * to the target's URL/baseURL value.
27
+ */
28
+ export declare function splitPathSegments(pathStr: string): string[];
29
+ //# sourceMappingURL=signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/operation/signature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,GACX,MAAM,CAOR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAG3D"}
@@ -0,0 +1,41 @@
1
+ import { HTTP_METHOD_LITERAL } from "@ir-kit/openapi-core";
2
+ /**
3
+ * Derive the canonical *base* name for an operation — the unstyled
4
+ * identifier each emitter then runs through its own case transform
5
+ * (`exportedIdent` for Go, `camel` + `pascal` for Kotlin / Swift).
6
+ *
7
+ * - When `op.operationId` is present, prefer it verbatim. Producers
8
+ * are expected to write it in a sensible casing already; let the
9
+ * emitter normalise.
10
+ * - Otherwise, derive from `<method>_<segments...>` with curly braces
11
+ * stripped from path templates. Underscore form is the lowest
12
+ * common denominator: PascalCase / camelCase / snake_case can all
13
+ * be re-derived from it.
14
+ */
15
+ export function deriveBaseName(op, method, path) {
16
+ if (op.operationId)
17
+ return op.operationId;
18
+ const segments = path
19
+ .split("/")
20
+ .filter(Boolean)
21
+ .map((s) => s.replace(/[{}]/g, ""));
22
+ return [method, ...segments].join("_") || method;
23
+ }
24
+ /**
25
+ * Standard one-line doc comment every emitter puts on a generated
26
+ * operation method: `<METHOD> <path>`.
27
+ */
28
+ export function operationDocLine(method, pathStr) {
29
+ return `${HTTP_METHOD_LITERAL[method]} ${pathStr}`;
30
+ }
31
+ /**
32
+ * Split a templated OpenAPI path (`/pets/{id}/photos`) into its
33
+ * non-empty segments (`["pets", "{id}", "photos"]`), trimming a
34
+ * leading `/`. Each emitter's URL builder iterates these to append
35
+ * to the target's URL/baseURL value.
36
+ */
37
+ export function splitPathSegments(pathStr) {
38
+ const stripped = pathStr.startsWith("/") ? pathStr.slice(1) : pathStr;
39
+ return stripped.split("/").filter((s) => s.length > 0);
40
+ }
41
+ //# sourceMappingURL=signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/operation/signature.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAmB,MAAM,sBAAsB,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAC5B,EAAsB,EACtB,MAAkB,EAClB,IAAY;IAEZ,IAAI,EAAE,CAAC,WAAW;QAAE,OAAO,EAAE,CAAC,WAAW,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAI;SAClB,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACtC,OAAO,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB,EAAE,OAAe;IAClE,OAAO,GAAG,mBAAmB,CAAC,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACtE,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACzD,CAAC"}