@tertiumorganum/typespec-amqp-ws 0.0.2
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/LICENSE +21 -0
- package/README.md +291 -0
- package/dist/src/amqp/builder.d.ts +4 -0
- package/dist/src/amqp/builder.d.ts.map +1 -0
- package/dist/src/amqp/builder.js +121 -0
- package/dist/src/amqp/builder.js.map +1 -0
- package/dist/src/amqp/decorators.d.ts +32 -0
- package/dist/src/amqp/decorators.d.ts.map +1 -0
- package/dist/src/amqp/decorators.js +38 -0
- package/dist/src/amqp/decorators.js.map +1 -0
- package/dist/src/amqp/index.d.ts +5 -0
- package/dist/src/amqp/index.d.ts.map +1 -0
- package/dist/src/amqp/index.js +7 -0
- package/dist/src/amqp/index.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/shared/asyncapi-emitter.d.ts +5 -0
- package/dist/src/shared/asyncapi-emitter.d.ts.map +1 -0
- package/dist/src/shared/asyncapi-emitter.js +70 -0
- package/dist/src/shared/asyncapi-emitter.js.map +1 -0
- package/dist/src/shared/decorators-service.d.ts +33 -0
- package/dist/src/shared/decorators-service.d.ts.map +1 -0
- package/dist/src/shared/decorators-service.js +13 -0
- package/dist/src/shared/decorators-service.js.map +1 -0
- package/dist/src/shared/document.d.ts +134 -0
- package/dist/src/shared/document.d.ts.map +1 -0
- package/dist/src/shared/document.js +4 -0
- package/dist/src/shared/document.js.map +1 -0
- package/dist/src/shared/lib.d.ts +250 -0
- package/dist/src/shared/lib.d.ts.map +1 -0
- package/dist/src/shared/lib.js +108 -0
- package/dist/src/shared/lib.js.map +1 -0
- package/dist/src/shared/options.d.ts +8 -0
- package/dist/src/shared/options.d.ts.map +1 -0
- package/dist/src/shared/options.js +25 -0
- package/dist/src/shared/options.js.map +1 -0
- package/dist/src/shared/schema-emitter.d.ts +34 -0
- package/dist/src/shared/schema-emitter.d.ts.map +1 -0
- package/dist/src/shared/schema-emitter.js +351 -0
- package/dist/src/shared/schema-emitter.js.map +1 -0
- package/dist/src/shared/state.d.ts +13 -0
- package/dist/src/shared/state.d.ts.map +1 -0
- package/dist/src/shared/state.js +14 -0
- package/dist/src/shared/state.js.map +1 -0
- package/dist/src/shared/yaml-writer.d.ts +7 -0
- package/dist/src/shared/yaml-writer.d.ts.map +1 -0
- package/dist/src/shared/yaml-writer.js +8 -0
- package/dist/src/shared/yaml-writer.js.map +1 -0
- package/dist/src/testing.d.ts +2 -0
- package/dist/src/testing.d.ts.map +1 -0
- package/dist/src/testing.js +6 -0
- package/dist/src/testing.js.map +1 -0
- package/dist/src/ws/builder.d.ts +4 -0
- package/dist/src/ws/builder.d.ts.map +1 -0
- package/dist/src/ws/builder.js +94 -0
- package/dist/src/ws/builder.js.map +1 -0
- package/dist/src/ws/decorators.d.ts +12 -0
- package/dist/src/ws/decorators.d.ts.map +1 -0
- package/dist/src/ws/decorators.js +18 -0
- package/dist/src/ws/decorators.js.map +1 -0
- package/dist/src/ws/index.d.ts +5 -0
- package/dist/src/ws/index.d.ts.map +1 -0
- package/dist/src/ws/index.js +7 -0
- package/dist/src/ws/index.js.map +1 -0
- package/lib/amqp.tsp +83 -0
- package/lib/main.tsp +65 -0
- package/lib/ws.tsp +42 -0
- package/package.json +57 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JSONSchemaType } from "@typespec/compiler";
|
|
2
|
+
export interface EmitterOptions {
|
|
3
|
+
"file-type"?: "yaml" | "json";
|
|
4
|
+
"output-file"?: string;
|
|
5
|
+
"new-line"?: "lf" | "crlf";
|
|
6
|
+
}
|
|
7
|
+
export declare const EmitterOptionsSchema: JSONSchemaType<EmitterOptions>;
|
|
8
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/shared/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,cAAc,CAuB/D,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const EmitterOptionsSchema = {
|
|
2
|
+
type: "object",
|
|
3
|
+
additionalProperties: false,
|
|
4
|
+
properties: {
|
|
5
|
+
"file-type": {
|
|
6
|
+
type: "string",
|
|
7
|
+
enum: ["yaml", "json"],
|
|
8
|
+
nullable: true,
|
|
9
|
+
default: "yaml",
|
|
10
|
+
},
|
|
11
|
+
"output-file": {
|
|
12
|
+
type: "string",
|
|
13
|
+
nullable: true,
|
|
14
|
+
default: "asyncapi.yaml",
|
|
15
|
+
},
|
|
16
|
+
"new-line": {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["lf", "crlf"],
|
|
19
|
+
nullable: true,
|
|
20
|
+
default: "lf",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
required: [],
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/shared/options.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,oBAAoB,GAAmC;IAClE,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;YACtB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,MAAM;SAChB;QACD,aAAa,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,eAAe;SACzB;QACD,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;YACpB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI;SACd;KACF;IACD,QAAQ,EAAE,EAAE;CACb,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Program, Type } from "@typespec/compiler";
|
|
2
|
+
import type { Schema } from "./document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Преобразует TypeSpec-типы в JSON Schema-фрагменты и собирает их в components.schemas.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SchemaBuilder {
|
|
7
|
+
private readonly program;
|
|
8
|
+
private readonly namedSchemas;
|
|
9
|
+
constructor(program: Program);
|
|
10
|
+
/** Обход программы и сбор всех именованных типов. */
|
|
11
|
+
collect(): void;
|
|
12
|
+
/** Возвращает finalized map имён → схем для components.schemas. */
|
|
13
|
+
collectedSchemas(): Record<string, Schema>;
|
|
14
|
+
/** Конвертирует TypeSpec тип в JSON Schema. */
|
|
15
|
+
schemaFor(type: Type): Schema;
|
|
16
|
+
/** Поддерживаем только T | null. Прочие union'ы — ошибка. */
|
|
17
|
+
private unionSchema;
|
|
18
|
+
/** Скаляр в позиции использования: builtin → inline, custom → $ref. */
|
|
19
|
+
private scalarSchemaForUsage;
|
|
20
|
+
private isCustomScalar;
|
|
21
|
+
private addModel;
|
|
22
|
+
/**
|
|
23
|
+
* Прикрепляет description к field-схеме.
|
|
24
|
+
* Если схема — $ref, оборачивает в allOf (JSON Schema запрещает соседство $ref с другими полями).
|
|
25
|
+
* Иначе — добавляет description inline.
|
|
26
|
+
*/
|
|
27
|
+
private attachDescription;
|
|
28
|
+
private addScalar;
|
|
29
|
+
private rootBaseScalar;
|
|
30
|
+
private addEnum;
|
|
31
|
+
private scalarSchema;
|
|
32
|
+
private reportForbidden;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=schema-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-emitter.d.ts","sourceRoot":"","sources":["../../../src/shared/schema-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EAML,MAAM,oBAAoB,CAAC;AA0C5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AA6B5C;;GAEG;AACH,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6B;gBAE7B,OAAO,EAAE,OAAO;IAE7C,qDAAqD;IACrD,OAAO,IAAI,IAAI;IAQf,mEAAmE;IACnE,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAI1C,+CAA+C;IAC/C,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IA+B7B,6DAA6D;IAC7D,OAAO,CAAC,WAAW;IAoCnB,uEAAuE;IACvE,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,QAAQ;IA+ChB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,SAAS;IAoBjB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,OAAO;IA0Cf,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,eAAe;CAwCxB"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { navigateProgram, getDoc, isArrayModelType, isRecordModelType, } from "@typespec/compiler";
|
|
2
|
+
/** Скип stdlib и наших собственных library-моделей (TspAsyncApi.*) */
|
|
3
|
+
function isInLibraryNs(t) {
|
|
4
|
+
let ns = t.namespace;
|
|
5
|
+
while (ns) {
|
|
6
|
+
if (ns.name === "TypeSpec")
|
|
7
|
+
return true;
|
|
8
|
+
if (ns.name === "TspAsyncApi")
|
|
9
|
+
return true;
|
|
10
|
+
ns = ns.namespace;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
// Сохраняем старое имя для обратной совместимости в коде ниже.
|
|
15
|
+
const isInTypeSpecNs = isInLibraryNs;
|
|
16
|
+
/**
|
|
17
|
+
* Полное имя типа с префиксом namespace через `.`.
|
|
18
|
+
* Top-level (root service) namespace в префикс не входит.
|
|
19
|
+
* Например, для `namespace T; namespace business_event { model X }` → "business_event.X".
|
|
20
|
+
*/
|
|
21
|
+
function schemaNameOf(t) {
|
|
22
|
+
const parts = [];
|
|
23
|
+
let ns = t.namespace;
|
|
24
|
+
// Соберём имена всех родительских namespace, кроме самого корневого (его родитель — global).
|
|
25
|
+
while (ns && ns.namespace && ns.namespace.name) {
|
|
26
|
+
if (ns.name)
|
|
27
|
+
parts.unshift(ns.name);
|
|
28
|
+
ns = ns.namespace;
|
|
29
|
+
}
|
|
30
|
+
return parts.length > 0 ? `${parts.join(".")}.${t.name}` : t.name;
|
|
31
|
+
}
|
|
32
|
+
function capitalize(s) {
|
|
33
|
+
return s.length === 0 ? s : s[0].toUpperCase() + s.slice(1);
|
|
34
|
+
}
|
|
35
|
+
import { reportDiagnostic } from "./lib.js";
|
|
36
|
+
const ID_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
37
|
+
const BUILTIN_SCALAR_NAMES = new Set([
|
|
38
|
+
"string",
|
|
39
|
+
"boolean",
|
|
40
|
+
"integer",
|
|
41
|
+
"bytes",
|
|
42
|
+
...["int8", "int16", "int32", "uint8", "uint16", "uint32"],
|
|
43
|
+
...["int64", "uint64"],
|
|
44
|
+
...["float32", "float64", "decimal", "decimal128", "float"],
|
|
45
|
+
...["safeint", "numeric"],
|
|
46
|
+
...["utcDateTime", "offsetDateTime", "plainDate", "plainTime", "duration"],
|
|
47
|
+
"url",
|
|
48
|
+
]);
|
|
49
|
+
const SIZED_INT = new Set(["int8", "int16", "int32", "uint8", "uint16", "uint32"]);
|
|
50
|
+
const INT64 = new Set(["int64", "uint64"]);
|
|
51
|
+
const FLOAT = new Set(["float32", "float64", "decimal", "decimal128", "float"]);
|
|
52
|
+
const FUZZY = new Set(["safeint", "numeric"]);
|
|
53
|
+
const TEMPORAL = new Set([
|
|
54
|
+
"utcDateTime",
|
|
55
|
+
"offsetDateTime",
|
|
56
|
+
"plainDate",
|
|
57
|
+
"plainTime",
|
|
58
|
+
"duration",
|
|
59
|
+
]);
|
|
60
|
+
/**
|
|
61
|
+
* Преобразует TypeSpec-типы в JSON Schema-фрагменты и собирает их в components.schemas.
|
|
62
|
+
*/
|
|
63
|
+
export class SchemaBuilder {
|
|
64
|
+
program;
|
|
65
|
+
namedSchemas = new Map();
|
|
66
|
+
constructor(program) {
|
|
67
|
+
this.program = program;
|
|
68
|
+
}
|
|
69
|
+
/** Обход программы и сбор всех именованных типов. */
|
|
70
|
+
collect() {
|
|
71
|
+
navigateProgram(this.program, {
|
|
72
|
+
model: (m) => this.addModel(m),
|
|
73
|
+
enum: (e) => this.addEnum(e),
|
|
74
|
+
scalar: (s) => this.addScalar(s),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Возвращает finalized map имён → схем для components.schemas. */
|
|
78
|
+
collectedSchemas() {
|
|
79
|
+
return Object.fromEntries(this.namedSchemas);
|
|
80
|
+
}
|
|
81
|
+
/** Конвертирует TypeSpec тип в JSON Schema. */
|
|
82
|
+
schemaFor(type) {
|
|
83
|
+
if (type.kind === "Scalar") {
|
|
84
|
+
return this.scalarSchemaForUsage(type);
|
|
85
|
+
}
|
|
86
|
+
if (type.kind === "Enum" && type.name) {
|
|
87
|
+
return { $ref: `#/components/schemas/${schemaNameOf(type)}` };
|
|
88
|
+
}
|
|
89
|
+
if (type.kind === "String") {
|
|
90
|
+
return { type: "string", const: type.value };
|
|
91
|
+
}
|
|
92
|
+
if (type.kind === "Model") {
|
|
93
|
+
// Array<T> и Record<T,V>
|
|
94
|
+
if (isArrayModelType(this.program, type)) {
|
|
95
|
+
const itemType = type.indexer.value;
|
|
96
|
+
return { type: "array", items: this.schemaFor(itemType) };
|
|
97
|
+
}
|
|
98
|
+
if (isRecordModelType(this.program, type)) {
|
|
99
|
+
const valueType = type.indexer.value;
|
|
100
|
+
return { type: "object", additionalProperties: this.schemaFor(valueType) };
|
|
101
|
+
}
|
|
102
|
+
if (type.name && !isInTypeSpecNs(type)) {
|
|
103
|
+
return { $ref: `#/components/schemas/${schemaNameOf(type)}` };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (type.kind === "Union") {
|
|
107
|
+
return this.unionSchema(type);
|
|
108
|
+
}
|
|
109
|
+
// Заглушка
|
|
110
|
+
return { type: "string" };
|
|
111
|
+
}
|
|
112
|
+
/** Поддерживаем только T | null. Прочие union'ы — ошибка. */
|
|
113
|
+
unionSchema(u) {
|
|
114
|
+
const variants = [...u.variants.values()];
|
|
115
|
+
let hasNull = false;
|
|
116
|
+
const nonNull = [];
|
|
117
|
+
for (const v of variants) {
|
|
118
|
+
const t = v.type;
|
|
119
|
+
if (t.kind === "Intrinsic" && t.name === "null") {
|
|
120
|
+
hasNull = true;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
nonNull.push(v);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!hasNull || nonNull.length !== 1) {
|
|
127
|
+
reportDiagnostic(this.program, {
|
|
128
|
+
code: "unsupported-union",
|
|
129
|
+
target: u,
|
|
130
|
+
format: {},
|
|
131
|
+
});
|
|
132
|
+
return { type: "string" };
|
|
133
|
+
}
|
|
134
|
+
const base = this.schemaFor(nonNull[0].type);
|
|
135
|
+
if (!("type" in base) || typeof base.type !== "string") {
|
|
136
|
+
// Nullable $ref пока не поддерживаем — JSON Schema требует unwrap'нутый base.
|
|
137
|
+
reportDiagnostic(this.program, {
|
|
138
|
+
code: "unsupported-union",
|
|
139
|
+
target: u,
|
|
140
|
+
format: {},
|
|
141
|
+
});
|
|
142
|
+
return { type: "string" };
|
|
143
|
+
}
|
|
144
|
+
const t = base.type;
|
|
145
|
+
return { type: [t, "null"] };
|
|
146
|
+
}
|
|
147
|
+
/** Скаляр в позиции использования: builtin → inline, custom → $ref. */
|
|
148
|
+
scalarSchemaForUsage(s) {
|
|
149
|
+
if (this.isCustomScalar(s)) {
|
|
150
|
+
return { $ref: `#/components/schemas/${schemaNameOf(s)}` };
|
|
151
|
+
}
|
|
152
|
+
return this.scalarSchema(s);
|
|
153
|
+
}
|
|
154
|
+
isCustomScalar(s) {
|
|
155
|
+
// Любой скаляр из стандартной библиотеки (TypeSpec.* — любая глубина вложенности) — НЕ custom.
|
|
156
|
+
if (isInTypeSpecNs(s))
|
|
157
|
+
return false;
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
addModel(m) {
|
|
161
|
+
if (!m.name)
|
|
162
|
+
return;
|
|
163
|
+
if (isInTypeSpecNs(m))
|
|
164
|
+
return;
|
|
165
|
+
if (isArrayModelType(this.program, m))
|
|
166
|
+
return;
|
|
167
|
+
if (isRecordModelType(this.program, m))
|
|
168
|
+
return;
|
|
169
|
+
const key = schemaNameOf(m);
|
|
170
|
+
if (this.namedSchemas.has(key))
|
|
171
|
+
return;
|
|
172
|
+
const properties = {};
|
|
173
|
+
const required = [];
|
|
174
|
+
for (const [propName, prop] of m.properties) {
|
|
175
|
+
// Запрет на анонимные inline-модели в полях.
|
|
176
|
+
if (prop.type.kind === "Model" &&
|
|
177
|
+
!prop.type.name &&
|
|
178
|
+
!isArrayModelType(this.program, prop.type) &&
|
|
179
|
+
!isRecordModelType(this.program, prop.type)) {
|
|
180
|
+
reportDiagnostic(this.program, {
|
|
181
|
+
code: "anonymous-model",
|
|
182
|
+
target: prop,
|
|
183
|
+
format: {
|
|
184
|
+
field: propName,
|
|
185
|
+
parent: m.name,
|
|
186
|
+
suggested: `${capitalize(m.name)}${capitalize(propName)}`,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const baseSchema = this.schemaFor(prop.type);
|
|
192
|
+
const propDoc = getDoc(this.program, prop);
|
|
193
|
+
properties[propName] = this.attachDescription(baseSchema, propDoc);
|
|
194
|
+
if (!prop.optional)
|
|
195
|
+
required.push(propName);
|
|
196
|
+
}
|
|
197
|
+
const description = getDoc(this.program, m);
|
|
198
|
+
const schema = {
|
|
199
|
+
type: "object",
|
|
200
|
+
properties,
|
|
201
|
+
...(required.length > 0 ? { required } : {}),
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
...(description ? { description } : {}),
|
|
204
|
+
};
|
|
205
|
+
this.namedSchemas.set(key, schema);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Прикрепляет description к field-схеме.
|
|
209
|
+
* Если схема — $ref, оборачивает в allOf (JSON Schema запрещает соседство $ref с другими полями).
|
|
210
|
+
* Иначе — добавляет description inline.
|
|
211
|
+
*/
|
|
212
|
+
attachDescription(schema, doc) {
|
|
213
|
+
if (!doc)
|
|
214
|
+
return schema;
|
|
215
|
+
if ("$ref" in schema) {
|
|
216
|
+
return { allOf: [schema], description: doc };
|
|
217
|
+
}
|
|
218
|
+
return { ...schema, description: doc };
|
|
219
|
+
}
|
|
220
|
+
addScalar(s) {
|
|
221
|
+
if (!this.isCustomScalar(s))
|
|
222
|
+
return;
|
|
223
|
+
const key = schemaNameOf(s);
|
|
224
|
+
if (this.namedSchemas.has(key))
|
|
225
|
+
return;
|
|
226
|
+
// Прокатиться по цепочке extends до builtin'а.
|
|
227
|
+
const base = this.rootBaseScalar(s);
|
|
228
|
+
if (!base)
|
|
229
|
+
return;
|
|
230
|
+
const baseSchema = this.scalarSchema(base);
|
|
231
|
+
const description = getDoc(this.program, s);
|
|
232
|
+
if ("$ref" in baseSchema)
|
|
233
|
+
return; // не должно случиться, но защитимся
|
|
234
|
+
// Сплющиваем: schema = { ...baseSchema, description? }
|
|
235
|
+
const schema = description
|
|
236
|
+
? { ...baseSchema, description }
|
|
237
|
+
: baseSchema;
|
|
238
|
+
this.namedSchemas.set(key, schema);
|
|
239
|
+
}
|
|
240
|
+
rootBaseScalar(s) {
|
|
241
|
+
let current = s;
|
|
242
|
+
while (current && this.isCustomScalar(current)) {
|
|
243
|
+
current = current.baseScalar;
|
|
244
|
+
}
|
|
245
|
+
return current;
|
|
246
|
+
}
|
|
247
|
+
addEnum(e) {
|
|
248
|
+
if (!e.name)
|
|
249
|
+
return;
|
|
250
|
+
if (isInTypeSpecNs(e))
|
|
251
|
+
return;
|
|
252
|
+
const key = schemaNameOf(e);
|
|
253
|
+
if (this.namedSchemas.has(key))
|
|
254
|
+
return;
|
|
255
|
+
const values = [];
|
|
256
|
+
let hasError = false;
|
|
257
|
+
for (const [memberName, member] of e.members) {
|
|
258
|
+
// member.value undefined → используем имя, иначе значение должно быть строкой
|
|
259
|
+
if (member.value !== undefined && typeof member.value !== "string") {
|
|
260
|
+
reportDiagnostic(this.program, {
|
|
261
|
+
code: "non-string-enum",
|
|
262
|
+
target: e,
|
|
263
|
+
format: { name: e.name },
|
|
264
|
+
});
|
|
265
|
+
hasError = true;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
const v = member.value ?? memberName;
|
|
269
|
+
if (!ID_REGEX.test(v)) {
|
|
270
|
+
reportDiagnostic(this.program, {
|
|
271
|
+
code: "invalid-enum-value",
|
|
272
|
+
target: member,
|
|
273
|
+
format: { value: v },
|
|
274
|
+
});
|
|
275
|
+
hasError = true;
|
|
276
|
+
}
|
|
277
|
+
values.push(v);
|
|
278
|
+
}
|
|
279
|
+
if (hasError)
|
|
280
|
+
return;
|
|
281
|
+
const description = getDoc(this.program, e);
|
|
282
|
+
const schema = {
|
|
283
|
+
type: "string",
|
|
284
|
+
enum: values,
|
|
285
|
+
...(description ? { description } : {}),
|
|
286
|
+
};
|
|
287
|
+
this.namedSchemas.set(key, schema);
|
|
288
|
+
}
|
|
289
|
+
scalarSchema(s) {
|
|
290
|
+
switch (s.name) {
|
|
291
|
+
case "string":
|
|
292
|
+
return { type: "string" };
|
|
293
|
+
case "boolean":
|
|
294
|
+
return { type: "boolean" };
|
|
295
|
+
case "integer":
|
|
296
|
+
return { type: "integer" };
|
|
297
|
+
case "bytes":
|
|
298
|
+
return { type: "string", format: "binary" };
|
|
299
|
+
default:
|
|
300
|
+
this.reportForbidden(s);
|
|
301
|
+
return { type: "string" }; // fallback, чтобы компиляция не падала каскадно
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
reportForbidden(s) {
|
|
305
|
+
if (s.namespace?.name !== "TypeSpec")
|
|
306
|
+
return; // пользовательские скаляры — Task 9
|
|
307
|
+
if (SIZED_INT.has(s.name)) {
|
|
308
|
+
reportDiagnostic(this.program, {
|
|
309
|
+
code: "unsupported-sized-int",
|
|
310
|
+
target: s,
|
|
311
|
+
format: { name: s.name },
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
else if (INT64.has(s.name)) {
|
|
315
|
+
reportDiagnostic(this.program, {
|
|
316
|
+
code: "unsupported-int64",
|
|
317
|
+
target: s,
|
|
318
|
+
format: {},
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
else if (FLOAT.has(s.name)) {
|
|
322
|
+
reportDiagnostic(this.program, {
|
|
323
|
+
code: "unsupported-float",
|
|
324
|
+
target: s,
|
|
325
|
+
format: {},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
else if (FUZZY.has(s.name)) {
|
|
329
|
+
reportDiagnostic(this.program, {
|
|
330
|
+
code: "unsupported-fuzzy-numeric",
|
|
331
|
+
target: s,
|
|
332
|
+
format: { name: s.name },
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
else if (TEMPORAL.has(s.name)) {
|
|
336
|
+
reportDiagnostic(this.program, {
|
|
337
|
+
code: "unsupported-temporal",
|
|
338
|
+
target: s,
|
|
339
|
+
format: { name: s.name },
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
else if (s.name === "url") {
|
|
343
|
+
reportDiagnostic(this.program, {
|
|
344
|
+
code: "unsupported-url",
|
|
345
|
+
target: s,
|
|
346
|
+
format: {},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=schema-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-emitter.js","sourceRoot":"","sources":["../../../src/shared/schema-emitter.ts"],"names":[],"mappings":"AASA,OAAO,EACL,eAAe,EACf,MAAM,EACN,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,sEAAsE;AACtE,SAAS,aAAa,CAAC,CAA4B;IACjD,IAAI,EAAE,GAA0B,CAAC,CAAC,SAAS,CAAC;IAC5C,OAAO,EAAE,EAAE,CAAC;QACV,IAAI,EAAE,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC;QACxC,IAAI,EAAE,CAAC,IAAI,KAAK,aAAa;YAAE,OAAO,IAAI,CAAC;QAC3C,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,+DAA+D;AAC/D,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC;;;;GAIG;AACH,SAAS,YAAY,CAAC,CAA0C;IAC9D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,EAAE,GAA0B,CAAC,CAAC,SAAS,CAAC;IAC5C,6FAA6F;IAC7F,OAAO,EAAE,IAAI,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAC/C,IAAI,EAAE,CAAC,IAAI;YAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACpC,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAA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MAAM,EAAE,EAAE;aACX,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAC7B,IAAI,EAAE,mBAAmB;gBACzB,MAAM,EAAE,CAAC;gBACT,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAC7B,IAAI,EAAE,2BAA2B;gBACjC,MAAM,EAAE,CAAC;gBACT,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;aACzB,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAC7B,IAAI,EAAE,sBAAsB;gBAC5B,MAAM,EAAE,CAAC;gBACT,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;aACzB,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YAC5B,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAC7B,IAAI,EAAE,iBAAiB;gBACvB,MAAM,EAAE,CAAC;gBACT,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const ServiceKey: unique symbol;
|
|
2
|
+
export declare const InfoKey: unique symbol;
|
|
3
|
+
export declare const ServerKey: unique symbol;
|
|
4
|
+
export declare const AmqpPublishKey: unique symbol;
|
|
5
|
+
export declare const AmqpConsumeKey: unique symbol;
|
|
6
|
+
export declare const WsPublishKey: unique symbol;
|
|
7
|
+
export declare const WsConsumeKey: unique symbol;
|
|
8
|
+
export declare const WsReplyKey: unique symbol;
|
|
9
|
+
export declare const WsBinaryKey: unique symbol;
|
|
10
|
+
export declare const ChannelKey: unique symbol;
|
|
11
|
+
export declare const SummaryKey: unique symbol;
|
|
12
|
+
export declare const MessageKey: unique symbol;
|
|
13
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/shared/state.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,eAAyC,CAAC;AACjE,eAAO,MAAM,OAAO,eAAsC,CAAC;AAC3D,eAAO,MAAM,SAAS,eAAwC,CAAC;AAE/D,eAAO,MAAM,cAAc,eAA8C,CAAC;AAC1E,eAAO,MAAM,cAAc,eAA8C,CAAC;AAE1E,eAAO,MAAM,YAAY,eAA4C,CAAC;AACtE,eAAO,MAAM,YAAY,eAA4C,CAAC;AACtE,eAAO,MAAM,UAAU,eAA0C,CAAC;AAClE,eAAO,MAAM,WAAW,eAA2C,CAAC;AAEpE,eAAO,MAAM,UAAU,eAAyC,CAAC;AACjE,eAAO,MAAM,UAAU,eAAyC,CAAC;AACjE,eAAO,MAAM,UAAU,eAAyC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Уникальные ключи для хранения декораторного состояния в program.stateMap.
|
|
2
|
+
export const ServiceKey = Symbol.for("typespec-amqp-ws.service");
|
|
3
|
+
export const InfoKey = Symbol.for("typespec-amqp-ws.info");
|
|
4
|
+
export const ServerKey = Symbol.for("typespec-amqp-ws.server");
|
|
5
|
+
export const AmqpPublishKey = Symbol.for("typespec-amqp-ws.amqp.publish");
|
|
6
|
+
export const AmqpConsumeKey = Symbol.for("typespec-amqp-ws.amqp.consume");
|
|
7
|
+
export const WsPublishKey = Symbol.for("typespec-amqp-ws.ws.publish");
|
|
8
|
+
export const WsConsumeKey = Symbol.for("typespec-amqp-ws.ws.consume");
|
|
9
|
+
export const WsReplyKey = Symbol.for("typespec-amqp-ws.ws.reply");
|
|
10
|
+
export const WsBinaryKey = Symbol.for("typespec-amqp-ws.ws.binary");
|
|
11
|
+
export const ChannelKey = Symbol.for("typespec-amqp-ws.channel");
|
|
12
|
+
export const SummaryKey = Symbol.for("typespec-amqp-ws.summary");
|
|
13
|
+
export const MessageKey = Symbol.for("typespec-amqp-ws.message");
|
|
14
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/shared/state.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAE1E,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AsyncApiDoc } from "./document.js";
|
|
2
|
+
export interface SerializeOptions {
|
|
3
|
+
fileType: "yaml" | "json";
|
|
4
|
+
newLine: "lf" | "crlf";
|
|
5
|
+
}
|
|
6
|
+
export declare function serialize(doc: AsyncApiDoc, opts: SerializeOptions): string;
|
|
7
|
+
//# sourceMappingURL=yaml-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-writer.d.ts","sourceRoot":"","sources":["../../../src/shared/yaml-writer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC;CACxB;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAM1E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as yaml from "js-yaml";
|
|
2
|
+
export function serialize(doc, opts) {
|
|
3
|
+
const text = opts.fileType === "yaml"
|
|
4
|
+
? yaml.dump(doc, { lineWidth: 120, noRefs: true, sortKeys: false })
|
|
5
|
+
: JSON.stringify(doc, null, 2);
|
|
6
|
+
return opts.newLine === "crlf" ? text.replace(/\n/g, "\r\n") : text;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=yaml-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-writer.js","sourceRoot":"","sources":["../../../src/shared/yaml-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAQhC,MAAM,UAAU,SAAS,CAAC,GAAgB,EAAE,IAAsB;IAChE,MAAM,IAAI,GACR,IAAI,CAAC,QAAQ,KAAK,MAAM;QACtB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACnE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/testing.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,0DAGpC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createTestLibrary, findTestPackageRoot } from "@typespec/compiler/testing";
|
|
2
|
+
export const TypeSpecAmqpWsTestLibrary = createTestLibrary({
|
|
3
|
+
name: "@tertiumorganum/typespec-amqp-ws",
|
|
4
|
+
packageRoot: await findTestPackageRoot(import.meta.url),
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEpF,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;IACzD,IAAI,EAAE,kCAAkC;IACxC,WAAW,EAAE,MAAM,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;CACxD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/ws/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,oBAAoB,CAAC;AASpE,OAAO,KAAK,EACV,WAAW,EAIZ,MAAM,uBAAuB,CAAC;AAM/B,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAqBhE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { navigateProgram, getDoc, getSummary } from "@typespec/compiler";
|
|
2
|
+
import { WsPublishKey, WsConsumeKey, WsReplyKey, WsBinaryKey, MessageKey, } from "../shared/state.js";
|
|
3
|
+
import { reportDiagnostic } from "../shared/lib.js";
|
|
4
|
+
const DEFAULT_CHANNEL = "/";
|
|
5
|
+
export function buildWs(program, doc) {
|
|
6
|
+
let hasOps = false;
|
|
7
|
+
navigateProgram(program, {
|
|
8
|
+
operation(op) {
|
|
9
|
+
const isPub = program.stateMap(WsPublishKey).has(op);
|
|
10
|
+
const isCon = program.stateMap(WsConsumeKey).has(op);
|
|
11
|
+
if (!isPub && !isCon)
|
|
12
|
+
return;
|
|
13
|
+
hasOps = true;
|
|
14
|
+
attach(program, doc, op, isPub ? "send" : "receive");
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// Если есть операции — гарантируем существование канала "/".
|
|
18
|
+
if (hasOps) {
|
|
19
|
+
doc.channels = doc.channels ?? {};
|
|
20
|
+
doc.channels[DEFAULT_CHANNEL] = doc.channels[DEFAULT_CHANNEL] ?? {
|
|
21
|
+
address: DEFAULT_CHANNEL,
|
|
22
|
+
messages: {},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function attach(program, doc, op, action) {
|
|
27
|
+
const rt = op.returnType;
|
|
28
|
+
if (rt.kind !== "Model" || !rt.name) {
|
|
29
|
+
reportDiagnostic(program, {
|
|
30
|
+
code: "anonymous-return",
|
|
31
|
+
target: op,
|
|
32
|
+
format: { op: op.name },
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const override = program.stateMap(MessageKey).get(op);
|
|
37
|
+
const messageKey = override?.name ?? lowerFirst(rt.name);
|
|
38
|
+
const isBinary = program.stateMap(WsBinaryKey).has(op);
|
|
39
|
+
doc.channels = doc.channels ?? {};
|
|
40
|
+
doc.operations = doc.operations ?? {};
|
|
41
|
+
doc.components = doc.components ?? {};
|
|
42
|
+
doc.components.messages = doc.components.messages ?? {};
|
|
43
|
+
// Регистрация message
|
|
44
|
+
const message = {
|
|
45
|
+
payload: { $ref: `#/components/schemas/${rt.name}` },
|
|
46
|
+
};
|
|
47
|
+
if (override?.summary)
|
|
48
|
+
message.summary = override.summary;
|
|
49
|
+
if (isBinary)
|
|
50
|
+
message.contentType = "application/octet-stream";
|
|
51
|
+
doc.components.messages[messageKey] = message;
|
|
52
|
+
// Регистрация канала (создаём если не было)
|
|
53
|
+
const channel = doc.channels[DEFAULT_CHANNEL] ?? { address: DEFAULT_CHANNEL, messages: {} };
|
|
54
|
+
channel.messages = channel.messages ?? {};
|
|
55
|
+
channel.messages[messageKey] = { $ref: `#/components/messages/${messageKey}` };
|
|
56
|
+
// Reply
|
|
57
|
+
let replyBlock;
|
|
58
|
+
const replyType = program.stateMap(WsReplyKey).get(op);
|
|
59
|
+
if (replyType && replyType.name) {
|
|
60
|
+
const replyKey = lowerFirst(replyType.name);
|
|
61
|
+
doc.components.messages[replyKey] = {
|
|
62
|
+
payload: { $ref: `#/components/schemas/${replyType.name}` },
|
|
63
|
+
};
|
|
64
|
+
channel.messages[replyKey] = { $ref: `#/components/messages/${replyKey}` };
|
|
65
|
+
replyBlock = {
|
|
66
|
+
channel: { $ref: `#/channels/${escapePointer(DEFAULT_CHANNEL)}` },
|
|
67
|
+
messages: [
|
|
68
|
+
{ $ref: `#/channels/${escapePointer(DEFAULT_CHANNEL)}/messages/${replyKey}` },
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
doc.channels[DEFAULT_CHANNEL] = channel;
|
|
73
|
+
const summary = getSummary(program, op);
|
|
74
|
+
const description = getDoc(program, op);
|
|
75
|
+
const operation = {
|
|
76
|
+
action,
|
|
77
|
+
channel: { $ref: `#/channels/${escapePointer(DEFAULT_CHANNEL)}` },
|
|
78
|
+
messages: [{ $ref: `#/channels/${escapePointer(DEFAULT_CHANNEL)}/messages/${messageKey}` }],
|
|
79
|
+
};
|
|
80
|
+
if (summary)
|
|
81
|
+
operation.summary = summary;
|
|
82
|
+
if (description)
|
|
83
|
+
operation.description = description;
|
|
84
|
+
if (replyBlock)
|
|
85
|
+
operation.reply = replyBlock;
|
|
86
|
+
doc.operations[op.name] = operation;
|
|
87
|
+
}
|
|
88
|
+
function lowerFirst(s) {
|
|
89
|
+
return s.length === 0 ? s : s[0].toLowerCase() + s.slice(1);
|
|
90
|
+
}
|
|
91
|
+
function escapePointer(s) {
|
|
92
|
+
return s.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=builder.js.map
|