@typespec/emitter-framework 0.11.0-dev.0 → 0.11.0-dev.10

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 (212) hide show
  1. package/dist/src/core/components/index.d.ts +2 -0
  2. package/dist/src/core/components/index.d.ts.map +1 -1
  3. package/dist/src/core/components/index.js +4 -1
  4. package/dist/src/core/components/index.js.map +1 -0
  5. package/dist/src/core/components/output.js +2 -1
  6. package/dist/src/core/components/output.js.map +1 -0
  7. package/dist/src/core/components/overrides/component-overrides.d.ts +64 -0
  8. package/dist/src/core/components/overrides/component-overrides.d.ts.map +1 -0
  9. package/dist/src/core/components/overrides/component-overrides.js +41 -0
  10. package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
  11. package/dist/src/core/components/overrides/config.d.ts +28 -0
  12. package/dist/src/core/components/overrides/config.d.ts.map +1 -0
  13. package/dist/src/core/components/overrides/config.js +55 -0
  14. package/dist/src/core/components/overrides/config.js.map +1 -0
  15. package/dist/src/core/components/overrides/context.d.ts +11 -0
  16. package/dist/src/core/components/overrides/context.d.ts.map +1 -0
  17. package/dist/src/core/components/overrides/context.js +9 -0
  18. package/dist/src/core/components/overrides/context.js.map +1 -0
  19. package/dist/src/core/context/index.js +2 -1
  20. package/dist/src/core/context/index.js.map +1 -0
  21. package/dist/src/core/context/name-policy-context.js +2 -1
  22. package/dist/src/core/context/name-policy-context.js.map +1 -0
  23. package/dist/src/core/context/tsp-context.js +2 -1
  24. package/dist/src/core/context/tsp-context.js.map +1 -0
  25. package/dist/src/core/index.js +2 -1
  26. package/dist/src/core/index.js.map +1 -0
  27. package/dist/src/core/transport-name-policy.js +2 -1
  28. package/dist/src/core/transport-name-policy.js.map +1 -0
  29. package/dist/src/core/write-output.d.ts.map +1 -1
  30. package/dist/src/core/write-output.js +4 -3
  31. package/dist/src/core/write-output.js.map +1 -0
  32. package/dist/src/csharp/components/class/declaration.d.ts +1 -1
  33. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  34. package/dist/src/csharp/components/class/declaration.js +14 -5
  35. package/dist/src/csharp/components/class/declaration.js.map +1 -0
  36. package/dist/src/csharp/components/class/declaration.test.js +125 -92
  37. package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
  38. package/dist/src/csharp/components/enum/declaration.js +2 -1
  39. package/dist/src/csharp/components/enum/declaration.js.map +1 -0
  40. package/dist/src/csharp/components/enum/declaration.test.js +52 -88
  41. package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
  42. package/dist/src/csharp/components/index.js +2 -1
  43. package/dist/src/csharp/components/index.js.map +1 -0
  44. package/dist/src/csharp/components/property/property.d.ts.map +1 -1
  45. package/dist/src/csharp/components/property/property.js +40 -14
  46. package/dist/src/csharp/components/property/property.js.map +1 -0
  47. package/dist/src/csharp/components/property/property.test.js +129 -29
  48. package/dist/src/csharp/components/property/property.test.js.map +1 -0
  49. package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
  50. package/dist/src/csharp/components/type-expression.js +34 -6
  51. package/dist/src/csharp/components/type-expression.js.map +1 -0
  52. package/dist/src/csharp/components/type-expression.test.js +87 -54
  53. package/dist/src/csharp/components/type-expression.test.js.map +1 -0
  54. package/dist/src/csharp/components/utils/doc-comments.js +2 -1
  55. package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
  56. package/dist/src/csharp/components/utils/nullable-util.d.ts +4 -0
  57. package/dist/src/csharp/components/utils/nullable-util.d.ts.map +1 -0
  58. package/dist/src/csharp/components/utils/nullable-util.js +27 -0
  59. package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
  60. package/dist/src/csharp/components/utils/refkey.js +2 -1
  61. package/dist/src/csharp/components/utils/refkey.js.map +1 -0
  62. package/dist/src/csharp/index.js +2 -1
  63. package/dist/src/csharp/index.js.map +1 -0
  64. package/dist/src/lib.js +2 -1
  65. package/dist/src/lib.js.map +1 -0
  66. package/dist/src/testing/index.js +2 -1
  67. package/dist/src/testing/index.js.map +1 -0
  68. package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
  69. package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
  70. package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
  71. package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
  72. package/dist/src/testing/scenario-test/harness.js +8 -2
  73. package/dist/src/testing/scenario-test/harness.js.map +1 -0
  74. package/dist/src/testing/scenario-test/index.js +2 -1
  75. package/dist/src/testing/scenario-test/index.js.map +1 -0
  76. package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
  77. package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
  78. package/dist/src/typescript/components/array-expression.js +2 -1
  79. package/dist/src/typescript/components/array-expression.js.map +1 -0
  80. package/dist/src/typescript/components/arrow-function.js +2 -1
  81. package/dist/src/typescript/components/arrow-function.js.map +1 -0
  82. package/dist/src/typescript/components/class-method.js +2 -1
  83. package/dist/src/typescript/components/class-method.js.map +1 -0
  84. package/dist/src/typescript/components/enum-declaration.js +2 -1
  85. package/dist/src/typescript/components/enum-declaration.js.map +1 -0
  86. package/dist/src/typescript/components/function-declaration.js +2 -1
  87. package/dist/src/typescript/components/function-declaration.js.map +1 -0
  88. package/dist/src/typescript/components/function-expression.js +2 -1
  89. package/dist/src/typescript/components/function-expression.js.map +1 -0
  90. package/dist/src/typescript/components/function-type.js +2 -1
  91. package/dist/src/typescript/components/function-type.js.map +1 -0
  92. package/dist/src/typescript/components/index.js +2 -1
  93. package/dist/src/typescript/components/index.js.map +1 -0
  94. package/dist/src/typescript/components/interface-declaration.js +2 -1
  95. package/dist/src/typescript/components/interface-declaration.js.map +1 -0
  96. package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
  97. package/dist/src/typescript/components/interface-member.js +13 -20
  98. package/dist/src/typescript/components/interface-member.js.map +1 -0
  99. package/dist/src/typescript/components/interface-method.js +2 -1
  100. package/dist/src/typescript/components/interface-method.js.map +1 -0
  101. package/dist/src/typescript/components/record-expression.js +2 -1
  102. package/dist/src/typescript/components/record-expression.js.map +1 -0
  103. package/dist/src/typescript/components/static-serializers.js +2 -1
  104. package/dist/src/typescript/components/static-serializers.js.map +1 -0
  105. package/dist/src/typescript/components/type-alias-declaration.js +2 -1
  106. package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
  107. package/dist/src/typescript/components/type-declaration.js +2 -1
  108. package/dist/src/typescript/components/type-declaration.js.map +1 -0
  109. package/dist/src/typescript/components/type-expression.d.ts +0 -1
  110. package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
  111. package/dist/src/typescript/components/type-expression.js +13 -12
  112. package/dist/src/typescript/components/type-expression.js.map +1 -0
  113. package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
  114. package/dist/src/typescript/components/type-transform.js +5 -4
  115. package/dist/src/typescript/components/type-transform.js.map +1 -0
  116. package/dist/src/typescript/components/union/declaration.js +2 -1
  117. package/dist/src/typescript/components/union/declaration.js.map +1 -0
  118. package/dist/src/typescript/components/union/declaration.test.js +2 -1
  119. package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
  120. package/dist/src/typescript/components/union/expression.js +2 -1
  121. package/dist/src/typescript/components/union/expression.js.map +1 -0
  122. package/dist/src/typescript/components/union/expression.test.js +2 -1
  123. package/dist/src/typescript/components/union/expression.test.js.map +1 -0
  124. package/dist/src/typescript/components/value-expression.js +2 -1
  125. package/dist/src/typescript/components/value-expression.js.map +1 -0
  126. package/dist/src/typescript/index.js +2 -1
  127. package/dist/src/typescript/index.js.map +1 -0
  128. package/dist/src/typescript/lib.js +2 -1
  129. package/dist/src/typescript/lib.js.map +1 -0
  130. package/dist/src/typescript/utils/index.js +2 -1
  131. package/dist/src/typescript/utils/index.js.map +1 -0
  132. package/dist/src/typescript/utils/operation.js +2 -1
  133. package/dist/src/typescript/utils/operation.js.map +1 -0
  134. package/dist/src/typescript/utils/refkey.js +2 -1
  135. package/dist/src/typescript/utils/refkey.js.map +1 -0
  136. package/dist/test/test-host.js +2 -1
  137. package/dist/test/test-host.js.map +1 -0
  138. package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
  139. package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
  140. package/dist/test/testing/snippet-extractor-java.test.js +2 -1
  141. package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
  142. package/dist/test/testing/snippet-extractor-python.test.js +2 -1
  143. package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
  144. package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
  145. package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
  146. package/dist/test/typescript/components/arrow-function.test.js +18 -22
  147. package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
  148. package/dist/test/typescript/components/component-override.test.d.ts +2 -0
  149. package/dist/test/typescript/components/component-override.test.d.ts.map +1 -0
  150. package/dist/test/typescript/components/component-override.test.js +78 -0
  151. package/dist/test/typescript/components/component-override.test.js.map +1 -0
  152. package/dist/test/typescript/components/enum-declaration.test.js +2 -1
  153. package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
  154. package/dist/test/typescript/components/function-declaration.test.js +3 -2
  155. package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
  156. package/dist/test/typescript/components/function-expression.test.js +18 -22
  157. package/dist/test/typescript/components/function-expression.test.js.map +1 -0
  158. package/dist/test/typescript/components/function-type.test.js +18 -22
  159. package/dist/test/typescript/components/function-type.test.js.map +1 -0
  160. package/dist/test/typescript/components/interface-declaration.test.js +3 -2
  161. package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
  162. package/dist/test/typescript/components/interface-method.test.js +37 -45
  163. package/dist/test/typescript/components/interface-method.test.js.map +1 -0
  164. package/dist/test/typescript/components/member-expression.test.js +2 -1
  165. package/dist/test/typescript/components/member-expression.test.js.map +1 -0
  166. package/dist/test/typescript/components/type-alias-declaration.test.js +8 -5
  167. package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
  168. package/dist/test/typescript/components/type-transform.test.js +29 -27
  169. package/dist/test/typescript/components/type-transform.test.js.map +1 -0
  170. package/dist/test/typescript/components/value-expression.test.js +3 -2
  171. package/dist/test/typescript/components/value-expression.test.js.map +1 -0
  172. package/dist/test/typescript/utils.js +2 -1
  173. package/dist/test/typescript/utils.js.map +1 -0
  174. package/dist/test/utils.d.ts +1 -0
  175. package/dist/test/utils.d.ts.map +1 -1
  176. package/dist/test/utils.js +13 -3
  177. package/dist/test/utils.js.map +1 -0
  178. package/dist/test/vitest.setup.js +2 -1
  179. package/dist/test/vitest.setup.js.map +1 -0
  180. package/package.json +9 -13
  181. package/src/core/components/index.tsx +2 -0
  182. package/src/core/components/overrides/component-overrides.tsx +134 -0
  183. package/src/core/components/overrides/config.ts +85 -0
  184. package/src/core/components/overrides/context.ts +14 -0
  185. package/src/core/write-output.ts +2 -2
  186. package/src/csharp/components/class/declaration.test.tsx +114 -88
  187. package/src/csharp/components/class/declaration.tsx +13 -3
  188. package/src/csharp/components/enum/declaration.test.tsx +47 -78
  189. package/src/csharp/components/property/property.test.tsx +108 -25
  190. package/src/csharp/components/property/property.tsx +43 -11
  191. package/src/csharp/components/type-expression.test.tsx +84 -69
  192. package/src/csharp/components/type-expression.tsx +31 -5
  193. package/src/csharp/components/utils/nullable-util.ts +25 -0
  194. package/src/testing/scenario-test/harness.ts +6 -1
  195. package/src/typescript/components/interface-member.tsx +8 -14
  196. package/src/typescript/components/type-expression.tsx +7 -8
  197. package/src/typescript/components/type-transform.tsx +3 -7
  198. package/test/typescript/components/arrow-function.test.tsx +23 -42
  199. package/test/typescript/components/component-override.test.tsx +71 -0
  200. package/test/typescript/components/function-declaration.test.tsx +2 -1
  201. package/test/typescript/components/function-expression.test.tsx +23 -42
  202. package/test/typescript/components/function-type.test.tsx +22 -40
  203. package/test/typescript/components/interface-declaration.test.tsx +1 -1
  204. package/test/typescript/components/interface-method.test.tsx +50 -92
  205. package/test/typescript/components/type-alias-declaration.test.tsx +8 -6
  206. package/test/typescript/components/type-transform.test.tsx +37 -37
  207. package/test/typescript/components/value-expression.test.tsx +1 -1
  208. package/test/utils.ts +10 -3
  209. package/dist/test/typescript/test-host.d.ts +0 -16
  210. package/dist/test/typescript/test-host.d.ts.map +0 -1
  211. package/dist/test/typescript/test-host.js +0 -40
  212. package/test/typescript/test-host.ts +0 -49
@@ -1,6 +1,11 @@
1
+ import {
2
+ Experimental_ComponentOverrides,
3
+ Experimental_ComponentOverridesConfig,
4
+ } from "#core/index.js";
1
5
  import { Tester } from "#test/test-host.js";
2
- import { type Children } from "@alloy-js/core";
3
- import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
6
+ import { List, type Children } from "@alloy-js/core";
7
+ import { d } from "@alloy-js/core/testing";
8
+ import { createCSharpNamePolicy, SourceFile } from "@alloy-js/csharp";
4
9
  import { t, type TesterInstance } from "@typespec/compiler/testing";
5
10
  import { beforeEach, describe, expect, it } from "vitest";
6
11
  import { Output } from "../../../core/index.js";
@@ -16,9 +21,7 @@ function Wrapper(props: { children: Children }) {
16
21
  const policy = createCSharpNamePolicy();
17
22
  return (
18
23
  <Output program={runner.program} namePolicy={policy}>
19
- <Namespace name="TestNamespace">
20
- <SourceFile path="test.cs">{props.children}</SourceFile>
21
- </Namespace>
24
+ <SourceFile path="test.cs">{props.children}</SourceFile>
22
25
  </Output>
23
26
  );
24
27
  }
@@ -33,12 +36,9 @@ it("renders an empty class declaration", async () => {
33
36
  <ClassDeclaration type={TestModel} />
34
37
  </Wrapper>,
35
38
  ).toRenderTo(`
36
- namespace TestNamespace
39
+ class TestModel
37
40
  {
38
- class TestModel
39
- {
40
41
 
41
- }
42
42
  }
43
43
  `);
44
44
  });
@@ -56,17 +56,73 @@ it("renders a class declaration with properties", async () => {
56
56
  <ClassDeclaration type={TestModel} />
57
57
  </Wrapper>,
58
58
  ).toRenderTo(`
59
- namespace TestNamespace
59
+ class TestModel
60
60
  {
61
- class TestModel
62
- {
63
- public required string Prop1 { get; set; }
64
- public required int Prop2 { get; set; }
65
- }
61
+ public required string Prop1 { get; set; }
62
+
63
+ public required int Prop2 { get; set; }
64
+ }
65
+ `);
66
+ });
67
+
68
+ it("renders a class declaration with properties using component override", async () => {
69
+ const { TestModel, Foo, Bar } = await runner.compile(t.code`
70
+ model ${t.model("Foo")} {}
71
+ model ${t.model("Bar")} {}
72
+ model ${t.model("TestModel")} {
73
+ Prop1: string;
74
+ Prop2: int32;
75
+ Prop3?: Foo;
76
+ }
77
+ `);
78
+
79
+ expect(
80
+ <Wrapper>
81
+ <TestClientOverrides>
82
+ <List hardline>
83
+ <ClassDeclaration type={Foo} />
84
+ <ClassDeclaration type={Bar} />
85
+ <ClassDeclaration type={TestModel} />
86
+ </List>
87
+ </TestClientOverrides>
88
+ </Wrapper>,
89
+ ).toRenderTo(d`
90
+ class Foo
91
+ {
92
+
93
+ }
94
+ class Bar
95
+ {
96
+
97
+ }
98
+ class TestModel
99
+ {
100
+ public required string Prop1 { get; set; }
101
+
102
+ public required int Prop2 { get; set; }
103
+
104
+ public Bar? Prop3 { get; set; }
66
105
  }
67
106
  `);
68
107
  });
69
108
 
109
+ function TestClientOverrides(props: { children?: Children }) {
110
+ const overrides = Experimental_ComponentOverridesConfig().forTypeKind("Model", {
111
+ reference: (props) => {
112
+ if (props.type.name === "Foo") {
113
+ return "Bar";
114
+ } else {
115
+ return props.default;
116
+ }
117
+ },
118
+ });
119
+ return (
120
+ <Experimental_ComponentOverrides overrides={overrides}>
121
+ {props.children}
122
+ </Experimental_ComponentOverrides>
123
+ );
124
+ }
125
+
70
126
  it("can override class name", async () => {
71
127
  const { TestModel } = await runner.compile(t.code`
72
128
  model ${t.model("TestModel")} {}
@@ -77,12 +133,9 @@ it("can override class name", async () => {
77
133
  <ClassDeclaration type={TestModel} name="CustomClassName" />
78
134
  </Wrapper>,
79
135
  ).toRenderTo(`
80
- namespace TestNamespace
136
+ class CustomClassName
81
137
  {
82
- class CustomClassName
83
- {
84
138
 
85
- }
86
139
  }
87
140
  `);
88
141
  });
@@ -98,12 +151,9 @@ it("renders a class with access modifiers", async () => {
98
151
  <ClassDeclaration type={TestModel} protected />
99
152
  </Wrapper>,
100
153
  ).toRenderTo(`
101
- namespace TestNamespace
154
+ protected class TestModel
102
155
  {
103
- protected class TestModel
104
- {
105
156
 
106
- }
107
157
  }
108
158
  `);
109
159
  });
@@ -120,12 +170,9 @@ describe("from an interface", () => {
120
170
  <ClassDeclaration type={TestInterface} />
121
171
  </Wrapper>,
122
172
  ).toRenderTo(`
123
- namespace TestNamespace
173
+ class TestInterface
124
174
  {
125
- class TestInterface
126
- {
127
175
 
128
- }
129
176
  }
130
177
  `);
131
178
  });
@@ -142,12 +189,9 @@ describe("from an interface", () => {
142
189
  <ClassDeclaration type={TestInterface} />
143
190
  </Wrapper>,
144
191
  ).toRenderTo(`
145
- namespace TestNamespace
192
+ class TestInterface
146
193
  {
147
- class TestInterface
148
- {
149
- public abstract string GetName(string id);
150
- }
194
+ public abstract string GetName(string id);
151
195
  }
152
196
  `);
153
197
  });
@@ -168,16 +212,13 @@ it("renders a class with model members", async () => {
168
212
  <ClassDeclaration type={TestModel} />
169
213
  </Wrapper>,
170
214
  ).toRenderTo(`
171
- namespace TestNamespace
215
+ class TestReference
216
+ {
217
+
218
+ }
219
+ class TestModel
172
220
  {
173
- class TestReference
174
- {
175
-
176
- }
177
- class TestModel
178
- {
179
- public required TestReference Prop1 { get; set; }
180
- }
221
+ public required TestReference Prop1 { get; set; }
181
222
  }
182
223
  `);
183
224
  });
@@ -200,17 +241,14 @@ it("renders a class with enum members", async () => {
200
241
  <ClassDeclaration type={TestModel} />
201
242
  </Wrapper>,
202
243
  ).toRenderTo(`
203
- namespace TestNamespace
244
+ enum TestEnum
204
245
  {
205
- enum TestEnum
206
- {
207
- Value1,
208
- Value2
209
- }
210
- class TestModel
211
- {
212
- public required TestEnum Prop1 { get; set; }
213
- }
246
+ Value1,
247
+ Value2
248
+ }
249
+ class TestModel
250
+ {
251
+ public required TestEnum Prop1 { get; set; }
214
252
  }
215
253
  `);
216
254
  });
@@ -227,12 +265,9 @@ it("maps prop: string | null to nullable property", async () => {
227
265
  <ClassDeclaration type={TestModel} />
228
266
  </Wrapper>,
229
267
  ).toRenderTo(`
230
- namespace TestNamespace
268
+ class TestModel
231
269
  {
232
- class TestModel
233
- {
234
- public required string? Prop1 { get; set; }
235
- }
270
+ public required string? Prop1 { get; set; }
236
271
  }
237
272
  `);
238
273
  });
@@ -255,17 +290,14 @@ it("renders a class with string enums", async () => {
255
290
  <ClassDeclaration type={TestModel} />
256
291
  </Wrapper>,
257
292
  ).toRenderTo(`
258
- namespace TestNamespace
293
+ enum TestEnum
294
+ {
295
+ Value1,
296
+ Value2
297
+ }
298
+ class TestModel
259
299
  {
260
- enum TestEnum
261
- {
262
- Value1,
263
- Value2
264
- }
265
- class TestModel
266
- {
267
- public required TestEnum Prop1 { get; set; }
268
- }
300
+ public required TestEnum Prop1 { get; set; }
269
301
  }
270
302
  `);
271
303
  });
@@ -286,18 +318,15 @@ describe("with doc comments", () => {
286
318
  <ClassDeclaration type={TestModel} />
287
319
  </Wrapper>,
288
320
  ).toRenderTo(`
289
- namespace TestNamespace
321
+ /// <summary>
322
+ /// This is a test model
323
+ /// </summary>
324
+ class TestModel
290
325
  {
291
326
  /// <summary>
292
- /// This is a test model
327
+ /// This is a test property
293
328
  /// </summary>
294
- class TestModel
295
- {
296
- /// <summary>
297
- /// This is a test property
298
- /// </summary>
299
- public required string Prop1 { get; set; }
300
- }
329
+ public required string Prop1 { get; set; }
301
330
  }
302
331
  `);
303
332
  });
@@ -317,22 +346,19 @@ describe("with doc comments", () => {
317
346
  <ClassDeclaration type={TestInterface} />
318
347
  </Wrapper>,
319
348
  ).toRenderTo(`
320
- namespace TestNamespace
349
+ /// <summary>
350
+ /// This is a test interface
351
+ /// </summary>
352
+ class TestInterface
321
353
  {
322
354
  /// <summary>
323
- /// This is a test interface
355
+ /// This is a test operation
324
356
  /// </summary>
325
- class TestInterface
326
- {
327
- /// <summary>
328
- /// This is a test operation
329
- /// </summary>
330
- ///
331
- /// <returns>
332
- /// The name of the item
333
- /// </returns>
334
- public abstract string GetName(string id);
335
- }
357
+ ///
358
+ /// <returns>
359
+ /// The name of the item
360
+ /// </returns>
361
+ public abstract string GetName(string id);
336
362
  }
337
363
  `);
338
364
  });
@@ -1,7 +1,7 @@
1
- import { type Children, For } from "@alloy-js/core";
1
+ import { For, type Children } from "@alloy-js/core";
2
2
  import * as cs from "@alloy-js/csharp";
3
3
  import { Method } from "@alloy-js/csharp";
4
- import type { Interface, Model } from "@typespec/compiler";
4
+ import { isVoidType, type Interface, type Model } from "@typespec/compiler";
5
5
  import { useTsp } from "../../../core/index.js";
6
6
  import { Property } from "../property/property.jsx";
7
7
  import { TypeExpression } from "../type-expression.jsx";
@@ -41,6 +41,12 @@ export function ClassDeclaration(props: ClassDeclarationProps): Children {
41
41
  {...props}
42
42
  name={className}
43
43
  refkey={refkeys}
44
+ baseType={
45
+ props.baseType ??
46
+ (props.type.kind === "Model" && props.type.baseModel ? (
47
+ <TypeExpression type={props.type.baseModel} />
48
+ ) : undefined)
49
+ }
44
50
  doc={getDocComments($, props.type)}
45
51
  >
46
52
  {props.type.kind === "Model" && (
@@ -53,8 +59,12 @@ export function ClassDeclaration(props: ClassDeclarationProps): Children {
53
59
  }
54
60
 
55
61
  function ClassProperties(props: ClassPropertiesProps): Children {
62
+ // Ignore 'void' type properties which is not valid in csharp
63
+ const properties = Array.from(props.type.properties.entries()).filter(
64
+ ([_, p]) => !isVoidType(p.type),
65
+ );
56
66
  return (
57
- <For each={props.type.properties.entries()} hardline>
67
+ <For each={properties} doubleHardline>
58
68
  {([name, property]) => <Property type={property} jsonAttributes={props.jsonAttributes} />}
59
69
  </For>
60
70
  );
@@ -1,6 +1,6 @@
1
1
  import { Tester } from "#test/test-host.js";
2
2
  import { type Children } from "@alloy-js/core";
3
- import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
3
+ import { createCSharpNamePolicy, SourceFile } from "@alloy-js/csharp";
4
4
  import { t, type TesterInstance } from "@typespec/compiler/testing";
5
5
  import { beforeEach, expect, it } from "vitest";
6
6
  import { Output } from "../../../core/index.js";
@@ -16,9 +16,7 @@ function Wrapper(props: { children: Children }) {
16
16
  const policy = createCSharpNamePolicy();
17
17
  return (
18
18
  <Output program={runner.program} namePolicy={policy}>
19
- <Namespace name="TestNamespace">
20
- <SourceFile path="test.cs">{props.children}</SourceFile>
21
- </Namespace>
19
+ <SourceFile path="test.cs">{props.children}</SourceFile>
22
20
  </Output>
23
21
  );
24
22
  }
@@ -37,14 +35,11 @@ it("renders a basic enum declaration", async () => {
37
35
  <EnumDeclaration type={TestEnum} />
38
36
  </Wrapper>,
39
37
  ).toRenderTo(`
40
- namespace TestNamespace
38
+ enum TestEnum
41
39
  {
42
- enum TestEnum
43
- {
44
- Value1,
45
- Value2,
46
- Value3
47
- }
40
+ Value1,
41
+ Value2,
42
+ Value3
48
43
  }
49
44
  `);
50
45
  });
@@ -59,12 +54,9 @@ it("renders an empty enum declaration", async () => {
59
54
  <EnumDeclaration type={TestEnum} />
60
55
  </Wrapper>,
61
56
  ).toRenderTo(`
62
- namespace TestNamespace
57
+ enum TestEnum
63
58
  {
64
- enum TestEnum
65
- {
66
59
 
67
- }
68
60
  }
69
61
  `);
70
62
  });
@@ -82,13 +74,10 @@ it("can override enum name", async () => {
82
74
  <EnumDeclaration type={TestEnum} name="CustomEnumName" />
83
75
  </Wrapper>,
84
76
  ).toRenderTo(`
85
- namespace TestNamespace
77
+ enum CustomEnumName
86
78
  {
87
- enum CustomEnumName
88
- {
89
- Value1,
90
- Value2
91
- }
79
+ Value1,
80
+ Value2
92
81
  }
93
82
  `);
94
83
  });
@@ -106,13 +95,10 @@ it("renders an enum with access modifiers", async () => {
106
95
  <EnumDeclaration type={TestEnum} internal />
107
96
  </Wrapper>,
108
97
  ).toRenderTo(`
109
- namespace TestNamespace
98
+ internal enum TestEnum
110
99
  {
111
- internal enum TestEnum
112
- {
113
- Value1,
114
- Value2
115
- }
100
+ Value1,
101
+ Value2
116
102
  }
117
103
  `);
118
104
  });
@@ -128,21 +114,16 @@ it("renders enum with C# naming conventions", async () => {
128
114
 
129
115
  expect(
130
116
  <Output program={runner.program} namePolicy={createCSharpNamePolicy()}>
131
- <Namespace name="TestNamespace">
132
- <SourceFile path="test.cs">
133
- <EnumDeclaration type={TestEnum} />
134
- </SourceFile>
135
- </Namespace>
117
+ <SourceFile path="test.cs">
118
+ <EnumDeclaration type={TestEnum} />
119
+ </SourceFile>
136
120
  </Output>,
137
121
  ).toRenderTo(`
138
- namespace TestNamespace
122
+ enum TestEnum
139
123
  {
140
- enum TestEnum
141
- {
142
- ValueOne,
143
- ValueTwo,
144
- ValueThree
145
- }
124
+ ValueOne,
125
+ ValueTwo,
126
+ ValueThree
146
127
  }
147
128
  `);
148
129
  });
@@ -159,13 +140,10 @@ it("renders enum with single value", async () => {
159
140
  <EnumDeclaration type={TestEnum} />
160
141
  </Wrapper>,
161
142
  ).toRenderTo(`
162
- namespace TestNamespace
163
- {
164
- enum TestEnum
165
- {
166
- OnlyValue
167
- }
168
- }
143
+ enum TestEnum
144
+ {
145
+ OnlyValue
146
+ }
169
147
  `);
170
148
  });
171
149
 
@@ -184,15 +162,12 @@ it("renders enum with numeric-like member names", async () => {
184
162
  <EnumDeclaration type={TestEnum} />
185
163
  </Wrapper>,
186
164
  ).toRenderTo(`
187
- namespace TestNamespace
165
+ enum TestEnum
188
166
  {
189
- enum TestEnum
190
- {
191
- Value0,
192
- Value1,
193
- Value10,
194
- Value100
195
- }
167
+ Value0,
168
+ Value1,
169
+ Value10,
170
+ Value100
196
171
  }
197
172
  `);
198
173
  });
@@ -217,19 +192,16 @@ it("renders multiple enums in the same namespace", async () => {
217
192
  <EnumDeclaration type={TestEnum2} />
218
193
  </Wrapper>,
219
194
  ).toRenderTo(`
220
- namespace TestNamespace
195
+ enum TestEnum1
196
+ {
197
+ Value1,
198
+ Value2
199
+ }
200
+ enum TestEnum2
221
201
  {
222
- enum TestEnum1
223
- {
224
- Value1,
225
- Value2
226
- }
227
- enum TestEnum2
228
- {
229
- OptionA,
230
- OptionB,
231
- OptionC
232
- }
202
+ OptionA,
203
+ OptionB,
204
+ OptionC
233
205
  }
234
206
  `);
235
207
  });
@@ -249,19 +221,16 @@ it("renders an enum with doc comments", async () => {
249
221
  <EnumDeclaration type={TestEnum} />
250
222
  </Wrapper>,
251
223
  ).toRenderTo(`
252
- namespace TestNamespace
224
+ enum TestEnum
253
225
  {
254
- enum TestEnum
255
- {
256
- /// <summary>
257
- /// This is value one
258
- /// </summary>
259
- Value1,
260
- /// <summary>
261
- /// This is value two
262
- /// </summary>
263
- Value2
264
- }
226
+ /// <summary>
227
+ /// This is value one
228
+ /// </summary>
229
+ Value1,
230
+ /// <summary>
231
+ /// This is value two
232
+ /// </summary>
233
+ Value2
265
234
  }
266
235
  `);
267
236
  });