@ir-kit/spec-convert 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -7
- package/dist/converters/openapi3-to-proto/allof.d.ts +11 -0
- package/dist/converters/openapi3-to-proto/allof.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto/allof.js +122 -0
- package/dist/converters/openapi3-to-proto/allof.js.map +1 -0
- package/dist/converters/openapi3-to-proto/ast.d.ts +69 -0
- package/dist/converters/openapi3-to-proto/ast.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto/ast.js +15 -0
- package/dist/converters/openapi3-to-proto/ast.js.map +1 -0
- package/dist/converters/openapi3-to-proto/index.d.ts +12 -0
- package/dist/converters/openapi3-to-proto/index.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto/index.js +173 -0
- package/dist/converters/openapi3-to-proto/index.js.map +1 -0
- package/dist/converters/openapi3-to-proto/names.d.ts +13 -0
- package/dist/converters/openapi3-to-proto/names.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto/names.js +40 -0
- package/dist/converters/openapi3-to-proto/names.js.map +1 -0
- package/dist/converters/openapi3-to-proto/ops.d.ts +40 -0
- package/dist/converters/openapi3-to-proto/ops.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto/ops.js +268 -0
- package/dist/converters/openapi3-to-proto/ops.js.map +1 -0
- package/dist/converters/openapi3-to-proto/print.d.ts +3 -0
- package/dist/converters/openapi3-to-proto/print.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto/print.js +73 -0
- package/dist/converters/openapi3-to-proto/print.js.map +1 -0
- package/dist/converters/openapi3-to-proto.d.ts +2 -0
- package/dist/converters/openapi3-to-proto.d.ts.map +1 -0
- package/dist/converters/openapi3-to-proto.js +14 -0
- package/dist/converters/openapi3-to-proto.js.map +1 -0
- package/dist/converters/typespec-to-proto.js +1 -0
- package/dist/converters/typespec-to-proto.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -21
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +2 -0
- package/dist/registry.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -29,15 +29,37 @@ if (result.output.kind === "document") {
|
|
|
29
29
|
|
|
30
30
|
## Registered converters
|
|
31
31
|
|
|
32
|
-
| From | → | To
|
|
33
|
-
| -------- | --- |
|
|
34
|
-
| openapi3 | → | json-schema, postman, typespec |
|
|
35
|
-
| postman | → | openapi3
|
|
36
|
-
| proto | → | openapi3
|
|
37
|
-
| typespec | → | openapi3, json-schema, proto
|
|
32
|
+
| From | → | To |
|
|
33
|
+
| -------- | --- | ------------------------------------- |
|
|
34
|
+
| openapi3 | → | json-schema, postman, proto, typespec |
|
|
35
|
+
| postman | → | openapi3 |
|
|
36
|
+
| proto | → | openapi3 |
|
|
37
|
+
| typespec | → | openapi3, json-schema, proto |
|
|
38
38
|
|
|
39
39
|
Any combination not in this table is resolved automatically by chaining edges through the graph — e.g. `postman → typespec` runs `postman → openapi3 → typespec`.
|
|
40
40
|
|
|
41
|
+
## OpenAPI → proto
|
|
42
|
+
|
|
43
|
+
`openapi3 → proto` writes one proto3 file. Pass `upstream: { package: "acme.v1" }` to set the package; it defaults to the snake_cased `info.title`.
|
|
44
|
+
|
|
45
|
+
| OpenAPI | Protobuf |
|
|
46
|
+
| ----------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
47
|
+
| component object schema | `message`; non-required scalar and enum fields are `optional` |
|
|
48
|
+
| `allOf` of objects | one `message` with the merged properties |
|
|
49
|
+
| `oneOf` / `anyOf` | `message` with a `oneof variant` |
|
|
50
|
+
| string `enum` | `enum` with a `<NAME>_UNSPECIFIED = 0` value first |
|
|
51
|
+
| integer `enum` | `int32` / `int64` |
|
|
52
|
+
| `array` / `additionalProperties` | `repeated` / `map<string, T>`; nested ones are boxed in a single-field message |
|
|
53
|
+
| `string` + `date-time`, `binary`/`byte` | `google.protobuf.Timestamp`, `bytes` |
|
|
54
|
+
| untyped schema, mixed enum | `google.protobuf.Value` |
|
|
55
|
+
| `$ref` to an array, map or scalar component | the referenced type, inlined (proto has no aliases) |
|
|
56
|
+
| operation | `rpc` in a `<FirstTag>Service`, commented with its summary and `METHOD /path` |
|
|
57
|
+
| parameters + request body | `<Rpc>Request` with one field per parameter plus `body` |
|
|
58
|
+
| 2xx response | the referenced message, or `<Rpc>Response`; several 2xx become a `oneof` |
|
|
59
|
+
| no parameters / no response body | `google.protobuf.Empty` |
|
|
60
|
+
|
|
61
|
+
Property names become snake_case fields with `json_name` set to the original key. HTTP bindings (`google.api.http`), security schemes and error responses are not emitted. The proto JSON mapping of enums and `oneof`s differs from the OpenAPI JSON for the same data. The output uses proto3 `optional`, which needs protoc 3.15+.
|
|
62
|
+
|
|
41
63
|
## API
|
|
42
64
|
|
|
43
65
|
| Export | Description |
|
|
@@ -59,5 +81,5 @@ See [`@ir-kit/cli`](../../cli) for full flags.
|
|
|
59
81
|
|
|
60
82
|
## Limitations
|
|
61
83
|
|
|
62
|
-
- `
|
|
84
|
+
- `typespec → proto` only accepts TypeSpec written for `@typespec/protobuf`, so no route passes through it; `openapi3 → proto` uses its own converter.
|
|
63
85
|
- AsyncAPI 3 outputs are not yet registered — `asyncapi3` works as a load target via `@ir-kit/spec-loader`, but not yet as a convert target.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Json = Record<string, unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* Rewrite every `allOf` whose members are all objects (inline or via a
|
|
4
|
+
* local `$ref`) into one object schema carrying the members' combined
|
|
5
|
+
* properties. Protobuf has no inheritance, so a message must list every
|
|
6
|
+
* inherited field itself. Mutates `doc`; `allOf`s that mix in unions or
|
|
7
|
+
* non-object types are left alone.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeObjectAllOf(doc: Json): void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=allof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allof.d.ts","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/allof.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAUpC;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAiGhD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2
|
+
/**
|
|
3
|
+
* Rewrite every `allOf` whose members are all objects (inline or via a
|
|
4
|
+
* local `$ref`) into one object schema carrying the members' combined
|
|
5
|
+
* properties. Protobuf has no inheritance, so a message must list every
|
|
6
|
+
* inherited field itself. Mutates `doc`; `allOf`s that mix in unions or
|
|
7
|
+
* non-object types are left alone.
|
|
8
|
+
*/
|
|
9
|
+
export function mergeObjectAllOf(doc) {
|
|
10
|
+
const resolve = (node) => {
|
|
11
|
+
let current = node;
|
|
12
|
+
for (let depth = 0; current && typeof current.$ref === "string"; depth++) {
|
|
13
|
+
if (depth > 32)
|
|
14
|
+
return undefined;
|
|
15
|
+
current = pointer(doc, current.$ref);
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
};
|
|
19
|
+
const flatten = (node, seen) => {
|
|
20
|
+
const target = resolve(node);
|
|
21
|
+
if (!target || seen.has(target))
|
|
22
|
+
return undefined;
|
|
23
|
+
if (target.oneOf || target.anyOf || target.not)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (target.type !== undefined && target.type !== "object")
|
|
26
|
+
return undefined;
|
|
27
|
+
const nextSeen = new Set(seen).add(target);
|
|
28
|
+
const properties = {};
|
|
29
|
+
const required = new Set();
|
|
30
|
+
if (Array.isArray(target.allOf)) {
|
|
31
|
+
for (const member of target.allOf) {
|
|
32
|
+
if (!isObject(member))
|
|
33
|
+
return undefined;
|
|
34
|
+
const flat = flatten(member, nextSeen);
|
|
35
|
+
if (!flat)
|
|
36
|
+
return undefined;
|
|
37
|
+
mergeProperties(properties, flat.properties);
|
|
38
|
+
for (const r of flat.required)
|
|
39
|
+
required.add(r);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (isObject(target.properties))
|
|
43
|
+
mergeProperties(properties, target.properties);
|
|
44
|
+
if (Array.isArray(target.required)) {
|
|
45
|
+
for (const r of target.required) {
|
|
46
|
+
if (typeof r === "string")
|
|
47
|
+
required.add(r);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { properties, required: [...required] };
|
|
51
|
+
};
|
|
52
|
+
/** Inline object a merge can combine field by field. `$ref`s and
|
|
53
|
+
* maps are left out: merging through a `$ref` can recurse forever,
|
|
54
|
+
* and a map has no fields to combine. */
|
|
55
|
+
const isInlineObject = (node) => isObject(node) &&
|
|
56
|
+
node.$ref === undefined &&
|
|
57
|
+
isObject(node.properties) &&
|
|
58
|
+
(node.type === undefined || node.type === "object") &&
|
|
59
|
+
!node.allOf &&
|
|
60
|
+
!node.oneOf &&
|
|
61
|
+
!node.anyOf;
|
|
62
|
+
/** A property several members declare as an inline object keeps
|
|
63
|
+
* every member's fields; otherwise the later declaration wins. */
|
|
64
|
+
function mergeProperties(into, from) {
|
|
65
|
+
for (const [key, schema] of Object.entries(from)) {
|
|
66
|
+
const prev = into[key];
|
|
67
|
+
into[key] =
|
|
68
|
+
prev !== schema && isInlineObject(prev) && isInlineObject(schema)
|
|
69
|
+
? mergeObjects(prev, schema)
|
|
70
|
+
: schema;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function mergeObjects(a, b) {
|
|
74
|
+
const properties = { ...a.properties };
|
|
75
|
+
mergeProperties(properties, b.properties);
|
|
76
|
+
const required = new Set([a.required, b.required].flatMap((r) => (Array.isArray(r) ? r : [])));
|
|
77
|
+
const merged = { ...a, ...b, properties };
|
|
78
|
+
if (required.size > 0)
|
|
79
|
+
merged.required = [...required];
|
|
80
|
+
return merged;
|
|
81
|
+
}
|
|
82
|
+
const visited = new WeakSet();
|
|
83
|
+
const walk = (node) => {
|
|
84
|
+
if (typeof node !== "object" || node === null || visited.has(node))
|
|
85
|
+
return;
|
|
86
|
+
visited.add(node);
|
|
87
|
+
if (Array.isArray(node)) {
|
|
88
|
+
for (const item of node)
|
|
89
|
+
walk(item);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const obj = node;
|
|
93
|
+
if (Array.isArray(obj.allOf) && obj.allOf.length > 0) {
|
|
94
|
+
const flat = flatten(obj, new Set());
|
|
95
|
+
if (flat && Object.keys(flat.properties).length > 0) {
|
|
96
|
+
delete obj.allOf;
|
|
97
|
+
obj.type = "object";
|
|
98
|
+
obj.properties = flat.properties;
|
|
99
|
+
if (flat.required.length > 0)
|
|
100
|
+
obj.required = flat.required;
|
|
101
|
+
else
|
|
102
|
+
delete obj.required;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const value of Object.values(obj))
|
|
106
|
+
walk(value);
|
|
107
|
+
};
|
|
108
|
+
walk(doc);
|
|
109
|
+
}
|
|
110
|
+
function pointer(doc, ref) {
|
|
111
|
+
if (!ref.startsWith("#/"))
|
|
112
|
+
return undefined;
|
|
113
|
+
let current = doc;
|
|
114
|
+
for (const raw of ref.slice(2).split("/")) {
|
|
115
|
+
const key = decodeURIComponent(raw).replace(/~1/g, "/").replace(/~0/g, "~");
|
|
116
|
+
if (!isObject(current))
|
|
117
|
+
return undefined;
|
|
118
|
+
current = current[key];
|
|
119
|
+
}
|
|
120
|
+
return isObject(current) ? current : undefined;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=allof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allof.js","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/allof.ts"],"names":[],"mappings":"AAEA,MA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,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,OAAO,GAAY,GAAG,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC5E,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,SAAS,CAAC;QACzC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export type ProtoScalar = "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "bool" | "string" | "bytes";
|
|
2
|
+
export type ProtoType = {
|
|
3
|
+
kind: "scalar";
|
|
4
|
+
name: ProtoScalar;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "named";
|
|
7
|
+
name: string;
|
|
8
|
+
isEnum: boolean;
|
|
9
|
+
import?: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "repeated";
|
|
12
|
+
elem: ProtoType;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "map";
|
|
15
|
+
value: ProtoType;
|
|
16
|
+
};
|
|
17
|
+
export interface ProtoField {
|
|
18
|
+
name: string;
|
|
19
|
+
number: number;
|
|
20
|
+
type: ProtoType;
|
|
21
|
+
optional?: boolean;
|
|
22
|
+
jsonName?: string;
|
|
23
|
+
deprecated?: boolean;
|
|
24
|
+
comment?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ProtoOneof {
|
|
27
|
+
name: string;
|
|
28
|
+
fields: ProtoField[];
|
|
29
|
+
}
|
|
30
|
+
export interface ProtoMessage {
|
|
31
|
+
kind: "message";
|
|
32
|
+
name: string;
|
|
33
|
+
fields: ProtoField[];
|
|
34
|
+
oneofs: ProtoOneof[];
|
|
35
|
+
comment?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ProtoEnum {
|
|
38
|
+
kind: "enum";
|
|
39
|
+
name: string;
|
|
40
|
+
values: Array<{
|
|
41
|
+
name: string;
|
|
42
|
+
number: number;
|
|
43
|
+
}>;
|
|
44
|
+
comment?: string;
|
|
45
|
+
}
|
|
46
|
+
export type ProtoDecl = ProtoMessage | ProtoEnum;
|
|
47
|
+
export interface ProtoRpc {
|
|
48
|
+
name: string;
|
|
49
|
+
request: ProtoType;
|
|
50
|
+
response: ProtoType;
|
|
51
|
+
deprecated?: boolean;
|
|
52
|
+
comment?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ProtoService {
|
|
55
|
+
name: string;
|
|
56
|
+
rpcs: ProtoRpc[];
|
|
57
|
+
comment?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ProtoFile {
|
|
60
|
+
package: string;
|
|
61
|
+
decls: ProtoDecl[];
|
|
62
|
+
services: ProtoService[];
|
|
63
|
+
}
|
|
64
|
+
export declare const scalar: (name: ProtoScalar) => ProtoType;
|
|
65
|
+
export declare const protoValue: ProtoType;
|
|
66
|
+
export declare const protoEmpty: ProtoType;
|
|
67
|
+
export declare const protoTimestamp: ProtoType;
|
|
68
|
+
export declare const isMessageType: (t: ProtoType) => boolean;
|
|
69
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/ast.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,OAAO,CAAC;AAEZ,M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,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED,eAAO,MAAM,MAAM,GAAI,MAAM,WAAW,KAAG,SAGzC,CAAC;AASH,eAAO,MAAM,UAAU,WAA+B,CAAC;AACvD,eAAO,MAAM,UAAU,WAA8B,CAAC;AACtD,eAAO,MAAM,cAAc,WAAsC,CAAC;AAElE,eAAO,MAAM,aAAa,GAAI,GAAG,SAAS,KAAG,OACZ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const scalar = (name) => ({
|
|
2
|
+
kind: "scalar",
|
|
3
|
+
name,
|
|
4
|
+
});
|
|
5
|
+
const wellKnown = (name, file) => ({
|
|
6
|
+
kind: "named",
|
|
7
|
+
name: `google.protobuf.${name}`,
|
|
8
|
+
isEnum: false,
|
|
9
|
+
import: `google/protobuf/${file}.proto`,
|
|
10
|
+
});
|
|
11
|
+
export const protoValue = wellKnown("Value", "struct");
|
|
12
|
+
export const protoEmpty = wellKnown("Empty", "empty");
|
|
13
|
+
export const protoTimestamp = wellKnown("Timestamp", "timestamp");
|
|
14
|
+
export const isMessageType = (t) => t.kind === "named" && !t.isEnum;
|
|
15
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/ast.ts"],"names":[],"mappings":"AAqEA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAiB,EAAa,EAAE,CAAC,CAAC;IACvD,IAAI,EAAE,QAAQ;IACd,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY,EAAa,EAAE,CAAC,CAAC;IAC5D,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,mBAAmB,IAAI,EAAE;IAC/B,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,mBAAmB,IAAI,QAAQ;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAElE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAY,EAAW,EAAE,CACrD,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface OpenAPIToProtoOptions {
|
|
2
|
+
/** Protobuf package. Defaults to the snake_cased `info.title`. */
|
|
3
|
+
package?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Build a proto3 file from an OpenAPI document: one message or enum per
|
|
7
|
+
* component schema, and one gRPC service per operation tag with an RPC
|
|
8
|
+
* per operation. Each RPC's request message holds the operation's
|
|
9
|
+
* parameters plus a `body` field; its response is the 2xx schema.
|
|
10
|
+
*/
|
|
11
|
+
export declare function openAPIToProto(document: Record<string, unknown>, options?: OpenAPIToProtoOptions): string;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/index.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,GAAE,qBAA0B,GAClC,MAAM,CAkDR"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { pascal } from "@ir-kit/codegen-core";
|
|
2
|
+
import { classifyBody, classifyEnumLiterals, classifyReturnShape, collectLocatedParams, deriveBaseName, extractEnumValues, fromHeyApi, iterateObjectProperties, iterOperations, operationDocLine, schemaTypeName, } from "@ir-kit/openapi";
|
|
3
|
+
import { parseSpec } from "@ir-kit/openapi-tools";
|
|
4
|
+
import { mergeObjectAllOf } from "./allof.js";
|
|
5
|
+
import { isMessageType, protoEmpty, } from "./ast.js";
|
|
6
|
+
import { newTypeNames, packageIdent } from "./names.js";
|
|
7
|
+
import { createProtoOps } from "./ops.js";
|
|
8
|
+
import { printProtoFile } from "./print.js";
|
|
9
|
+
/**
|
|
10
|
+
* Build a proto3 file from an OpenAPI document: one message or enum per
|
|
11
|
+
* component schema, and one gRPC service per operation tag with an RPC
|
|
12
|
+
* per operation. Each RPC's request message holds the operation's
|
|
13
|
+
* parameters plus a `body` field; its response is the 2xx schema.
|
|
14
|
+
*/
|
|
15
|
+
export function openAPIToProto(document, options = {}) {
|
|
16
|
+
const doc = structuredClone(document);
|
|
17
|
+
mergeObjectAllOf(doc);
|
|
18
|
+
const ir = parseSpec(doc);
|
|
19
|
+
const info = isRecord(doc.info) ? doc.info : {};
|
|
20
|
+
const title = typeof info.title === "string" ? info.title : undefined;
|
|
21
|
+
const pkg = options.package ?? packageIdent(title);
|
|
22
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(pkg)) {
|
|
23
|
+
throw new Error(`openapi3→proto: invalid package name "${pkg}"`);
|
|
24
|
+
}
|
|
25
|
+
const state = {
|
|
26
|
+
names: newTypeNames(),
|
|
27
|
+
enumValues: new Set(),
|
|
28
|
+
enums: new Set(),
|
|
29
|
+
aliases: new Map(),
|
|
30
|
+
decls: [],
|
|
31
|
+
};
|
|
32
|
+
const ops = createProtoOps(state);
|
|
33
|
+
const components = Object.entries(ir.components?.schemas ?? {}).map(([raw, hey]) => ({
|
|
34
|
+
name: schemaTypeName(state.names, raw),
|
|
35
|
+
schema: fromHeyApi(hey),
|
|
36
|
+
}));
|
|
37
|
+
// Classify every component before generating any of them, so forward
|
|
38
|
+
// references know whether they point at an enum or an inlined alias.
|
|
39
|
+
for (const { name, schema } of components) {
|
|
40
|
+
if (isStringEnum(schema))
|
|
41
|
+
state.enums.add(name);
|
|
42
|
+
else if (!ops.isMessageShape(schema))
|
|
43
|
+
state.aliases.set(name, schema);
|
|
44
|
+
}
|
|
45
|
+
for (const { name, schema } of components) {
|
|
46
|
+
if (isStringEnum(schema)) {
|
|
47
|
+
ops.emitStringEnum(name, extractEnumValues(schema), (d) => state.decls.push({ ...d, comment: schema.description }), state.names);
|
|
48
|
+
}
|
|
49
|
+
else if (state.aliases.has(name)) {
|
|
50
|
+
ops.refType(name);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
state.decls.push(namedMessage(ops, name, schema));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const services = buildServices(ir.paths, ops, state, title);
|
|
57
|
+
const file = { package: pkg, decls: state.decls, services };
|
|
58
|
+
return printProtoFile(file);
|
|
59
|
+
}
|
|
60
|
+
function buildServices(paths, ops, state, title) {
|
|
61
|
+
const services = new Map();
|
|
62
|
+
const rpcNames = new Map();
|
|
63
|
+
for (const { pathStr, method, op } of iterOperations(paths)) {
|
|
64
|
+
const tag = op.tags?.[0];
|
|
65
|
+
const serviceName = state.names.claim(`service:${tag ?? ""}`, `${tag ?? title ?? "Api"}Service`);
|
|
66
|
+
let service = services.get(serviceName);
|
|
67
|
+
if (!service) {
|
|
68
|
+
service = { name: serviceName, rpcs: [] };
|
|
69
|
+
services.set(serviceName, service);
|
|
70
|
+
rpcNames.set(serviceName, newTypeNames());
|
|
71
|
+
}
|
|
72
|
+
const opKey = `${method} ${pathStr}`;
|
|
73
|
+
const rpc = rpcNames
|
|
74
|
+
.get(serviceName)
|
|
75
|
+
.claim(opKey, deriveBaseName(op, method, pathStr));
|
|
76
|
+
const properties = collectLocatedParams(op).map(({ param }) => {
|
|
77
|
+
const schema = fromHeyApi(param.schema);
|
|
78
|
+
return {
|
|
79
|
+
jsonKey: param.name,
|
|
80
|
+
schema: {
|
|
81
|
+
...schema,
|
|
82
|
+
description: param.description ?? schema.description,
|
|
83
|
+
deprecated: param.deprecated ?? schema.deprecated,
|
|
84
|
+
},
|
|
85
|
+
required: param.required ?? false,
|
|
86
|
+
isBinary: false,
|
|
87
|
+
propPathSegment: pascal(param.name),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
if (op.body) {
|
|
91
|
+
const body = classifyBody(op.body);
|
|
92
|
+
properties.push({
|
|
93
|
+
jsonKey: "body",
|
|
94
|
+
schema: body.shape.kind === "opaque"
|
|
95
|
+
? { type: "string", format: "binary" }
|
|
96
|
+
: body.schema,
|
|
97
|
+
required: op.body.required ?? false,
|
|
98
|
+
isBinary: body.shape.kind === "opaque",
|
|
99
|
+
propPathSegment: "Body",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
let request = protoEmpty;
|
|
103
|
+
if (properties.length > 0) {
|
|
104
|
+
const name = state.names.claim(`rpc:${opKey}:request`, `${rpc}Request`);
|
|
105
|
+
state.decls.push(ops.message(name, properties));
|
|
106
|
+
request = ops.refType(name);
|
|
107
|
+
}
|
|
108
|
+
service.rpcs.push({
|
|
109
|
+
name: rpc,
|
|
110
|
+
request,
|
|
111
|
+
response: responseType(op, opKey, rpc, ops, state),
|
|
112
|
+
deprecated: op.deprecated,
|
|
113
|
+
comment: [op.summary, op.description, operationDocLine(method, pathStr)]
|
|
114
|
+
.filter((s) => Boolean(s?.trim()))
|
|
115
|
+
.join("\n\n"),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return [...services.values()];
|
|
119
|
+
}
|
|
120
|
+
function responseType(op, opKey, rpc, ops, state) {
|
|
121
|
+
const shape = classifyReturnShape(op);
|
|
122
|
+
const claim = () => state.names.claim(`rpc:${opKey}:response`, `${rpc}Response`);
|
|
123
|
+
let schema;
|
|
124
|
+
if (shape.kind === "single")
|
|
125
|
+
schema = shape.schema;
|
|
126
|
+
if (shape.kind === "multi") {
|
|
127
|
+
const bodies = shape.cases.filter((c) => c.schema !== undefined);
|
|
128
|
+
const distinct = new Set(bodies.map((c) => JSON.stringify(c.schema)));
|
|
129
|
+
const hasEmpty = bodies.length < shape.cases.length;
|
|
130
|
+
if (distinct.size === 1 && !hasEmpty)
|
|
131
|
+
schema = bodies[0].schema;
|
|
132
|
+
else if (distinct.size > 0) {
|
|
133
|
+
// One branch per status code, so callers can tell 200 from 202 or
|
|
134
|
+
// a 204 with no body.
|
|
135
|
+
const name = claim();
|
|
136
|
+
state.decls.push(ops.oneofMessage(name, shape.cases.map((c) => ({
|
|
137
|
+
schema: c.schema,
|
|
138
|
+
label: `status_${c.statusCode}`,
|
|
139
|
+
}))));
|
|
140
|
+
return ops.refType(name);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!schema)
|
|
144
|
+
return protoEmpty;
|
|
145
|
+
if (schema.$ref) {
|
|
146
|
+
const target = ops.dispatch(schema, ops.ctx(rpc));
|
|
147
|
+
if (isMessageType(target))
|
|
148
|
+
return target;
|
|
149
|
+
}
|
|
150
|
+
const name = claim();
|
|
151
|
+
state.decls.push(ops.isMessageShape(schema)
|
|
152
|
+
? namedMessage(ops, name, schema)
|
|
153
|
+
: ops.wrapperMessage(name, ops.dispatch(schema, ops.ctx(name, ["Value"]))));
|
|
154
|
+
return ops.refType(name);
|
|
155
|
+
}
|
|
156
|
+
/** Message declared under `name` for an object or multi-branch union. */
|
|
157
|
+
function namedMessage(ops, name, schema) {
|
|
158
|
+
if (schema.type === "object" && !schema.oneOf && !schema.anyOf) {
|
|
159
|
+
return ops.message(name, Array.from(iterateObjectProperties(schema)), schema.description);
|
|
160
|
+
}
|
|
161
|
+
return ops.unionMessage(name, schema);
|
|
162
|
+
}
|
|
163
|
+
function isStringEnum(schema) {
|
|
164
|
+
const values = extractEnumValues(schema);
|
|
165
|
+
return (!schema.$ref &&
|
|
166
|
+
values !== undefined &&
|
|
167
|
+
values.length > 0 &&
|
|
168
|
+
classifyEnumLiterals(values.filter((v) => typeof v === "string" ||
|
|
169
|
+
typeof v === "number" ||
|
|
170
|
+
typeof v === "boolean")) === "string");
|
|
171
|
+
}
|
|
172
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
173
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,uBAAuB,EACvB,cAAc,EAEd,gBAAgB,EAEhB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,aAAa,EAIb,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,cAAc,EAAkC,MAAM,UAAU,CAAC;AAC1E,OAAO,E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AC,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Namespace } from "@ir-kit/codegen-core";
|
|
2
|
+
/** `PetStatus` → `PET_STATUS`, `in-progress` → `IN_PROGRESS`. */
|
|
3
|
+
export declare function upperSnake(s: string): string;
|
|
4
|
+
/** Field names: `petId` → `pet_id`, never starting with a digit. */
|
|
5
|
+
export declare function fieldIdent(s: string): string;
|
|
6
|
+
/** protoc's default JSON name for a field: `pet_id` → `petId`. */
|
|
7
|
+
export declare function defaultJsonName(field: string): string;
|
|
8
|
+
export declare function typeIdent(s: string): string;
|
|
9
|
+
export declare function packageIdent(title: string | undefined): string;
|
|
10
|
+
/** Message, enum and service names share one package scope. */
|
|
11
|
+
export declare function newTypeNames(): Namespace;
|
|
12
|
+
export declare function newFieldNames(): Namespace;
|
|
13
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,sBAAsB,CAAC;AAEzD,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG3C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAG9D;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAED,wBAAgB,aAAa,IAAI,SAAS,CAKzC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Namespace, pascal } from "@ir-kit/codegen-core";
|
|
2
|
+
/** `PetStatus` → `PET_STATUS`, `in-progress` → `IN_PROGRESS`. */
|
|
3
|
+
export function upperSnake(s) {
|
|
4
|
+
return snakeWords(s).toUpperCase();
|
|
5
|
+
}
|
|
6
|
+
/** Field names: `petId` → `pet_id`, never starting with a digit. */
|
|
7
|
+
export function fieldIdent(s) {
|
|
8
|
+
const snake = snakeWords(s).toLowerCase() || "field";
|
|
9
|
+
return /^[0-9]/.test(snake) ? `f_${snake}` : snake;
|
|
10
|
+
}
|
|
11
|
+
/** protoc's default JSON name for a field: `pet_id` → `petId`. */
|
|
12
|
+
export function defaultJsonName(field) {
|
|
13
|
+
return field.replace(/_+([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
14
|
+
}
|
|
15
|
+
export function typeIdent(s) {
|
|
16
|
+
const p = pascal(s) || "Empty";
|
|
17
|
+
return /^[0-9]/.test(p) ? `X${p}` : p;
|
|
18
|
+
}
|
|
19
|
+
export function packageIdent(title) {
|
|
20
|
+
const snake = fieldIdent(title ?? "");
|
|
21
|
+
return snake === "field" ? "api" : snake.replace(/^f_/, "api_");
|
|
22
|
+
}
|
|
23
|
+
/** Message, enum and service names share one package scope. */
|
|
24
|
+
export function newTypeNames() {
|
|
25
|
+
return new Namespace({ normalize: typeIdent, foldCase: true });
|
|
26
|
+
}
|
|
27
|
+
export function newFieldNames() {
|
|
28
|
+
return new Namespace({
|
|
29
|
+
normalize: fieldIdent,
|
|
30
|
+
disambiguate: (b, n) => `${b}_${n}`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function snakeWords(s) {
|
|
34
|
+
return s
|
|
35
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
36
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
37
|
+
.replace(/[^A-Za-z0-9]+/g, "_")
|
|
38
|
+
.replace(/^_+|_+$/g, "");
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEzD,iEAAiE;AACjE,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACrC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC;IACrD,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACrD,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IAC/B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAyB;IACpD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACtC,OAAO,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,SAAS,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,SAAS,CAAC;QACnB,SAAS,EAAE,UAAU;QACrB,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;KACpC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC;SACL,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC;SACzC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Namespace } from "@ir-kit/codegen-core";
|
|
2
|
+
import { type ObjectProperty, type Schema, type SchemaToTypeOps, type TypeCtx } from "@ir-kit/openapi";
|
|
3
|
+
import { type ProtoDecl, type ProtoMessage, type ProtoType } from "./ast.js";
|
|
4
|
+
export interface ProtoState {
|
|
5
|
+
names: Namespace;
|
|
6
|
+
/** Enum value names are package-scoped (C++ scoping rules). */
|
|
7
|
+
enumValues: Set<string>;
|
|
8
|
+
/** Names declared (or about to be declared) as enums. */
|
|
9
|
+
enums: Set<string>;
|
|
10
|
+
/** Component schemas that don't declare a message or enum of their
|
|
11
|
+
* own (`$ref`s, arrays, maps, scalars). Proto has no type aliases, so
|
|
12
|
+
* each reference is replaced by the aliased type. */
|
|
13
|
+
aliases: Map<string, Schema>;
|
|
14
|
+
decls: ProtoDecl[];
|
|
15
|
+
}
|
|
16
|
+
export type ProtoCtx = TypeCtx<ProtoDecl>;
|
|
17
|
+
export interface ProtoOps extends SchemaToTypeOps<ProtoType, ProtoDecl> {
|
|
18
|
+
dispatch(schema: Schema, ctx: ProtoCtx): ProtoType;
|
|
19
|
+
ctx(ownerName: string, propPath?: ReadonlyArray<string>): ProtoCtx;
|
|
20
|
+
/** Message with one field per property. */
|
|
21
|
+
message(name: string, properties: ReadonlyArray<ObjectProperty>, comment?: string): ProtoMessage;
|
|
22
|
+
/** Message holding a `oneof` with one field per union branch. */
|
|
23
|
+
unionMessage(name: string, schema: Schema): ProtoMessage;
|
|
24
|
+
/** Message holding a `oneof` with the given branches. */
|
|
25
|
+
oneofMessage(name: string, branches: ReadonlyArray<OneofBranch>, comment?: string): ProtoMessage;
|
|
26
|
+
/** Message wrapping a single value of any type in field `value`. */
|
|
27
|
+
wrapperMessage(name: string, type: ProtoType): ProtoMessage;
|
|
28
|
+
/** Schema that becomes its own message when given a name: a plain
|
|
29
|
+
* object or a multi-branch union. */
|
|
30
|
+
isMessageShape(schema: Schema): boolean;
|
|
31
|
+
}
|
|
32
|
+
/** A `oneof` branch. `label` names its field and synthesized type
|
|
33
|
+
* (otherwise it's named after its type); no `schema` means an empty
|
|
34
|
+
* result (`google.protobuf.Empty`). */
|
|
35
|
+
export interface OneofBranch {
|
|
36
|
+
schema?: Schema;
|
|
37
|
+
label?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function createProtoOps(state: ProtoState): ProtoOps;
|
|
40
|
+
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops.d.ts","sourceRoot":"","sources":["../../../src/converters/openapi3-to-proto/ops.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,eAAe,EAGpB,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,YAAY,EACjB,KAAK,SA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