Skip to content

Commit 5da30e9

Browse files
authored
Update CodeGen to version 3.0.0-beta.20240312.2 (#22)
1 parent f49feeb commit 5da30e9

File tree

247 files changed

+4302
-2647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+4302
-2647
lines changed

.dotnet/scripts/Update-ClientModel.ps1

+61-16
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function Update-OpenAIClient {
3434
$content = $content -creplace "\s+\/\/\/ <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>", ""
3535
$content = $content -creplace "\s+internal TelemetrySource ClientDiagnostics { get; }", ""
3636
$content = $content -creplace "\(KeyCredential", "(ApiKeyCredential"
37-
$content = $content -creplace "ClientUtilities.AssertNotNull\((?<var>\w+), nameof\((\w+)\)\);", "if (`${var} is null) throw new ArgumentNullException(nameof(`${var}));"
3837
$content = $content -creplace "\s+ClientDiagnostics = new TelemetrySource\(options, true\);", ""
3938
$content = $content -creplace "_pipeline = MessagePipeline\.Create\(options, new IPipelinePolicy<PipelineMessage>\[\] \{ new KeyCredentialPolicy\(_keyCredential, AuthorizationHeader, AuthorizationApiKeyPrefix\) \}, Array\.Empty<IPipelinePolicy<PipelineMessage>>\(\)\);", "var authenticationPolicy = ApiKeyAuthenticationPolicy.CreateBearerAuthorizationPolicy(_credential);`r`n _pipeline = ClientPipeline.Create(options,`r`n perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,`r`n perTryPolicies: new PipelinePolicy[] { authenticationPolicy },`r`n beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);"
4039
$content = $content -creplace "\(ClientDiagnostics, ", "("
@@ -75,10 +74,6 @@ function Update-Subclients {
7574
$content = $content -creplace "\s+using System.ClientModel.Primitives.Pipeline;", ""
7675
$content = $content -creplace "using System.ClientModel.Primitives;", "using System.ClientModel.Primitives;`r`nusing System.Text;"
7776

78-
# Fix ClientUtilities
79-
$content = $content -creplace "ClientUtilities.AssertNotNull\((?<var>\w+), nameof\((\w+)\)\);", "if (`${var} is null) throw new ArgumentNullException(nameof(`${var}));"
80-
$content = $content -creplace "ClientUtilities.AssertNotNullOrEmpty\((?<var>\w+), nameof\((\w+)\)\);", "if (`${var} is null) throw new ArgumentNullException(nameof(`${var}));`r`n if (string.IsNullOrEmpty(`${var})) throw new ArgumentException(nameof(`${var}));"
81-
8277
# Delete TelemetrySource
8378
$content = $content -creplace "\s+\/\/\/ <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>", ""
8479
$content = $content -creplace "\s+internal TelemetrySource ClientDiagnostics { get; }", ""
@@ -115,11 +110,10 @@ function Update-Subclients {
115110
$content = $content -creplace " RequestBody content", " BinaryContent content"
116111
$content = $content -creplace "\(RequestOptions context", "(RequestOptions options"
117112
$content = $content -creplace " RequestOptions context", " RequestOptions options"
118-
$content = $content -creplace "\s+using var scope = ClientDiagnostics\.CreateSpan\(`"(\w+\.\w+)`"\);", ""
119-
$content = $content -creplace "\s+scope\.Start\(\);", ""
120-
$content = $content -creplace "(?s)\s+try\s+\{\s+using PipelineMessage message = (?<method>\w+)\((?<params>[(\w+)(,\s\w+)]*)context\);\s+return Result\.FromResponse\(await _pipeline\.ProcessMessageAsync\(message, context\)\.ConfigureAwait\(false\)\);\s+\}", "`r`n options ??= new RequestOptions();`r`n using PipelineMessage message = `${method}(`${params}options);`r`n await _pipeline.SendAsync(message).ConfigureAwait(false);`r`n PipelineResponse response = message.Response!;`r`n`r`n if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)`r`n {`r`n throw await ClientResultException.CreateAsync(response).ConfigureAwait(false);`r`n }`r`n`r`n return ClientResult.FromResponse(response);"
121-
$content = $content -creplace "(?s)\s+try\s+\{\s+using PipelineMessage message = (?<method>\w+)\((?<params>[(\w+)(,\s\w+)]*)context\);\s+return Result\.FromResponse\(_pipeline.ProcessMessage\(message, context\)\);\s+\}", "`r`n options ??= new RequestOptions();`r`n using PipelineMessage message = `${method}(`${params}options);`r`n _pipeline.Send(message);`r`n PipelineResponse response = message.Response!;`r`n`r`n if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)`r`n {`r`n throw new ClientResultException(response);`r`n }`r`n`r`n return ClientResult.FromResponse(response);"
122-
$content = $content -creplace "(?s)\s+catch \(Exception e\)\s+\{\s+scope\.Failed\(e\);\s+throw;\s+\}", ""
113+
$content = $content -creplace "context\)", "options)"
114+
$content = $content -creplace "using var scope = ClientDiagnostics\.CreateSpan\(`"(?<tag>\w+)\.(?<operationId>\w+)`"\);", "options ??= new RequestOptions();`r`n // using var scope = ClientDiagnostics.CreateSpan(`"`${tag}.`${operationId}`"\);"
115+
$content = $content -creplace "scope\.Start\(\);", "// scope.Start();"
116+
$content = $content -creplace "scope\.Failed\(e\);", "// scope.Failed(e);"
123117

124118
# Create request
125119
$content = $content -creplace "\(RequestBody content", "(BinaryContent content"
@@ -136,9 +130,6 @@ function Update-Subclients {
136130
$content = $content -creplace "request\.SetHeaderValue", "request.Headers.Set"
137131
$content = $content -creplace "request\.Content = content;", "request.Content = content;`r`n message.Apply(options);"
138132

139-
# Delete DefaultRequestContext
140-
# $content = $content -creplace "\s+private static RequestOptions DefaultRequestContext = new RequestOptions\(\);", ""
141-
142133
# Clean up ApiKeyCredential
143134
$content = $content -creplace " KeyCredential", " ApiKeyCredential"
144135
$content = $content -creplace "_keyCredential", "_credential"
@@ -170,16 +161,67 @@ function Update-Models {
170161
Write-Output "Editing $($file.FullName)"
171162

172163
$content = $content -creplace "\s+#nullable disable", ""
173-
$content = $content -creplace "ClientUtilities.AssertNotNull\((?<var>@?\w+), nameof\((@?\w+)\)\);", "if (`${var} is null) throw new ArgumentNullException(nameof(`${var}));"
174-
$content = $content -creplace "using System.ClientModel.Internal;", "using OpenAI.ClientShared.Internal;"
164+
$content = $content -creplace "using System\.ClientModel\.Internal;", "using OpenAI.ClientShared.Internal;"
165+
$content = $content -creplace "using System\.ClientModel\.Primitives;", "using System.ClientModel;`r`nusing System.ClientModel.Primitives;"
175166
$content = $content -creplace ": IUtf8JsonWriteable,", ":"
176167
$content = $content -creplace "\s+void IUtf8JsonWriteable\.Write\(Utf8JsonWriter writer\) => \(\(IJsonModel<(\w+)>\)this\)\.Write\(writer, new ModelReaderWriterOptions\(`"W`"\)\);`r`n", ""
177-
$content = $content -creplace "(?s)\s+\/\/\/ <summary> Convert into a Utf8JsonRequestBody\. </summary>.*?return content;.*?\}", ""
168+
$content = $content -creplace " RequestBody", " BinaryContent"
178169

179170
$content | Set-Content -Path $file.FullName -NoNewline
180171
}
181172
}
182173

174+
function Update-InternalClientPipelineExtensions {
175+
$root = Split-Path $PSScriptRoot -Parent
176+
$directory = Join-Path -Path $root -ChildPath "src\Generated\Internal"
177+
$file = Get-ChildItem -Path $directory -Filter "ClientPipelineExtensions.cs"
178+
$content = Get-Content -Path $file -Raw
179+
180+
Write-Output "Editing $($file.FullName)"
181+
182+
$content = $content -creplace "\s+using System\.ClientModel\.Primitives\.Pipeline;", ""
183+
$content = $content -creplace " Pipeline<PipelineMessage>", " ClientPipeline"
184+
$content = $content -creplace "\.ErrorBehavior", ".ErrorOptions"
185+
$content = $content -creplace "ErrorBehavior\.", "ClientErrorBehaviors."
186+
$content = $content -creplace " MessageFailedException", " ClientResultException"
187+
$content = $content -creplace "(?s)\s+public static async ValueTask<NullableResult<bool>> ProcessHeadAsBoolMessageAsync.*?\}.*?\}", ""
188+
$content = $content -creplace "(?s)\s+public static NullableResult<bool> ProcessHeadAsBoolMessage.*?\}.*?\}", ""
189+
190+
$content | Set-Content -Path $file.FullName -NoNewline
191+
}
192+
193+
function Update-InternalErrorResult {
194+
$root = Split-Path $PSScriptRoot -Parent
195+
$directory = Join-Path -Path $root -ChildPath "src\Generated\Internal"
196+
$file = Get-ChildItem -Path $directory -Filter "ErrorResult.cs"
197+
$content = Get-Content -Path $file -Raw
198+
199+
Write-Output "Editing $($file.FullName)"
200+
201+
$content = $content -creplace " MessagePipeline", " ClientPipeline"
202+
$content = $content -creplace " Result", " ClientResult"
203+
$content = $content -creplace " MessageFailedException", " ClientResultException"
204+
$content = $content -creplace "\s+public override bool HasValue => false;", ""
205+
$content = $content -creplace "(?s)\s+public override PipelineResponse GetRawResponse\(\)\s+\{\s+return _response;\s+\}", ""
206+
207+
$content | Set-Content -Path $file.FullName -NoNewline
208+
}
209+
210+
function Update-InternalUtf8JsonRequestBody {
211+
$root = Split-Path $PSScriptRoot -Parent
212+
$directory = Join-Path -Path $root -ChildPath "src\Generated\Internal"
213+
$file = Get-ChildItem -Path $directory -Filter "Utf8JsonRequestBody.cs"
214+
$content = Get-Content -Path $file -Raw
215+
216+
Write-Output "Editing $($file.FullName)"
217+
218+
$content = $content -creplace "using System\.ClientModel\.Primitives;", "using System;`r`nusing System.ClientModel;"
219+
$content = $content -creplace " RequestBody", " BinaryContent"
220+
$content = $content -creplace "_content = CreateFromStream\(_stream\);", "_content = BinaryContent.Create(BinaryData.FromStream(_stream));"
221+
222+
$content | Set-Content -Path $file.FullName -NoNewline
223+
}
224+
183225
function Update-Tests {
184226
$root = Split-Path $PSScriptRoot -Parent
185227
$directory = Join-Path -Path $root -ChildPath "tests\Generated\Tests"
@@ -201,4 +243,7 @@ Update-OpenAIClient
201243
Update-OpenAIClientOptions
202244
Update-Subclients
203245
Update-Models
246+
Update-InternalClientPipelineExtensions
247+
Update-InternalErrorResult
248+
Update-InternalUtf8JsonRequestBody
204249
Update-Tests

.dotnet/src/ClientShared/OptionalDictionary.cs

-214
This file was deleted.

0 commit comments

Comments
 (0)