@ir-kit/openapi-kotlin 2.0.0 → 2.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.
- package/README.md +13 -13
- package/dist/ast/index.d.ts +168 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +194 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +7 -7
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ir/identifiers.d.ts +7 -0
- package/dist/ir/identifiers.d.ts.map +1 -1
- package/dist/ir/identifiers.js +92 -3
- package/dist/ir/identifiers.js.map +1 -1
- package/dist/ir/impl/body.d.ts +4 -3
- package/dist/ir/impl/body.d.ts.map +1 -1
- package/dist/ir/impl/body.js +11 -8
- package/dist/ir/impl/body.js.map +1 -1
- package/dist/ir/impl/decode.d.ts +3 -2
- package/dist/ir/impl/decode.d.ts.map +1 -1
- package/dist/ir/impl/decode.js +16 -16
- package/dist/ir/impl/decode.js.map +1 -1
- package/dist/ir/impl/headers.d.ts +1 -1
- package/dist/ir/impl/headers.d.ts.map +1 -1
- package/dist/ir/impl/headers.js +3 -3
- package/dist/ir/impl/headers.js.map +1 -1
- package/dist/ir/impl/index.d.ts +5 -2
- package/dist/ir/impl/index.d.ts.map +1 -1
- package/dist/ir/impl/index.js +6 -7
- package/dist/ir/impl/index.js.map +1 -1
- package/dist/ir/impl/request.d.ts +6 -6
- package/dist/ir/impl/request.d.ts.map +1 -1
- package/dist/ir/impl/request.js +18 -8
- package/dist/ir/impl/request.js.map +1 -1
- package/dist/ir/impl/serializer.d.ts +4 -2
- package/dist/ir/impl/serializer.d.ts.map +1 -1
- package/dist/ir/impl/serializer.js +41 -60
- package/dist/ir/impl/serializer.js.map +1 -1
- package/dist/ir/impl/url.d.ts +1 -1
- package/dist/ir/impl/url.d.ts.map +1 -1
- package/dist/ir/impl/url.js +4 -4
- package/dist/ir/impl/url.js.map +1 -1
- package/dist/ir/index.d.ts +1 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +1 -1
- package/dist/ir/index.js.map +1 -1
- package/dist/ir/operation/body.d.ts +1 -1
- package/dist/ir/operation/body.d.ts.map +1 -1
- package/dist/ir/operation/body.js +3 -3
- package/dist/ir/operation/body.js.map +1 -1
- package/dist/ir/operation/params.d.ts +1 -1
- package/dist/ir/operation/params.d.ts.map +1 -1
- package/dist/ir/operation/params.js +3 -3
- package/dist/ir/operation/params.js.map +1 -1
- package/dist/ir/operation/response.d.ts +3 -1
- package/dist/ir/operation/response.d.ts.map +1 -1
- package/dist/ir/operation/response.js +3 -4
- package/dist/ir/operation/response.js.map +1 -1
- package/dist/ir/operation/signature.d.ts +4 -2
- package/dist/ir/operation/signature.d.ts.map +1 -1
- package/dist/ir/operation/signature.js +5 -4
- package/dist/ir/operation/signature.js.map +1 -1
- package/dist/ir/operations.d.ts +7 -1
- package/dist/ir/operations.d.ts.map +1 -1
- package/dist/ir/operations.js +13 -7
- package/dist/ir/operations.js.map +1 -1
- package/dist/ir/runtime/index.d.ts +1 -1
- package/dist/ir/runtime/index.d.ts.map +1 -1
- package/dist/ir/runtime/index.js +1 -1
- package/dist/ir/runtime/index.js.map +1 -1
- package/dist/ir/runtime/templates.d.ts +1 -21
- package/dist/ir/runtime/templates.d.ts.map +1 -1
- package/dist/ir/runtime/templates.js +24 -428
- package/dist/ir/runtime/templates.js.map +1 -1
- package/dist/ir/schema.d.ts +3 -2
- package/dist/ir/schema.d.ts.map +1 -1
- package/dist/ir/schema.js +24 -11
- package/dist/ir/schema.js.map +1 -1
- package/dist/ir/type/context.d.ts +1 -1
- package/dist/ir/type/context.d.ts.map +1 -1
- package/dist/ir/type/index.d.ts +5 -3
- package/dist/ir/type/index.d.ts.map +1 -1
- package/dist/ir/type/index.js +12 -8
- package/dist/ir/type/index.js.map +1 -1
- package/dist/ir/type/primitive.d.ts +1 -1
- package/dist/ir/type/primitive.d.ts.map +1 -1
- package/dist/ir/type/primitive.js +1 -1
- package/dist/ir/type/primitive.js.map +1 -1
- package/dist/ir/type-ops.d.ts +2 -2
- package/dist/ir/type-ops.d.ts.map +1 -1
- package/dist/ir/type-ops.js +13 -17
- package/dist/ir/type-ops.js.map +1 -1
- package/dist/kt-compiler/index.d.ts +3 -6
- package/dist/kt-compiler/index.d.ts.map +1 -1
- package/dist/kt-compiler/index.js +7 -22
- package/dist/kt-compiler/index.js.map +1 -1
- package/dist/project/build.d.ts +1 -1
- package/dist/project/build.d.ts.map +1 -1
- package/dist/project/build.js +6 -8
- package/dist/project/build.js.map +1 -1
- package/dist/project/imports.d.ts +12 -12
- package/dist/project/imports.d.ts.map +1 -1
- package/dist/project/imports.js +60 -138
- package/dist/project/imports.js.map +1 -1
- package/dist/project/layout.d.ts +1 -1
- package/dist/project/layout.d.ts.map +1 -1
- package/dist/project/layout.js +1 -3
- package/dist/project/layout.js.map +1 -1
- package/package.json +11 -9
- package/runtime/APIClient.kt +140 -0
- package/runtime/APIError.kt +42 -0
- package/runtime/APIInterceptors.kt +14 -0
- package/runtime/APIKeyLocation.kt +7 -0
- package/runtime/Auth.kt +86 -0
- package/runtime/MultipartFormBody.kt +41 -0
- package/runtime/QueryStyle.kt +12 -0
- package/runtime/RequestOptions.kt +29 -0
- package/runtime/URLEncoding.kt +45 -0
- package/dist/kt-compiler/decl/class.d.ts +0 -6
- package/dist/kt-compiler/decl/class.d.ts.map +0 -1
- package/dist/kt-compiler/decl/class.js +0 -38
- package/dist/kt-compiler/decl/class.js.map +0 -1
- package/dist/kt-compiler/decl/dataClass.d.ts +0 -3
- package/dist/kt-compiler/decl/dataClass.d.ts.map +0 -1
- package/dist/kt-compiler/decl/dataClass.js +0 -18
- package/dist/kt-compiler/decl/dataClass.js.map +0 -1
- package/dist/kt-compiler/decl/enum.d.ts +0 -3
- package/dist/kt-compiler/decl/enum.d.ts.map +0 -1
- package/dist/kt-compiler/decl/enum.js +0 -32
- package/dist/kt-compiler/decl/enum.js.map +0 -1
- package/dist/kt-compiler/decl/fun.d.ts +0 -11
- package/dist/kt-compiler/decl/fun.d.ts.map +0 -1
- package/dist/kt-compiler/decl/fun.js +0 -69
- package/dist/kt-compiler/decl/fun.js.map +0 -1
- package/dist/kt-compiler/decl/index.d.ts +0 -13
- package/dist/kt-compiler/decl/index.d.ts.map +0 -1
- package/dist/kt-compiler/decl/index.js +0 -39
- package/dist/kt-compiler/decl/index.js.map +0 -1
- package/dist/kt-compiler/decl/interface.d.ts +0 -3
- package/dist/kt-compiler/decl/interface.d.ts.map +0 -1
- package/dist/kt-compiler/decl/interface.js +0 -15
- package/dist/kt-compiler/decl/interface.js.map +0 -1
- package/dist/kt-compiler/decl/object.d.ts +0 -3
- package/dist/kt-compiler/decl/object.d.ts.map +0 -1
- package/dist/kt-compiler/decl/object.js +0 -19
- package/dist/kt-compiler/decl/object.js.map +0 -1
- package/dist/kt-compiler/decl/prop.d.ts +0 -20
- package/dist/kt-compiler/decl/prop.d.ts.map +0 -1
- package/dist/kt-compiler/decl/prop.js +0 -42
- package/dist/kt-compiler/decl/prop.js.map +0 -1
- package/dist/kt-compiler/decl/sealedClass.d.ts +0 -3
- package/dist/kt-compiler/decl/sealedClass.d.ts.map +0 -1
- package/dist/kt-compiler/decl/sealedClass.js +0 -32
- package/dist/kt-compiler/decl/sealedClass.js.map +0 -1
- package/dist/kt-compiler/decl/topLevel.d.ts +0 -3
- package/dist/kt-compiler/decl/topLevel.d.ts.map +0 -1
- package/dist/kt-compiler/decl/topLevel.js +0 -5
- package/dist/kt-compiler/decl/topLevel.js.map +0 -1
- package/dist/kt-compiler/decl/typeAlias.d.ts +0 -3
- package/dist/kt-compiler/decl/typeAlias.d.ts.map +0 -1
- package/dist/kt-compiler/decl/typeAlias.js +0 -6
- package/dist/kt-compiler/decl/typeAlias.js.map +0 -1
- package/dist/kt-compiler/expr.d.ts +0 -4
- package/dist/kt-compiler/expr.d.ts.map +0 -1
- package/dist/kt-compiler/expr.js +0 -123
- package/dist/kt-compiler/expr.js.map +0 -1
- package/dist/kt-compiler/format.d.ts +0 -20
- package/dist/kt-compiler/format.d.ts.map +0 -1
- package/dist/kt-compiler/format.js +0 -27
- package/dist/kt-compiler/format.js.map +0 -1
- package/dist/kt-compiler/stmt.d.ts +0 -4
- package/dist/kt-compiler/stmt.d.ts.map +0 -1
- package/dist/kt-compiler/stmt.js +0 -72
- package/dist/kt-compiler/stmt.js.map +0 -1
- package/dist/kt-compiler/type.d.ts +0 -3
- package/dist/kt-compiler/type.d.ts.map +0 -1
- package/dist/kt-compiler/type.js +0 -28
- package/dist/kt-compiler/type.js.map +0 -1
- package/dist/kt-dsl/decl/class.d.ts +0 -50
- package/dist/kt-dsl/decl/class.d.ts.map +0 -1
- package/dist/kt-dsl/decl/class.js +0 -33
- package/dist/kt-dsl/decl/class.js.map +0 -1
- package/dist/kt-dsl/decl/dataClass.d.ts +0 -36
- package/dist/kt-dsl/decl/dataClass.d.ts.map +0 -1
- package/dist/kt-dsl/decl/dataClass.js +0 -25
- package/dist/kt-dsl/decl/dataClass.js.map +0 -1
- package/dist/kt-dsl/decl/enum.d.ts +0 -60
- package/dist/kt-dsl/decl/enum.d.ts.map +0 -1
- package/dist/kt-dsl/decl/enum.js +0 -38
- package/dist/kt-dsl/decl/enum.js.map +0 -1
- package/dist/kt-dsl/decl/index.d.ts +0 -11
- package/dist/kt-dsl/decl/index.d.ts.map +0 -1
- package/dist/kt-dsl/decl/index.js +0 -11
- package/dist/kt-dsl/decl/index.js.map +0 -1
- package/dist/kt-dsl/decl/interface.d.ts +0 -33
- package/dist/kt-dsl/decl/interface.d.ts.map +0 -1
- package/dist/kt-dsl/decl/interface.js +0 -24
- package/dist/kt-dsl/decl/interface.js.map +0 -1
- package/dist/kt-dsl/decl/object.d.ts +0 -34
- package/dist/kt-dsl/decl/object.d.ts.map +0 -1
- package/dist/kt-dsl/decl/object.js +0 -24
- package/dist/kt-dsl/decl/object.js.map +0 -1
- package/dist/kt-dsl/decl/prop.d.ts +0 -47
- package/dist/kt-dsl/decl/prop.d.ts.map +0 -1
- package/dist/kt-dsl/decl/prop.js +0 -28
- package/dist/kt-dsl/decl/prop.js.map +0 -1
- package/dist/kt-dsl/decl/sealedClass.d.ts +0 -68
- package/dist/kt-dsl/decl/sealedClass.d.ts.map +0 -1
- package/dist/kt-dsl/decl/sealedClass.js +0 -52
- package/dist/kt-dsl/decl/sealedClass.js.map +0 -1
- package/dist/kt-dsl/decl/topLevel.d.ts +0 -19
- package/dist/kt-dsl/decl/topLevel.d.ts.map +0 -1
- package/dist/kt-dsl/decl/topLevel.js +0 -17
- package/dist/kt-dsl/decl/topLevel.js.map +0 -1
- package/dist/kt-dsl/decl/typeAlias.d.ts +0 -23
- package/dist/kt-dsl/decl/typeAlias.d.ts.map +0 -1
- package/dist/kt-dsl/decl/typeAlias.js +0 -18
- package/dist/kt-dsl/decl/typeAlias.js.map +0 -1
- package/dist/kt-dsl/decl/types.d.ts +0 -10
- package/dist/kt-dsl/decl/types.d.ts.map +0 -1
- package/dist/kt-dsl/decl/types.js +0 -2
- package/dist/kt-dsl/decl/types.js.map +0 -1
- package/dist/kt-dsl/expr/access.d.ts +0 -48
- package/dist/kt-dsl/expr/access.d.ts.map +0 -1
- package/dist/kt-dsl/expr/access.js +0 -59
- package/dist/kt-dsl/expr/access.js.map +0 -1
- package/dist/kt-dsl/expr/call.d.ts +0 -38
- package/dist/kt-dsl/expr/call.d.ts.map +0 -1
- package/dist/kt-dsl/expr/call.js +0 -38
- package/dist/kt-dsl/expr/call.js.map +0 -1
- package/dist/kt-dsl/expr/index.d.ts +0 -7
- package/dist/kt-dsl/expr/index.d.ts.map +0 -1
- package/dist/kt-dsl/expr/index.js +0 -7
- package/dist/kt-dsl/expr/index.js.map +0 -1
- package/dist/kt-dsl/expr/literal.d.ts +0 -100
- package/dist/kt-dsl/expr/literal.d.ts.map +0 -1
- package/dist/kt-dsl/expr/literal.js +0 -108
- package/dist/kt-dsl/expr/literal.js.map +0 -1
- package/dist/kt-dsl/expr/misc.d.ts +0 -45
- package/dist/kt-dsl/expr/misc.d.ts.map +0 -1
- package/dist/kt-dsl/expr/misc.js +0 -63
- package/dist/kt-dsl/expr/misc.js.map +0 -1
- package/dist/kt-dsl/expr/op.d.ts +0 -25
- package/dist/kt-dsl/expr/op.d.ts.map +0 -1
- package/dist/kt-dsl/expr/op.js +0 -24
- package/dist/kt-dsl/expr/op.js.map +0 -1
- package/dist/kt-dsl/expr/types.d.ts +0 -93
- package/dist/kt-dsl/expr/types.d.ts.map +0 -1
- package/dist/kt-dsl/expr/types.js +0 -2
- package/dist/kt-dsl/expr/types.js.map +0 -1
- package/dist/kt-dsl/file.d.ts +0 -14
- package/dist/kt-dsl/file.d.ts.map +0 -1
- package/dist/kt-dsl/file.js +0 -9
- package/dist/kt-dsl/file.js.map +0 -1
- package/dist/kt-dsl/fun.d.ts +0 -73
- package/dist/kt-dsl/fun.d.ts.map +0 -1
- package/dist/kt-dsl/fun.js +0 -50
- package/dist/kt-dsl/fun.js.map +0 -1
- package/dist/kt-dsl/index.d.ts +0 -8
- package/dist/kt-dsl/index.d.ts.map +0 -1
- package/dist/kt-dsl/index.js +0 -8
- package/dist/kt-dsl/index.js.map +0 -1
- package/dist/kt-dsl/stmt/binding.d.ts +0 -56
- package/dist/kt-dsl/stmt/binding.d.ts.map +0 -1
- package/dist/kt-dsl/stmt/binding.js +0 -70
- package/dist/kt-dsl/stmt/binding.js.map +0 -1
- package/dist/kt-dsl/stmt/control.d.ts +0 -80
- package/dist/kt-dsl/stmt/control.d.ts.map +0 -1
- package/dist/kt-dsl/stmt/control.js +0 -77
- package/dist/kt-dsl/stmt/control.js.map +0 -1
- package/dist/kt-dsl/stmt/index.d.ts +0 -4
- package/dist/kt-dsl/stmt/index.d.ts.map +0 -1
- package/dist/kt-dsl/stmt/index.js +0 -4
- package/dist/kt-dsl/stmt/index.js.map +0 -1
- package/dist/kt-dsl/stmt/types.d.ts +0 -62
- package/dist/kt-dsl/stmt/types.d.ts.map +0 -1
- package/dist/kt-dsl/stmt/types.js +0 -2
- package/dist/kt-dsl/stmt/types.js.map +0 -1
- package/dist/kt-dsl/type/builders.d.ts +0 -75
- package/dist/kt-dsl/type/builders.d.ts.map +0 -1
- package/dist/kt-dsl/type/builders.js +0 -83
- package/dist/kt-dsl/type/builders.js.map +0 -1
- package/dist/kt-dsl/type/index.d.ts +0 -3
- package/dist/kt-dsl/type/index.d.ts.map +0 -1
- package/dist/kt-dsl/type/index.js +0 -3
- package/dist/kt-dsl/type/index.js.map +0 -1
- package/dist/kt-dsl/type/types.d.ts +0 -25
- package/dist/kt-dsl/type/types.d.ts.map +0 -1
- package/dist/kt-dsl/type/types.js +0 -2
- package/dist/kt-dsl/type/types.js.map +0 -1
- package/dist/kt-dsl/visibility.d.ts +0 -2
- package/dist/kt-dsl/visibility.d.ts.map +0 -1
- package/dist/kt-dsl/visibility.js +0 -2
- package/dist/kt-dsl/visibility.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ir/runtime/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ir/runtime/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime helper sources. These files ship verbatim into every generated
|
|
3
|
-
* SDK — no spec-driven content beyond the package name. Encoding them as
|
|
4
|
-
* fixed Kotlin strings (rather than DSL-built) keeps the codegen surface
|
|
5
|
-
* small: the DSL only has to model what the per-operation impl actually
|
|
6
|
-
* uses.
|
|
7
|
-
*
|
|
8
|
-
* Convention: `__PACKAGE__` is replaced by the consumer-chosen package
|
|
9
|
-
* name during `buildRuntimeFiles(...)`.
|
|
10
|
-
*/
|
|
11
1
|
export interface RuntimeOpts {
|
|
12
|
-
/**
|
|
13
|
-
* `Auth` / `APIKeyLocation` files. Set when the spec declares any
|
|
14
|
-
* `securitySchemes`. */
|
|
15
|
-
hasAuth: boolean;
|
|
16
|
-
/** Emit the `multipart/form-data` helper. Set when at least one op has
|
|
2
|
+
/** Ship the `multipart/form-data` helper. Set when at least one op has
|
|
17
3
|
* a `multipart/form-data` body. */
|
|
18
4
|
hasMultipart: boolean;
|
|
19
|
-
/** Emit the `application/x-www-form-urlencoded` helper file (`FormUrlEncoder`
|
|
20
|
-
* object). Currently this is folded into ad-hoc `FormBody.Builder` calls
|
|
21
|
-
* in the impl, so we don't ship a dedicated runtime file for it. */
|
|
22
|
-
hasFormUrlEncoded: boolean;
|
|
23
5
|
}
|
|
24
6
|
export interface RuntimeFile {
|
|
25
7
|
name: string;
|
|
26
8
|
content: string;
|
|
27
9
|
}
|
|
28
|
-
export declare function apiClientKt(opts: RuntimeOpts): string;
|
|
29
|
-
/** Ordered runtime files. The orchestrator places them under `API/`. */
|
|
30
10
|
export declare function buildRuntimeFiles(opts: RuntimeOpts, pkg: string): RuntimeFile[];
|
|
31
11
|
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/ir/runtime/templates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/ir/runtime/templates.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,WAAW;IAC1B;wCACoC;IACpC,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAaD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,GACV,WAAW,EAAE,CAWf"}
|
|
@@ -1,431 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* runs against every outgoing request. Multiple interceptors compose —
|
|
19
|
-
* auth, logging, and tracing all coexist as separate entries instead
|
|
20
|
-
* of being chained inside one closure.
|
|
21
|
-
*/
|
|
22
|
-
public class APIInterceptors {
|
|
23
|
-
public val request: MutableList<suspend (Request) -> Request> = mutableListOf()
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
const API_ERROR_KT = `package __PACKAGE__
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The typed error every impl method throws on non-2xx responses.
|
|
30
|
-
*
|
|
31
|
-
* - \`ClientError(statusCode, body)\` — 4XX
|
|
32
|
-
* - \`ServerError(statusCode, body)\` — 5XX
|
|
33
|
-
* - \`UnexpectedStatus(statusCode, body)\` — 1XX/3XX/anything outside 2-5
|
|
34
|
-
* - \`DecodingFailed(cause)\` — kotlinx-serialization threw on a 2XX body
|
|
35
|
-
* - \`Transport(cause)\` — OkHttp / network-layer failure
|
|
36
|
-
*
|
|
37
|
-
* Consumers \`catch\` and pattern-match. Bodies are surfaced as raw
|
|
38
|
-
* \`ByteArray\` so callers can decode error envelopes themselves with the
|
|
39
|
-
* codec they prefer.
|
|
40
|
-
*/
|
|
41
|
-
public sealed class APIError(message: String? = null, cause: Throwable? = null) :
|
|
42
|
-
RuntimeException(message, cause) {
|
|
43
|
-
|
|
44
|
-
public class ClientError(
|
|
45
|
-
public val statusCode: Int,
|
|
46
|
-
public val body: ByteArray,
|
|
47
|
-
) : APIError("Client error: \$statusCode")
|
|
48
|
-
|
|
49
|
-
public class ServerError(
|
|
50
|
-
public val statusCode: Int,
|
|
51
|
-
public val body: ByteArray,
|
|
52
|
-
) : APIError("Server error: \$statusCode")
|
|
53
|
-
|
|
54
|
-
public class UnexpectedStatus(
|
|
55
|
-
public val statusCode: Int,
|
|
56
|
-
public val body: ByteArray,
|
|
57
|
-
) : APIError("Unexpected status: \$statusCode")
|
|
58
|
-
|
|
59
|
-
public class DecodingFailed(cause: Throwable) :
|
|
60
|
-
APIError("Decoding failed: \${cause.message}", cause)
|
|
61
|
-
|
|
62
|
-
public class Transport(cause: Throwable) :
|
|
63
|
-
APIError("Transport failure: \${cause.message}", cause)
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
const QUERY_STYLE_KT = `package __PACKAGE__
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Query-array serialization style — matches the OpenAPI 3 \`style\` field
|
|
70
|
-
* for query parameters whose value is an array. The default is \`form\`
|
|
71
|
-
* with explode=true; the others appear when the spec opts into them.
|
|
72
|
-
*/
|
|
73
|
-
public enum class QueryStyle {
|
|
74
|
-
FORM,
|
|
75
|
-
SPACE_DELIMITED,
|
|
76
|
-
PIPE_DELIMITED,
|
|
77
|
-
}
|
|
78
|
-
`;
|
|
79
|
-
const URL_ENCODING_KT = `package __PACKAGE__
|
|
80
|
-
|
|
81
|
-
import okhttp3.HttpUrl
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Helpers used by generated impl code to add OpenAPI-shaped query
|
|
85
|
-
* parameters onto an \`HttpUrl.Builder\` without each call site having to
|
|
86
|
-
* know the style/explode rules.
|
|
87
|
-
*
|
|
88
|
-
* - \`addScalar\` skips when the value is \`null\` so optional-and-missing
|
|
89
|
-
* params don't emit a key at all.
|
|
90
|
-
* - \`addArray\` honours \`style\` + \`explode\`: explode=true emits one
|
|
91
|
-
* \`?name=v\` per element; explode=false joins per the style separator.
|
|
92
|
-
*/
|
|
93
|
-
public object URLEncoding {
|
|
94
|
-
public fun addScalar(builder: HttpUrl.Builder, name: String, value: Any?) {
|
|
95
|
-
if (value == null) return
|
|
96
|
-
builder.addQueryParameter(name, value.toString())
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public fun addArray(
|
|
100
|
-
builder: HttpUrl.Builder,
|
|
101
|
-
name: String,
|
|
102
|
-
values: List<Any>?,
|
|
103
|
-
style: QueryStyle = QueryStyle.FORM,
|
|
104
|
-
explode: Boolean = true,
|
|
105
|
-
) {
|
|
106
|
-
if (values == null) return
|
|
107
|
-
if (explode) {
|
|
108
|
-
for (v in values) builder.addQueryParameter(name, v.toString())
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
val sep = when (style) {
|
|
112
|
-
QueryStyle.FORM -> ","
|
|
113
|
-
QueryStyle.SPACE_DELIMITED -> " "
|
|
114
|
-
QueryStyle.PIPE_DELIMITED -> "|"
|
|
115
|
-
}
|
|
116
|
-
builder.addQueryParameter(name, values.joinToString(sep) { it.toString() })
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
`;
|
|
120
|
-
const MULTIPART_KT = `package __PACKAGE__
|
|
121
|
-
|
|
122
|
-
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|
123
|
-
import okhttp3.MultipartBody
|
|
124
|
-
import okhttp3.RequestBody
|
|
125
|
-
import okhttp3.RequestBody.Companion.toRequestBody
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Thin wrapper over OkHttp's \`MultipartBody.Builder\` — keeps the impl
|
|
129
|
-
* code symmetric with the JSON / form-urlencoded paths.
|
|
130
|
-
*
|
|
131
|
-
* - \`appendText(name, value)\` — text part.
|
|
132
|
-
* - \`appendFile(name, filename, bytes,\`
|
|
133
|
-
* \`mimeType)\` — binary part.
|
|
134
|
-
* - \`build()\` — finalizes and returns a
|
|
135
|
-
* \`RequestBody\` ready to pass
|
|
136
|
-
* into \`.method("POST", body)\`.
|
|
137
|
-
*/
|
|
138
|
-
public class MultipartFormBody {
|
|
139
|
-
private val builder: MultipartBody.Builder =
|
|
140
|
-
MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
141
|
-
|
|
142
|
-
public fun appendText(name: String, value: String) {
|
|
143
|
-
builder.addFormDataPart(name, value)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public fun appendFile(
|
|
147
|
-
name: String,
|
|
148
|
-
filename: String,
|
|
149
|
-
bytes: ByteArray,
|
|
150
|
-
mimeType: String = "application/octet-stream",
|
|
151
|
-
) {
|
|
152
|
-
val body: RequestBody = bytes.toRequestBody(mimeType.toMediaTypeOrNull())
|
|
153
|
-
builder.addFormDataPart(name, filename, body)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public fun build(): RequestBody = builder.build()
|
|
157
|
-
}
|
|
158
|
-
`;
|
|
159
|
-
const REQUEST_OPTIONS_KT = `package __PACKAGE__
|
|
160
|
-
|
|
161
|
-
import okhttp3.HttpUrl
|
|
162
|
-
import okhttp3.Request
|
|
163
|
-
import okhttp3.Response
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Per-call options bag — every generated method takes a
|
|
167
|
-
* \`RequestOptions\` last param. Mirrors hey-api's TS SDK options shape.
|
|
168
|
-
*
|
|
169
|
-
* - \`client\` — override the impl's bound \`APIClient\`.
|
|
170
|
-
* - \`baseUrl\` — override \`client.baseUrl\` for one call.
|
|
171
|
-
* - \`timeout\` — per-call call-timeout in milliseconds.
|
|
172
|
-
* - \`headers\` — extra/override headers, applied last.
|
|
173
|
-
* - \`requestInterceptors\` — extra suspend interceptors, run after
|
|
174
|
-
* client-level ones.
|
|
175
|
-
* - \`responseValidator\` — runs after a 2xx response; throwing
|
|
176
|
-
* converts the call into an exception.
|
|
177
|
-
* - \`responseTransformer\` — rewrite the response body before decode.
|
|
178
|
-
*/
|
|
179
|
-
public data class RequestOptions(
|
|
180
|
-
public val client: APIClient? = null,
|
|
181
|
-
public val baseUrl: HttpUrl? = null,
|
|
182
|
-
public val timeout: Long? = null,
|
|
183
|
-
public val headers: Map<String, String> = emptyMap(),
|
|
184
|
-
public val requestInterceptors: List<suspend (Request) -> Request> = emptyList(),
|
|
185
|
-
public val responseValidator: (suspend (ByteArray, Response) -> Unit)? = null,
|
|
186
|
-
public val responseTransformer: (suspend (ByteArray) -> ByteArray)? = null,
|
|
187
|
-
)
|
|
188
|
-
`;
|
|
189
|
-
const API_KEY_LOCATION_KT = `package __PACKAGE__
|
|
190
|
-
|
|
191
|
-
public enum class APIKeyLocation {
|
|
192
|
-
HEADER,
|
|
193
|
-
QUERY,
|
|
194
|
-
COOKIE,
|
|
195
|
-
}
|
|
196
|
-
`;
|
|
197
|
-
const AUTH_KT = `package __PACKAGE__
|
|
198
|
-
|
|
199
|
-
import java.util.Base64
|
|
200
|
-
import okhttp3.HttpUrl
|
|
201
|
-
import okhttp3.Request
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Auth schemes consumers reach for in practice:
|
|
205
|
-
*
|
|
206
|
-
* - \`Bearer(token)\` — \`Authorization: Bearer <token>\`.
|
|
207
|
-
* - \`ApiKey(name, value, in)\` — header / query / cookie placement,
|
|
208
|
-
* matching the spec's
|
|
209
|
-
* \`securitySchemes.<name>.in\`.
|
|
210
|
-
* - \`Basic(username, password)\` — \`Authorization: Basic <base64>\`.
|
|
211
|
-
*
|
|
212
|
-
* Per-operation auth is auto-wired by the generator when an op has
|
|
213
|
-
* \`security\` requirements; it walks the requirement names and applies
|
|
214
|
-
* any matching scheme value the consumer has placed on \`APIClient.auth\`.
|
|
215
|
-
*
|
|
216
|
-
* \`apply\` mutates the request builder in-place for header / cookie
|
|
217
|
-
* auth and returns the (possibly rewritten) \`HttpUrl\` so query auth
|
|
218
|
-
* can re-thread its name=value into the URL.
|
|
219
|
-
*/
|
|
220
|
-
public sealed class Auth {
|
|
221
|
-
public abstract fun apply(builder: Request.Builder, url: HttpUrl): HttpUrl
|
|
222
|
-
|
|
223
|
-
public data class Bearer(public val token: String) : Auth() {
|
|
224
|
-
override fun apply(builder: Request.Builder, url: HttpUrl): HttpUrl {
|
|
225
|
-
builder.header("Authorization", "Bearer \$token")
|
|
226
|
-
return url
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public data class ApiKey(
|
|
231
|
-
public val name: String,
|
|
232
|
-
public val value: String,
|
|
233
|
-
public val location: APIKeyLocation,
|
|
234
|
-
) : Auth() {
|
|
235
|
-
override fun apply(builder: Request.Builder, url: HttpUrl): HttpUrl =
|
|
236
|
-
when (location) {
|
|
237
|
-
APIKeyLocation.HEADER -> {
|
|
238
|
-
builder.header(name, value)
|
|
239
|
-
url
|
|
240
|
-
}
|
|
241
|
-
APIKeyLocation.QUERY ->
|
|
242
|
-
url.newBuilder().addQueryParameter(name, value).build()
|
|
243
|
-
APIKeyLocation.COOKIE -> {
|
|
244
|
-
val cookie = "\$name=\$value"
|
|
245
|
-
val existing = builder.build().header("Cookie")
|
|
246
|
-
builder.header("Cookie", existing?.let { "\$it; \$cookie" } ?: cookie)
|
|
247
|
-
url
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
public data class Basic(
|
|
253
|
-
public val username: String,
|
|
254
|
-
public val password: String,
|
|
255
|
-
) : Auth() {
|
|
256
|
-
override fun apply(builder: Request.Builder, url: HttpUrl): HttpUrl {
|
|
257
|
-
val encoded = Base64.getEncoder()
|
|
258
|
-
.encodeToString("\$username:\$password".toByteArray(Charsets.UTF_8))
|
|
259
|
-
builder.header("Authorization", "Basic \$encoded")
|
|
260
|
-
return url
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
`;
|
|
265
|
-
const API_CLIENT_KT_BASE = `package __PACKAGE__
|
|
266
|
-
|
|
267
|
-
import java.util.concurrent.TimeUnit
|
|
268
|
-
import kotlinx.coroutines.Dispatchers
|
|
269
|
-
import kotlinx.coroutines.withContext
|
|
270
|
-
import kotlinx.serialization.json.Json
|
|
271
|
-
import okhttp3.HttpUrl
|
|
272
|
-
import okhttp3.OkHttpClient
|
|
273
|
-
import okhttp3.Request
|
|
274
|
-
import okhttp3.Response
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Runtime helper every per-tag impl class delegates to. Owns the
|
|
278
|
-
* transport-level concerns — \`OkHttpClient\`, \`Json\`, the interceptor
|
|
279
|
-
* pipeline — and provides one source of truth for status-code
|
|
280
|
-
* dispatch and decoding.
|
|
281
|
-
*
|
|
282
|
-
* - \`execute<T>(request, deserializer, …)\` — decodes a 2xx body to \`T\`.
|
|
283
|
-
* - \`executeUnit(request, …)\` — discards the body.
|
|
284
|
-
* - \`executeWithResponse<T>(request, deserializer,\`
|
|
285
|
-
* \`…)\` — decode + raw \`Response\`.
|
|
286
|
-
* - \`executeUnitWithResponse(request, …)\` — raw \`Response\` only.
|
|
287
|
-
* - \`executeRaw(request, …)\` — raw \`(ByteArray, Response)\`,
|
|
288
|
-
* used by multi-2xx ops.
|
|
289
|
-
*
|
|
290
|
-
* Status-code dispatch lives in \`sendAndDispatch\`; 2xx returns the
|
|
291
|
-
* body bytes, 4xx/5xx throw the matching \`APIError\` subclass.
|
|
292
|
-
*/
|
|
293
|
-
public class APIClient(
|
|
294
|
-
public var baseUrl: HttpUrl,
|
|
295
|
-
public val httpClient: OkHttpClient = OkHttpClient(),
|
|
296
|
-
public val json: Json = Json {
|
|
297
|
-
ignoreUnknownKeys = true
|
|
298
|
-
encodeDefaults = true
|
|
299
|
-
},
|
|
300
|
-
public val interceptors: APIInterceptors = APIInterceptors(),__AUTH_FIELD__
|
|
301
|
-
) {
|
|
302
|
-
public suspend fun <T> execute(
|
|
303
|
-
request: Request,
|
|
304
|
-
deserializer: kotlinx.serialization.DeserializationStrategy<T>,
|
|
305
|
-
timeout: Long? = null,
|
|
306
|
-
extraInterceptors: List<suspend (Request) -> Request> = emptyList(),
|
|
307
|
-
responseValidator: (suspend (ByteArray, Response) -> Unit)? = null,
|
|
308
|
-
responseTransformer: (suspend (ByteArray) -> ByteArray)? = null,
|
|
309
|
-
): T {
|
|
310
|
-
val (data, response) = sendAndDispatch(request, timeout, extraInterceptors)
|
|
311
|
-
responseValidator?.invoke(data, response)
|
|
312
|
-
val body = responseTransformer?.invoke(data) ?: data
|
|
313
|
-
return try {
|
|
314
|
-
json.decodeFromString(deserializer, body.decodeToString())
|
|
315
|
-
} catch (e: Throwable) {
|
|
316
|
-
throw APIError.DecodingFailed(e)
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
public suspend fun executeUnit(
|
|
321
|
-
request: Request,
|
|
322
|
-
timeout: Long? = null,
|
|
323
|
-
extraInterceptors: List<suspend (Request) -> Request> = emptyList(),
|
|
324
|
-
responseValidator: (suspend (ByteArray, Response) -> Unit)? = null,
|
|
325
|
-
) {
|
|
326
|
-
val (data, response) = sendAndDispatch(request, timeout, extraInterceptors)
|
|
327
|
-
responseValidator?.invoke(data, response)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
public suspend fun <T> executeWithResponse(
|
|
331
|
-
request: Request,
|
|
332
|
-
deserializer: kotlinx.serialization.DeserializationStrategy<T>,
|
|
333
|
-
timeout: Long? = null,
|
|
334
|
-
extraInterceptors: List<suspend (Request) -> Request> = emptyList(),
|
|
335
|
-
responseValidator: (suspend (ByteArray, Response) -> Unit)? = null,
|
|
336
|
-
responseTransformer: (suspend (ByteArray) -> ByteArray)? = null,
|
|
337
|
-
): Pair<T, Response> {
|
|
338
|
-
val (data, response) = sendAndDispatch(request, timeout, extraInterceptors)
|
|
339
|
-
responseValidator?.invoke(data, response)
|
|
340
|
-
val body = responseTransformer?.invoke(data) ?: data
|
|
341
|
-
return try {
|
|
342
|
-
json.decodeFromString(deserializer, body.decodeToString()) to response
|
|
343
|
-
} catch (e: Throwable) {
|
|
344
|
-
throw APIError.DecodingFailed(e)
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
public suspend fun executeUnitWithResponse(
|
|
349
|
-
request: Request,
|
|
350
|
-
timeout: Long? = null,
|
|
351
|
-
extraInterceptors: List<suspend (Request) -> Request> = emptyList(),
|
|
352
|
-
responseValidator: (suspend (ByteArray, Response) -> Unit)? = null,
|
|
353
|
-
): Response {
|
|
354
|
-
val (data, response) = sendAndDispatch(request, timeout, extraInterceptors)
|
|
355
|
-
responseValidator?.invoke(data, response)
|
|
356
|
-
return response
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
public suspend fun executeRaw(
|
|
360
|
-
request: Request,
|
|
361
|
-
timeout: Long? = null,
|
|
362
|
-
extraInterceptors: List<suspend (Request) -> Request> = emptyList(),
|
|
363
|
-
responseValidator: (suspend (ByteArray, Response) -> Unit)? = null,
|
|
364
|
-
responseTransformer: (suspend (ByteArray) -> ByteArray)? = null,
|
|
365
|
-
): Pair<ByteArray, Response> {
|
|
366
|
-
val (data, response) = sendAndDispatch(request, timeout, extraInterceptors)
|
|
367
|
-
responseValidator?.invoke(data, response)
|
|
368
|
-
val body = responseTransformer?.invoke(data) ?: data
|
|
369
|
-
return body to response
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
private suspend fun sendAndDispatch(
|
|
373
|
-
request: Request,
|
|
374
|
-
timeout: Long?,
|
|
375
|
-
extraInterceptors: List<suspend (Request) -> Request>,
|
|
376
|
-
): Pair<ByteArray, Response> {
|
|
377
|
-
var req = request
|
|
378
|
-
for (interceptor in interceptors.request) req = interceptor(req)
|
|
379
|
-
for (interceptor in extraInterceptors) req = interceptor(req)
|
|
380
|
-
val callClient = if (timeout == null) httpClient else
|
|
381
|
-
httpClient.newBuilder().callTimeout(timeout, TimeUnit.MILLISECONDS).build()
|
|
382
|
-
val response = try {
|
|
383
|
-
withContext(Dispatchers.IO) {
|
|
384
|
-
callClient.newCall(req).execute()
|
|
385
|
-
}
|
|
386
|
-
} catch (e: Throwable) {
|
|
387
|
-
throw APIError.Transport(e)
|
|
388
|
-
}
|
|
389
|
-
val body = response.body?.bytes() ?: ByteArray(0)
|
|
390
|
-
return when (val code = response.code) {
|
|
391
|
-
in 200..299 -> body to response
|
|
392
|
-
in 400..499 -> throw APIError.ClientError(code, body)
|
|
393
|
-
in 500..599 -> throw APIError.ServerError(code, body)
|
|
394
|
-
else -> throw APIError.UnexpectedStatus(code, body)
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
`;
|
|
399
|
-
export function apiClientKt(opts) {
|
|
400
|
-
const authField = opts.hasAuth
|
|
401
|
-
? "\n public val auth: MutableMap<String, Auth> = mutableMapOf(),"
|
|
402
|
-
: "";
|
|
403
|
-
return API_CLIENT_KT_BASE.replace("__AUTH_FIELD__", authField);
|
|
404
|
-
}
|
|
405
|
-
/** Ordered runtime files. The orchestrator places them under `API/`. */
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime helpers that ship into every generated SDK. They live as real,
|
|
4
|
+
* ktlint-clean Kotlin sources in `packages/openapi/kotlin/runtime/` and
|
|
5
|
+
* are copied verbatim; only the package header is rewritten.
|
|
6
|
+
*/
|
|
7
|
+
const RUNTIME_DIR = new URL("../../../runtime/", import.meta.url);
|
|
8
|
+
const ALWAYS = [
|
|
9
|
+
"APIClient.kt",
|
|
10
|
+
"APIError.kt",
|
|
11
|
+
"APIInterceptors.kt",
|
|
12
|
+
"APIKeyLocation.kt",
|
|
13
|
+
"Auth.kt",
|
|
14
|
+
"QueryStyle.kt",
|
|
15
|
+
"RequestOptions.kt",
|
|
16
|
+
"URLEncoding.kt",
|
|
17
|
+
];
|
|
406
18
|
export function buildRuntimeFiles(opts, pkg) {
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
{ name: "RequestOptions.kt", content: subst(REQUEST_OPTIONS_KT) },
|
|
415
|
-
];
|
|
416
|
-
if (opts.hasAuth) {
|
|
417
|
-
files.push({ name: "Auth.kt", content: subst(AUTH_KT) });
|
|
418
|
-
files.push({
|
|
419
|
-
name: "APIKeyLocation.kt",
|
|
420
|
-
content: subst(API_KEY_LOCATION_KT),
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
if (opts.hasMultipart) {
|
|
424
|
-
files.push({
|
|
425
|
-
name: "MultipartFormBody.kt",
|
|
426
|
-
content: subst(MULTIPART_KT),
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
return files;
|
|
19
|
+
const names = opts.hasMultipart
|
|
20
|
+
? [...ALWAYS, "MultipartFormBody.kt"]
|
|
21
|
+
: ALWAYS;
|
|
22
|
+
return names.map((name) => ({
|
|
23
|
+
name,
|
|
24
|
+
content: readFileSync(new URL(name, RUNTIME_DIR), "utf8").replace(/^package dev\.irkit\.runtime$/m, `package ${pkg}`),
|
|
25
|
+
}));
|
|
430
26
|
}
|
|
431
27
|
//# sourceMappingURL=templates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/ir/runtime/templates.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/ir/runtime/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAalE,MAAM,MAAM,GAAG;IACb,cAAc;IACd,aAAa;IACb,oBAAoB;IACpB,mBAAmB;IACnB,SAAS;IACT,eAAe;IACf,mBAAmB;IACnB,gBAAgB;CACjB,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAC/B,IAAiB,EACjB,GAAW;IAEX,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY;QAC7B,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,sBAAsB,CAAC;QACrC,CAAC,CAAC,MAAM,CAAC;IACX,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,IAAI;QACJ,OAAO,EAAE,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,OAAO,CAC/D,gCAAgC,EAChC,WAAW,GAAG,EAAE,CACjB;KACF,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/dist/ir/schema.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IR } from "@hey-api/shared";
|
|
2
|
-
import {
|
|
2
|
+
import type { Namespace } from "@ir-kit/codegen-core";
|
|
3
|
+
import { type KtDecl } from "../ast/index.js";
|
|
3
4
|
/**
|
|
4
5
|
* Translate `IR.Model.components.schemas` into Kotlin decls.
|
|
5
6
|
*
|
|
@@ -13,5 +14,5 @@ import { type KtDecl } from "../kt-dsl/index.js";
|
|
|
13
14
|
* Schemas come in as hey-api's `IR.SchemaObject` and are folded to
|
|
14
15
|
* canonical {@link Schema} at the boundary.
|
|
15
16
|
*/
|
|
16
|
-
export declare function schemasToDecls(schemas: Record<string, IR.SchemaObject
|
|
17
|
+
export declare function schemasToDecls(schemas: Record<string, IR.SchemaObject>, names?: Namespace): KtDecl[];
|
|
17
18
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/ir/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/ir/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/ir/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAQtD,OAAO,EACL,KAAK,MAAM,EAMZ,MAAM,iBAAiB,CAAC;AAIzB;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,EACxC,KAAK,GAAE,SAA0B,GAChC,MAAM,EAAE,CAyDV"}
|
package/dist/ir/schema.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { fromHeyApi, refName } from "@ir-kit/openapi";
|
|
2
|
-
import {
|
|
1
|
+
import { fromHeyApi, refName, schemaTypeName, } from "@ir-kit/openapi";
|
|
2
|
+
import { ktJsonElement, ktMap, ktRef, ktString, ktTypeAlias, } from "../ast/index.js";
|
|
3
|
+
import { newTypeNames } from "./identifiers.js";
|
|
3
4
|
import { buildEnumFromIR, buildStruct, schemaToType } from "./type/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Translate `IR.Model.components.schemas` into Kotlin decls.
|
|
@@ -14,40 +15,52 @@ import { buildEnumFromIR, buildStruct, schemaToType } from "./type/index.js";
|
|
|
14
15
|
* Schemas come in as hey-api's `IR.SchemaObject` and are folded to
|
|
15
16
|
* canonical {@link Schema} at the boundary.
|
|
16
17
|
*/
|
|
17
|
-
export function schemasToDecls(schemas) {
|
|
18
|
+
export function schemasToDecls(schemas, names = newTypeNames()) {
|
|
18
19
|
const decls = [];
|
|
19
20
|
const emit = (d) => decls.push(d);
|
|
20
|
-
|
|
21
|
+
// Components claim their names before any synthesized inline type.
|
|
22
|
+
for (const rawName of Object.keys(schemas))
|
|
23
|
+
schemaTypeName(names, rawName);
|
|
24
|
+
for (const [rawName, heySchema] of Object.entries(schemas)) {
|
|
25
|
+
const name = schemaTypeName(names, rawName);
|
|
21
26
|
const schema = fromHeyApi(heySchema);
|
|
22
27
|
if (schema.$ref) {
|
|
23
|
-
decls.push(ktTypeAlias({
|
|
28
|
+
decls.push(ktTypeAlias({
|
|
29
|
+
name,
|
|
30
|
+
type: ktRef(schemaTypeName(names, refName(schema.$ref))),
|
|
31
|
+
}));
|
|
24
32
|
continue;
|
|
25
33
|
}
|
|
26
34
|
const isEnum = Array.isArray(schema.enum) && schema.enum.length > 0;
|
|
27
35
|
if (isEnum) {
|
|
28
|
-
buildEnumFromIR(name, schema, emit);
|
|
36
|
+
buildEnumFromIR(name, schema, emit, names);
|
|
29
37
|
continue;
|
|
30
38
|
}
|
|
31
39
|
if (schema.type === "object" && schema.properties) {
|
|
32
|
-
decls.push(buildStruct(name, schema, { emit }));
|
|
40
|
+
decls.push(buildStruct(name, schema, { emit, names }));
|
|
33
41
|
continue;
|
|
34
42
|
}
|
|
35
43
|
if (schema.type === "object") {
|
|
36
44
|
const ap = schema.additionalProperties;
|
|
37
45
|
const sealed = ap === false;
|
|
38
46
|
if (sealed) {
|
|
39
|
-
decls.push(buildStruct(name, schema, { emit }));
|
|
47
|
+
decls.push(buildStruct(name, schema, { emit, names }));
|
|
40
48
|
continue;
|
|
41
49
|
}
|
|
42
50
|
const valueType = ap && typeof ap === "object"
|
|
43
|
-
? schemaToType(ap, { emit, ownerName: name, propPath: [] })
|
|
44
|
-
:
|
|
51
|
+
? schemaToType(ap, { emit, names, ownerName: name, propPath: [] })
|
|
52
|
+
: ktJsonElement;
|
|
45
53
|
decls.push(ktTypeAlias({ name, type: ktMap(ktString, valueType) }));
|
|
46
54
|
continue;
|
|
47
55
|
}
|
|
48
56
|
decls.push(ktTypeAlias({
|
|
49
57
|
name,
|
|
50
|
-
type: schemaToType(schema, {
|
|
58
|
+
type: schemaToType(schema, {
|
|
59
|
+
emit,
|
|
60
|
+
names,
|
|
61
|
+
ownerName: name,
|
|
62
|
+
propPath: [],
|
|
63
|
+
}),
|
|
51
64
|
}));
|
|
52
65
|
}
|
|
53
66
|
return decls;
|
package/dist/ir/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/ir/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/ir/schema.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/ir/type/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/ir/type/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/ir/type/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { Namespace } from "@ir-kit/codegen-core";
|
|
1
2
|
import { type Schema } from "@ir-kit/openapi";
|
|
2
|
-
import type { KtDecl } from "../../
|
|
3
|
-
import type
|
|
3
|
+
import type { KtDecl } from "../../ast/index.js";
|
|
4
|
+
import { type KtType } from "../../ast/index.js";
|
|
4
5
|
import type { TypeCtx } from "./context.js";
|
|
5
6
|
export type { TypeCtx } from "./context.js";
|
|
6
7
|
/**
|
|
@@ -11,6 +12,7 @@ export type { TypeCtx } from "./context.js";
|
|
|
11
12
|
export declare function schemaToType(schema: Schema, ctx: TypeCtx): KtType;
|
|
12
13
|
export declare function buildStruct(name: string, schema: Schema, ctx: {
|
|
13
14
|
emit: (d: KtDecl) => void;
|
|
15
|
+
names: Namespace;
|
|
14
16
|
}): KtDecl;
|
|
15
|
-
export declare function buildEnumFromIR(name: string, schema: Schema, emit: (d: KtDecl) => void): KtType;
|
|
17
|
+
export declare function buildEnumFromIR(name: string, schema: Schema, emit: (d: KtDecl) => void, names: Namespace): KtType;
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ir/type/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EAEZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ir/type/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAGL,KAAK,MAAM,EAEZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,KAAK,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAEjE;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,GAAG,EAAE;IAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACnD,MAAM,CAUR;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,EACzB,KAAK,EAAE,SAAS,GACf,MAAM,CAQR"}
|