@typespec/emitter-framework 0.9.0-dev.3 → 0.9.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/src/csharp/components/class/declaration.d.ts +13 -0
  2. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -0
  3. package/dist/src/csharp/components/{class-declaration.js → class/declaration.js} +35 -41
  4. package/dist/src/csharp/components/class/declaration.test.d.ts +2 -0
  5. package/dist/src/csharp/components/class/declaration.test.d.ts.map +1 -0
  6. package/dist/src/csharp/components/class/declaration.test.js +392 -0
  7. package/dist/src/csharp/components/enum-declaration.d.ts +1 -1
  8. package/dist/src/csharp/components/enum-declaration.d.ts.map +1 -1
  9. package/dist/src/csharp/components/enum-declaration.js +12 -9
  10. package/dist/src/csharp/components/index.d.ts +2 -1
  11. package/dist/src/csharp/components/index.d.ts.map +1 -1
  12. package/dist/src/csharp/components/index.js +2 -1
  13. package/dist/src/csharp/components/property/property.d.ts +15 -0
  14. package/dist/src/csharp/components/property/property.d.ts.map +1 -0
  15. package/dist/src/csharp/components/property/property.js +85 -0
  16. package/dist/src/csharp/components/property/property.test.d.ts +2 -0
  17. package/dist/src/csharp/components/property/property.test.d.ts.map +1 -0
  18. package/dist/src/csharp/components/property/property.test.js +117 -0
  19. package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
  20. package/dist/src/csharp/components/type-expression.js +15 -1
  21. package/dist/src/csharp/components/type-expression.test.d.ts +2 -0
  22. package/dist/src/csharp/components/type-expression.test.d.ts.map +1 -0
  23. package/dist/src/csharp/components/type-expression.test.js +128 -0
  24. package/dist/src/csharp/components/utils/doc-comments.d.ts +14 -0
  25. package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -0
  26. package/dist/src/csharp/components/utils/doc-comments.js +67 -0
  27. package/dist/src/typescript/components/arrow-function.d.ts +1 -1
  28. package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
  29. package/dist/src/typescript/components/arrow-function.js +2 -1
  30. package/dist/src/typescript/components/function-expression.d.ts +1 -1
  31. package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
  32. package/dist/src/typescript/components/function-expression.js +2 -1
  33. package/dist/src/typescript/components/function-type.d.ts +1 -1
  34. package/dist/src/typescript/components/function-type.d.ts.map +1 -1
  35. package/dist/src/typescript/components/function-type.js +2 -1
  36. package/dist/test/csharp/components/enum-declaration.test.js +57 -9
  37. package/dist/test/test-host.d.ts +2 -0
  38. package/dist/test/test-host.d.ts.map +1 -0
  39. package/dist/test/test-host.js +5 -0
  40. package/dist/test/vitest.setup.d.ts +2 -0
  41. package/dist/test/vitest.setup.d.ts.map +1 -0
  42. package/dist/test/vitest.setup.js +1 -0
  43. package/package.json +10 -7
  44. package/src/csharp/components/class/declaration.test.tsx +401 -0
  45. package/src/csharp/components/class/declaration.tsx +86 -0
  46. package/src/csharp/components/enum-declaration.tsx +23 -15
  47. package/src/csharp/components/index.ts +2 -1
  48. package/src/csharp/components/property/property.test.tsx +97 -0
  49. package/src/csharp/components/property/property.tsx +62 -0
  50. package/src/csharp/components/type-expression.test.tsx +133 -0
  51. package/src/csharp/components/type-expression.tsx +10 -3
  52. package/src/csharp/components/utils/doc-comments.tsx +58 -0
  53. package/src/typescript/components/arrow-function.tsx +1 -1
  54. package/src/typescript/components/function-expression.tsx +1 -1
  55. package/src/typescript/components/function-type.tsx +1 -1
  56. package/test/csharp/components/enum-declaration.test.tsx +50 -9
  57. package/test/test-host.ts +4 -0
  58. package/test/vitest.setup.ts +1 -0
  59. package/tsconfig.json +2 -1
  60. package/vitest.config.ts +2 -1
  61. package/dist/src/csharp/components/class-declaration.d.ts +0 -9
  62. package/dist/src/csharp/components/class-declaration.d.ts.map +0 -1
  63. package/dist/test/csharp/components/class-declaration.test.d.ts +0 -2
  64. package/dist/test/csharp/components/class-declaration.test.d.ts.map +0 -1
  65. package/dist/test/csharp/components/class-declaration.test.js +0 -421
  66. package/src/csharp/components/class-declaration.tsx +0 -87
  67. package/test/csharp/components/class-declaration.test.tsx +0 -344
@@ -0,0 +1,13 @@
1
+ import * as ay from "@alloy-js/core";
2
+ import * as cs from "@alloy-js/csharp";
3
+ import { Interface, Model } from "@typespec/compiler";
4
+ export interface ClassDeclarationProps extends Omit<cs.ClassDeclarationProps, "name"> {
5
+ /** Set an alternative name for the class. Otherwise default to the type name. */
6
+ name?: string;
7
+ /** Type to use to create this class. */
8
+ type: Model | Interface;
9
+ /** If set the property will add the json serialization attributes(using System.Text.Json). */
10
+ jsonAttributes?: boolean;
11
+ }
12
+ export declare function ClassDeclaration(props: ClassDeclarationProps): ay.Children;
13
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/class/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOtD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,EAAE,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACnF,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,8FAA8F;IAC9F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAYD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,EAAE,CAAC,QAAQ,CAuB1E"}
@@ -1,9 +1,11 @@
1
- import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
2
  import * as ay from "@alloy-js/core";
3
3
  import * as cs from "@alloy-js/csharp";
4
- import { useTsp } from "../../core/index.js";
5
- import { TypeExpression } from "./type-expression.js";
6
- import { declarationRefkeys } from "./utils/refkey.js";
4
+ import { useTsp } from "../../../core/index.js";
5
+ import { Property } from "../property/property.js";
6
+ import { TypeExpression } from "../type-expression.js";
7
+ import { getDocComments } from "../utils/doc-comments.js";
8
+ import { declarationRefkeys } from "../utils/refkey.js";
7
9
  export function ClassDeclaration(props) {
8
10
  const {
9
11
  $
@@ -12,16 +14,19 @@ export function ClassDeclaration(props) {
12
14
  const className = props.name ?? namePolicy.getName(props.type.name, "class");
13
15
  const refkeys = declarationRefkeys(props.refkey, props.type)[0]; // TODO: support multiple refkeys for declarations in alloy
14
16
 
15
- return [_$createComponent(cs.Class, {
17
+ return [_$createComponent(cs.ClassDeclaration, _$mergeProps(props, {
16
18
  name: className,
17
- get accessModifier() {
18
- return props.accessModifier;
19
- },
20
19
  refkey: refkeys,
20
+ get doc() {
21
+ return getDocComments($, props.type);
22
+ },
21
23
  get children() {
22
- return [_$memo(() => _$memo(() => !!$.model.is(props.type))() && _$createComponent(ClassProperties, {
24
+ return [_$memo(() => _$memo(() => props.type.kind === "Model")() && _$createComponent(ClassProperties, {
23
25
  get type() {
24
26
  return props.type;
27
+ },
28
+ get jsonAttributes() {
29
+ return props.jsonAttributes;
25
30
  }
26
31
  })), _$memo(() => _$memo(() => props.type.kind === "Interface")() && _$createComponent(ClassMethods, {
27
32
  get type() {
@@ -29,50 +34,36 @@ export function ClassDeclaration(props) {
29
34
  }
30
35
  }))];
31
36
  }
32
- })];
37
+ }))];
33
38
  }
34
39
  function ClassProperties(props) {
35
- const namePolicy = cs.useCSharpNamePolicy();
36
- const classProperties = [];
37
- for (const [name, prop] of props.type.properties) {
38
- classProperties.push([_$createComponent(cs.ClassMember, {
39
- get name() {
40
- return namePolicy.getName(name, "class-member-public");
41
- },
42
- get type() {
43
- return _$createComponent(TypeExpression, {
44
- get type() {
45
- return prop.type;
46
- }
47
- });
48
- },
49
- accessModifier: "public"
50
- }), " ", _$createComponent(ay.Block, {
51
- newline: true,
52
- get children() {
53
- return _$createComponent(ay.StatementList, {
54
- children: ["get", "set"]
55
- });
56
- }
57
- })]);
58
- }
59
40
  return _$createComponent(ay.For, {
60
- each: classProperties,
41
+ get each() {
42
+ return props.type.properties.entries();
43
+ },
61
44
  hardline: true,
62
- children: c => c
45
+ children: ([name, property]) => _$createComponent(Property, {
46
+ type: property,
47
+ get jsonAttributes() {
48
+ return props.jsonAttributes;
49
+ }
50
+ })
63
51
  });
64
52
  }
65
53
  function ClassMethods(props) {
54
+ const {
55
+ $
56
+ } = useTsp();
66
57
  const namePolicy = cs.useCSharpNamePolicy();
67
58
  const abstractMethods = [];
68
- for (const [name, prop] of props.type.operations) {
59
+ for (const [name, method] of props.type.operations) {
69
60
  abstractMethods.push(_$createComponent(cs.ClassMethod, {
70
61
  get name() {
71
62
  return namePolicy.getName(name, "class-method");
72
63
  },
73
- methodModifier: "abstract",
64
+ abstract: true,
74
65
  get parameters() {
75
- return [...prop.parameters.properties.entries()].map(([name, prop]) => {
66
+ return [...method.parameters.properties.entries()].map(([name, prop]) => {
76
67
  return {
77
68
  name: namePolicy.getName(name, "type-parameter"),
78
69
  type: _$createComponent(TypeExpression, {
@@ -83,11 +74,14 @@ function ClassMethods(props) {
83
74
  };
84
75
  });
85
76
  },
86
- accessModifier: "public",
77
+ "public": true,
78
+ get doc() {
79
+ return getDocComments($, method);
80
+ },
87
81
  get returns() {
88
82
  return _$createComponent(TypeExpression, {
89
83
  get type() {
90
- return prop.returnType;
84
+ return method.returnType;
91
85
  }
92
86
  });
93
87
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declaration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/class/declaration.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,392 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { Tester } from "#test/test-host.js";
3
+ import { render } from "@alloy-js/core";
4
+ import { d } from "@alloy-js/core/testing";
5
+ import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
6
+ import { t } from "@typespec/compiler/testing";
7
+ import { beforeEach, describe, it } from "vitest";
8
+ import { assertFileContents } from "../../../../test/csharp/utils.js";
9
+ import { Output } from "../../../core/index.js";
10
+ import { ClassDeclaration, EnumDeclaration } from "../../index.js";
11
+ let runner;
12
+ beforeEach(async () => {
13
+ runner = await Tester.createInstance();
14
+ });
15
+ function Wrapper(props) {
16
+ const policy = createCSharpNamePolicy();
17
+ return _$createComponent(Output, {
18
+ get program() {
19
+ return runner.program;
20
+ },
21
+ namePolicy: policy,
22
+ get children() {
23
+ return _$createComponent(Namespace, {
24
+ name: "TestNamespace",
25
+ get children() {
26
+ return _$createComponent(SourceFile, {
27
+ path: "test.cs",
28
+ get children() {
29
+ return props.children;
30
+ }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ });
36
+ }
37
+ it("renders an empty class declaration", async () => {
38
+ const {
39
+ TestModel
40
+ } = await runner.compile(t.code`
41
+ model ${t.model("TestModel")} {}
42
+ `);
43
+ const res = render(_$createComponent(Wrapper, {
44
+ get children() {
45
+ return _$createComponent(ClassDeclaration, {
46
+ type: TestModel
47
+ });
48
+ }
49
+ }));
50
+ assertFileContents(res, d`
51
+ namespace TestNamespace
52
+ {
53
+ class TestModel
54
+ {
55
+
56
+ }
57
+ }
58
+ `);
59
+ });
60
+ it("renders a class declaration with properties", async () => {
61
+ const {
62
+ TestModel
63
+ } = await runner.compile(t.code`
64
+ model ${t.model("TestModel")} {
65
+ @test Prop1: string;
66
+ @test Prop2: int32;
67
+ }
68
+ `);
69
+ const res = render(_$createComponent(Wrapper, {
70
+ get children() {
71
+ return _$createComponent(ClassDeclaration, {
72
+ type: TestModel
73
+ });
74
+ }
75
+ }));
76
+ assertFileContents(res, d`
77
+ namespace TestNamespace
78
+ {
79
+ class TestModel
80
+ {
81
+ public required string Prop1 { get; set; }
82
+ public required int Prop2 { get; set; }
83
+ }
84
+ }
85
+ `);
86
+ });
87
+ it("can override class name", async () => {
88
+ const {
89
+ TestModel
90
+ } = await runner.compile(t.code`
91
+ model ${t.model("TestModel")} {}
92
+ `);
93
+ const res = render(_$createComponent(Wrapper, {
94
+ get children() {
95
+ return _$createComponent(ClassDeclaration, {
96
+ type: TestModel,
97
+ name: "CustomClassName"
98
+ });
99
+ }
100
+ }));
101
+ assertFileContents(res, d`
102
+ namespace TestNamespace
103
+ {
104
+ class CustomClassName
105
+ {
106
+
107
+ }
108
+ }
109
+ `);
110
+ });
111
+ it("renders a class with access modifiers", async () => {
112
+ const {
113
+ TestModel
114
+ } = await runner.compile(t.code`
115
+ model ${t.model("TestModel")} {
116
+ }
117
+ `);
118
+ const res = render(_$createComponent(Wrapper, {
119
+ get children() {
120
+ return _$createComponent(ClassDeclaration, {
121
+ type: TestModel,
122
+ "protected": true
123
+ });
124
+ }
125
+ }));
126
+ assertFileContents(res, d`
127
+ namespace TestNamespace
128
+ {
129
+ protected class TestModel
130
+ {
131
+
132
+ }
133
+ }
134
+ `);
135
+ });
136
+ describe("from an interface", () => {
137
+ it("renders an empty class", async () => {
138
+ const {
139
+ TestInterface
140
+ } = await runner.compile(t.code`
141
+ interface ${t.interface("TestInterface")} {
142
+ }
143
+ `);
144
+ const res = render(_$createComponent(Wrapper, {
145
+ get children() {
146
+ return _$createComponent(ClassDeclaration, {
147
+ type: TestInterface
148
+ });
149
+ }
150
+ }));
151
+ assertFileContents(res, d`
152
+ namespace TestNamespace
153
+ {
154
+ class TestInterface
155
+ {
156
+
157
+ }
158
+ }
159
+ `);
160
+ });
161
+ it("renders a class with operations", async () => {
162
+ const {
163
+ TestInterface
164
+ } = await runner.compile(t.code`
165
+ interface ${t.interface("TestInterface")} {
166
+ op getName(id: string): string;
167
+ }
168
+ `);
169
+ const res = render(_$createComponent(Wrapper, {
170
+ get children() {
171
+ return _$createComponent(ClassDeclaration, {
172
+ type: TestInterface
173
+ });
174
+ }
175
+ }));
176
+ assertFileContents(res, d`
177
+ namespace TestNamespace
178
+ {
179
+ class TestInterface
180
+ {
181
+ public abstract string GetName(string id);
182
+ }
183
+ }
184
+ `);
185
+ });
186
+ });
187
+ it("renders a class with model members", async () => {
188
+ const {
189
+ TestModel,
190
+ TestReference
191
+ } = await runner.compile(t.code`
192
+ model ${t.model("TestReference")} { }
193
+ model ${t.model("TestModel")} {
194
+ prop1: TestReference;
195
+ }
196
+ `);
197
+ const res = render(_$createComponent(Wrapper, {
198
+ get children() {
199
+ return [_$createComponent(ClassDeclaration, {
200
+ type: TestReference
201
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
202
+ type: TestModel
203
+ })];
204
+ }
205
+ }));
206
+ assertFileContents(res, d`
207
+ namespace TestNamespace
208
+ {
209
+ class TestReference
210
+ {
211
+
212
+ }
213
+ class TestModel
214
+ {
215
+ public required TestReference Prop1 { get; set; }
216
+ }
217
+ }
218
+ `);
219
+ });
220
+ it("renders a class with enum members", async () => {
221
+ const {
222
+ TestModel,
223
+ TestEnum
224
+ } = await runner.compile(t.code`
225
+ @test enum ${t.enum("TestEnum")} {
226
+ Value1;
227
+ Value2;
228
+ }
229
+ model ${t.model("TestModel")} {
230
+ @test prop1: TestEnum;
231
+ }
232
+ `);
233
+ const res = render(_$createComponent(Wrapper, {
234
+ get children() {
235
+ return [_$createComponent(EnumDeclaration, {
236
+ type: TestEnum
237
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
238
+ type: TestModel
239
+ })];
240
+ }
241
+ }));
242
+ assertFileContents(res, d`
243
+ namespace TestNamespace
244
+ {
245
+ enum TestEnum
246
+ {
247
+ Value1,
248
+ Value2
249
+ }
250
+ class TestModel
251
+ {
252
+ public required TestEnum Prop1 { get; set; }
253
+ }
254
+ }
255
+ `);
256
+ });
257
+ it("maps prop: string | null to nullable property", async () => {
258
+ const {
259
+ TestModel
260
+ } = await runner.compile(t.code`
261
+ model ${t.model("TestModel")} {
262
+ prop1: string | null;
263
+ }
264
+ `);
265
+ const res = render(_$createComponent(Wrapper, {
266
+ get children() {
267
+ return _$createComponent(ClassDeclaration, {
268
+ type: TestModel
269
+ });
270
+ }
271
+ }));
272
+ assertFileContents(res, d`
273
+ namespace TestNamespace
274
+ {
275
+ class TestModel
276
+ {
277
+ public required string? Prop1 { get; set; }
278
+ }
279
+ }
280
+ `);
281
+ });
282
+ it("renders a class with string enums", async () => {
283
+ const {
284
+ TestModel,
285
+ TestEnum
286
+ } = await runner.compile(t.code`
287
+ @test enum ${t.enum("TestEnum")} {
288
+ Value1;
289
+ Value2;
290
+ }
291
+ model ${t.model("TestModel")} {
292
+ @test prop1: TestEnum;
293
+ }
294
+ `);
295
+ const res = render(_$createComponent(Wrapper, {
296
+ get children() {
297
+ return [_$createComponent(EnumDeclaration, {
298
+ type: TestEnum
299
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
300
+ type: TestModel
301
+ })];
302
+ }
303
+ }));
304
+ assertFileContents(res, d`
305
+ namespace TestNamespace
306
+ {
307
+ enum TestEnum
308
+ {
309
+ Value1,
310
+ Value2
311
+ }
312
+ class TestModel
313
+ {
314
+ public required TestEnum Prop1 { get; set; }
315
+ }
316
+ }
317
+ `);
318
+ });
319
+ describe("with doc comments", () => {
320
+ it("renders a model with docs", async () => {
321
+ const {
322
+ TestModel
323
+ } = await runner.compile(t.code`
324
+ @doc("This is a test model")
325
+ model ${t.model("TestModel")} {
326
+ @doc("This is a test property")
327
+ prop1: string;
328
+ }
329
+
330
+ `);
331
+ const res = render(_$createComponent(Wrapper, {
332
+ get children() {
333
+ return _$createComponent(ClassDeclaration, {
334
+ type: TestModel
335
+ });
336
+ }
337
+ }));
338
+ assertFileContents(res, d`
339
+ namespace TestNamespace
340
+ {
341
+ /// <summary>
342
+ /// This is a test model
343
+ /// </summary>
344
+ class TestModel
345
+ {
346
+ /// <summary>
347
+ /// This is a test property
348
+ /// </summary>
349
+ public required string Prop1 { get; set; }
350
+ }
351
+ }
352
+ `);
353
+ });
354
+ it("renders an interface with docs", async () => {
355
+ const {
356
+ TestInterface
357
+ } = await runner.compile(t.code`
358
+ @doc("This is a test interface")
359
+ @test interface ${t.interface("TestInterface")} {
360
+ @doc("This is a test operation")
361
+ @returnsDoc("The name of the item")
362
+ op getName(id: string): string;
363
+ }
364
+ `);
365
+ const res = render(_$createComponent(Wrapper, {
366
+ get children() {
367
+ return _$createComponent(ClassDeclaration, {
368
+ type: TestInterface
369
+ });
370
+ }
371
+ }));
372
+ assertFileContents(res, d`
373
+ namespace TestNamespace
374
+ {
375
+ /// <summary>
376
+ /// This is a test interface
377
+ /// </summary>
378
+ class TestInterface
379
+ {
380
+ /// <summary>
381
+ /// This is a test operation
382
+ /// </summary>
383
+ ///
384
+ /// <returns>
385
+ /// The name of the item
386
+ /// </returns>
387
+ public abstract string GetName(string id);
388
+ }
389
+ }
390
+ `);
391
+ });
392
+ });
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as cs from "@alloy-js/csharp";
3
3
  import { Enum, Union } from "@typespec/compiler";
4
- export interface EnumDeclarationProps extends Omit<cs.EnumProps, "name"> {
4
+ export interface EnumDeclarationProps extends Omit<cs.EnumDeclarationProps, "name"> {
5
5
  name?: string;
6
6
  type: Union | Enum;
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKjD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,EAAE,CAAC,QAAQ,CAmCxE"}
1
+ {"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAMjD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,EAAE,CAAC,QAAQ,CA0CxE"}
@@ -1,8 +1,9 @@
1
- import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, mergeProps as _$mergeProps, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
2
  import * as ay from "@alloy-js/core";
3
3
  import * as cs from "@alloy-js/csharp";
4
4
  import { useTsp } from "../../core/index.js";
5
5
  import { reportDiagnostic } from "../../lib.js";
6
+ import { getDocComments } from "./utils/doc-comments.js";
6
7
  import { declarationRefkeys, efRefkey } from "./utils/refkey.js";
7
8
  export function EnumDeclaration(props) {
8
9
  const {
@@ -26,27 +27,29 @@ export function EnumDeclaration(props) {
26
27
  const refkeys = declarationRefkeys(props.refkey, props.type)[0]; // TODO: support multiple refkeys for declarations in alloy
27
28
  const name = props.name ?? cs.useCSharpNamePolicy().getName(props.type.name, "enum");
28
29
  const members = Array.from(type.members.entries());
29
- return _$createComponent(cs.Enum, {
30
+ return [_$createComponent(cs.EnumDeclaration, _$mergeProps({
30
31
  name: name,
31
- refkey: refkeys,
32
- get accessModifier() {
33
- return props.accessModifier ?? "public";
34
- },
32
+ refkey: refkeys
33
+ }, props, {
35
34
  get children() {
36
35
  return _$createComponent(ay.For, {
37
36
  each: members,
38
37
  joiner: ",\n",
39
38
  children: ([key, value]) => {
40
- return _$createComponent(cs.EnumMember, {
39
+ return [_$createComponent(cs.DocWhen, {
40
+ get doc() {
41
+ return getDocComments($, value);
42
+ }
43
+ }), _$createComponent(cs.EnumMember, {
41
44
  get name() {
42
45
  return cs.useCSharpNamePolicy().getName(key, "enum-member");
43
46
  },
44
47
  get refkey() {
45
48
  return _$memo(() => !!$.union.is(props.type))() ? efRefkey(props.type.variants.get(key)) : efRefkey(value);
46
49
  }
47
- });
50
+ })];
48
51
  }
49
52
  });
50
53
  }
51
- });
54
+ }))];
52
55
  }
@@ -1,4 +1,5 @@
1
- export * from "./class-declaration.jsx";
1
+ export * from "./class/declaration.js";
2
2
  export * from "./enum-declaration.jsx";
3
+ export * from "./property/property.jsx";
3
4
  export * from "./type-expression.jsx";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
@@ -1,3 +1,4 @@
1
- export * from "./class-declaration.js";
1
+ export * from "./class/declaration.js";
2
2
  export * from "./enum-declaration.js";
3
+ export * from "./property/property.js";
3
4
  export * from "./type-expression.js";
@@ -0,0 +1,15 @@
1
+ import { Children } from "@alloy-js/core";
2
+ import { ModelProperty } from "@typespec/compiler";
3
+ export interface PropertyProps {
4
+ type: ModelProperty;
5
+ /** If set the property will add the json serialization attributes(using System.Text.Json). */
6
+ jsonAttributes?: boolean;
7
+ }
8
+ /**
9
+ * Create a C# property declaration from a TypeSpec property type.
10
+ */
11
+ export declare function Property(props: PropertyProps): Children;
12
+ export interface JsonNameAttributeProps {
13
+ type: ModelProperty;
14
+ }
15
+ //# sourceMappingURL=property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAC;AAK7E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,aAAa,CAAC;IACpB,8FAA8F;IAC9F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,QAAQ,CAiBvD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,aAAa,CAAC;CACrB"}