Skip to content

Commit a161eb8

Browse files
authored
Fix effective model issue (#3060)
* Fix effective model issue * Fix
1 parent 9124b1c commit a161eb8

File tree

7 files changed

+504
-50
lines changed

7 files changed

+504
-50
lines changed

src/CADL.Extension/Emitter.Csharp/src/lib/model.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,10 @@ export function getUsages(
599599
let typeName = "";
600600
if ("name" in type) typeName = type.name ?? "";
601601
if (type.kind === "Model") {
602-
const effectiveType = getEffectiveModelType(program, type);
602+
const effectiveType = getEffectiveSchemaType(
603+
program,
604+
type
605+
) as Model;
603606
typeName =
604607
getFriendlyName(program, effectiveType) ?? effectiveType.name;
605608
}

test/TestProjects/Lro-Basic-Cadl/Generated/Docs/LroBasicCadlClient.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,84 @@ Schema for <c>Project</c>:
203203
}
204204
</code>
205205

206+
</remarks>
207+
</member>
208+
<member name="CreateThingAsync(WaitUntil,RequestContent,RequestContext)">
209+
<example>
210+
This sample shows how to call CreateThingAsync with required parameters and request content and parse the result.
211+
<code><![CDATA[
212+
var endpoint = new Uri("<https://my-service.azure.com>");
213+
var client = new LroBasicCadlClient(endpoint);
214+
215+
var data = new {
216+
name = "<name>",
217+
};
218+
219+
var operation = await client.CreateThingAsync(WaitUntil.Completed, RequestContent.Create(data));
220+
221+
BinaryData data = operation.Value;
222+
JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
223+
Console.WriteLine(result.GetProperty("name").ToString());
224+
]]></code>
225+
</example>
226+
<remarks>
227+
Below is the JSON schema for the request and response payloads.
228+
229+
Request Body:
230+
231+
Schema for <c>Thing</c>:
232+
<code>{
233+
name: string, # Required.
234+
}
235+
</code>
236+
237+
Response Body:
238+
239+
Schema for <c>Thing</c>:
240+
<code>{
241+
name: string, # Required.
242+
}
243+
</code>
244+
245+
</remarks>
246+
</member>
247+
<member name="CreateThing(WaitUntil,RequestContent,RequestContext)">
248+
<example>
249+
This sample shows how to call CreateThing with required parameters and request content and parse the result.
250+
<code><![CDATA[
251+
var endpoint = new Uri("<https://my-service.azure.com>");
252+
var client = new LroBasicCadlClient(endpoint);
253+
254+
var data = new {
255+
name = "<name>",
256+
};
257+
258+
var operation = client.CreateThing(WaitUntil.Completed, RequestContent.Create(data));
259+
260+
BinaryData data = operation.Value;
261+
JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
262+
Console.WriteLine(result.GetProperty("name").ToString());
263+
]]></code>
264+
</example>
265+
<remarks>
266+
Below is the JSON schema for the request and response payloads.
267+
268+
Request Body:
269+
270+
Schema for <c>Thing</c>:
271+
<code>{
272+
name: string, # Required.
273+
}
274+
</code>
275+
276+
Response Body:
277+
278+
Schema for <c>Thing</c>:
279+
<code>{
280+
name: string, # Required.
281+
}
282+
</code>
283+
206284
</remarks>
207285
</member>
208286
</members>

test/TestProjects/Lro-Basic-Cadl/Generated/LroBasicCadlClient.cs

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System.Text.Json;
9+
using Azure;
10+
using Azure.Core;
11+
12+
namespace LroBasicCadl.Models
13+
{
14+
public partial class Thing : IUtf8JsonSerializable
15+
{
16+
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
17+
{
18+
writer.WriteStartObject();
19+
writer.WritePropertyName("name");
20+
writer.WriteStringValue(Name);
21+
writer.WriteEndObject();
22+
}
23+
24+
internal static Thing DeserializeThing(JsonElement element)
25+
{
26+
string name = default;
27+
foreach (var property in element.EnumerateObject())
28+
{
29+
if (property.NameEquals("name"))
30+
{
31+
name = property.Value.GetString();
32+
continue;
33+
}
34+
}
35+
return new Thing(name);
36+
}
37+
38+
/// <summary> Deserializes the model from a raw response. </summary>
39+
/// <param name="response"> The response to deserialize the model from. </param>
40+
internal static Thing FromResponse(Response response)
41+
{
42+
using var document = JsonDocument.Parse(response.Content);
43+
return DeserializeThing(document.RootElement);
44+
}
45+
46+
/// <summary> Convert into a Utf8JsonRequestContent. </summary>
47+
internal virtual RequestContent ToRequestContent()
48+
{
49+
var content = new Utf8JsonRequestContent();
50+
content.JsonWriter.WriteObjectValue(this);
51+
return content;
52+
}
53+
}
54+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System;
9+
using Azure.Core;
10+
11+
namespace LroBasicCadl.Models
12+
{
13+
/// <summary> The Thing. </summary>
14+
public partial class Thing
15+
{
16+
/// <summary> Initializes a new instance of Thing. </summary>
17+
/// <param name="name"></param>
18+
/// <exception cref="ArgumentNullException"> <paramref name="name"/> is null. </exception>
19+
public Thing(string name)
20+
{
21+
Argument.AssertNotNull(name, nameof(name));
22+
23+
Name = name;
24+
}
25+
26+
/// <summary> Gets or sets the name. </summary>
27+
public string Name { get; set; }
28+
}
29+
}

0 commit comments

Comments
 (0)