Skip to content

Commit

Permalink
Fix custompage issue when there are two (#3389)
Browse files Browse the repository at this point in the history
* Fix custompage issue when there are two

* Update

* update

* Update

* comment out shared source check until 3392 gets merged

---------

Co-authored-by: m-nash <[email protected]>
  • Loading branch information
pshao25 and m-nash authored May 12, 2023
1 parent 79a6291 commit 8b06121
Show file tree
Hide file tree
Showing 22 changed files with 1,692 additions and 540 deletions.
7 changes: 4 additions & 3 deletions eng/SharedCodeCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 1

Write-Host 'Downloading shared source files...'
& (Join-Path $PSScriptRoot 'DownloadSharedSource.ps1')
Write-Host 'Shared source files are downloaded'
#uncomment when this is fixed https://github.com/Azure/autorest.csharp/pull/3392
#Write-Host 'Downloading shared source files...'
#& (Join-Path $PSScriptRoot 'DownloadSharedSource.ps1')
#Write-Host 'Shared source files are downloaded'

Write-Host 'Checking file difference...'
git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code
Expand Down
4 changes: 2 additions & 2 deletions src/CADL.Extension/Emitter.Csharp/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
getSdkSimpleType,
isInternal
} from "@azure-tools/typespec-client-generator-core";
import { capitalize } from "./utils.js";
import { capitalize, getNameForTemplate } from "./utils.js";
/**
* Map calType to csharp InputTypeKind
*/
Expand Down Expand Up @@ -380,7 +380,7 @@ export function getInputType(

function getInputModelForModel(m: Model): InputModelType {
m = getEffectiveSchemaType(context, m) as Model;
const name = getFriendlyName(program, m) ?? m.name;
const name = getFriendlyName(program, m) ?? getNameForTemplate(m);
let model = models.get(name);
if (!model) {
const baseModel = getInputModelBaseType(m.baseModel);
Expand Down
13 changes: 13 additions & 0 deletions src/CADL.Extension/Emitter.Csharp/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import { Model } from "@typespec/compiler";

export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}

export function getNameForTemplate(model: Model): string {
if (model.templateMapper && model.templateMapper.args) {
return (
model.name +
model.templateMapper.args.map((it) => (it as Model).name).join("")
);
}

return model.name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"Models": [
{
"$id": "2",
"Name": "CustomPage",
"Name": "CustomPageLedgerEntry",
"Namespace": "Azure.Core.Foundations",
"Description": "Paged collection of LedgerEntry items",
"IsNullable": false,
"Usage": "Output",
"Usage": "None",
"Properties": [
{
"$id": "3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@
},
{
"$id": "18",
"Name": "CustomPage",
"Name": "CustomPageUser",
"Namespace": "Azure.Core.Foundations",
"Description": "Paged collection of User items",
"IsNullable": false,
"Usage": "Output",
"Usage": "None",
"Properties": [
{
"$id": "19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,7 @@ var client = new AuthoringClient(endpoint);
await foreach (var item in client.GetDeploymentsAsync("<projectName>", new RequestContext()))
{
JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("projectName").ToString());
Console.WriteLine(result.GetProperty("projectKind").ToString());
Console.WriteLine(result.GetProperty("storageInputContainerName").ToString());
Console.WriteLine(result.GetProperty("settings").GetProperty("<test>").ToString());
Console.WriteLine(result.GetProperty("multilingual").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("language").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("lastModifiedDateTime").ToString());
Console.WriteLine(result.GetProperty("lastTrainedDateTime").ToString());
Console.WriteLine(result.GetProperty("lastDeployedDateTime").ToString());
Console.WriteLine(result.GetProperty("name").ToString());
}
]]></code>
</example>
Expand All @@ -644,17 +634,7 @@ var client = new AuthoringClient(endpoint);
foreach (var item in client.GetDeployments("<projectName>", new RequestContext()))
{
JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("projectName").ToString());
Console.WriteLine(result.GetProperty("projectKind").ToString());
Console.WriteLine(result.GetProperty("storageInputContainerName").ToString());
Console.WriteLine(result.GetProperty("settings").GetProperty("<test>").ToString());
Console.WriteLine(result.GetProperty("multilingual").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("language").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("lastModifiedDateTime").ToString());
Console.WriteLine(result.GetProperty("lastTrainedDateTime").ToString());
Console.WriteLine(result.GetProperty("lastDeployedDateTime").ToString());
Console.WriteLine(result.GetProperty("name").ToString());
}
]]></code>
</example>
Expand Down
Loading

0 comments on commit 8b06121

Please sign in to comment.