Skip to content

Commit

Permalink
[FormRecognizer] Added autorest transform to support old service vers…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
kinelski committed Mar 12, 2021
1 parent e2a0efe commit 1b223df
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FormRecognizerClient(Uri endpoint, AzureKeyCredential credential, FormRec

Diagnostics = new ClientDiagnostics(options);
var pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, Constants.AuthorizationHeader));
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri);
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri, options.GetVersionString());
}

/// <summary>
Expand Down Expand Up @@ -93,7 +93,7 @@ public FormRecognizerClient(Uri endpoint, TokenCredential credential, FormRecogn

Diagnostics = new ClientDiagnostics(options);
var pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, Constants.DefaultCognitiveScope));
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri);
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri, options.GetVersionString());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public enum ServiceVersion
/// </summary>
public ServiceVersion Version { get; }

internal static string GetVersionString(ServiceVersion version)
internal string GetVersionString()
{
return version switch
return Version switch
{
ServiceVersion.V2_0 => "v2.0",
ServiceVersion.V2_1_Preview_2 => "v2.1-preview.2",
_ => throw new NotSupportedException($"The service version {version} is not supported."),
_ => throw new NotSupportedException($"The service version {Version} is not supported."),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public FormTrainingClient(Uri endpoint, AzureKeyCredential credential, FormRecog

Diagnostics = new ClientDiagnostics(options);
HttpPipeline pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, Constants.AuthorizationHeader));
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri);
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri, options.GetVersionString());
}

/// <summary>
Expand Down Expand Up @@ -101,7 +101,7 @@ public FormTrainingClient(Uri endpoint, TokenCredential credential, FormRecogniz

Diagnostics = new ClientDiagnostics(options);
var pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, Constants.DefaultCognitiveScope));
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri);
ServiceClient = new FormRecognizerRestClient(Diagnostics, pipeline, endpoint.AbsoluteUri, options.GetVersionString());
}

#region Training
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,41 @@ require:
- https://github.com/Azure/azure-rest-api-specs/blob/788507c386197b1ba7878fa00fe30871b8b01f22/specification/cognitiveservices/data-plane/FormRecognizer/readme.md
```
### Change host template to support old service versions
``` yaml
directive:
- from: swagger-document
where: $["x-ms-parameterized-host"]
transform: >
$["hostTemplate"] = "{endpoint}/formrecognizer/{serviceVersion}";
$["parameters"] = [
{
"$ref": "#/parameters/Endpoint"
},
{
"$ref": "#/parameters/ServiceVersion"
}
]
```
``` yaml
directive:
- from: swagger-document
where: $.parameters
transform: >
$["ServiceVersion"] = {
"name": "serviceVersion",
"in": "path",
"x-ms-parameter-location": "client",
"required": true,
"type": "string",
"x-ms-skip-url-encoding": true
}
```
### Make AnalyzeResult.readResult optional
This is a temporary work-around
``` yaml
directive:
Expand Down

0 comments on commit 1b223df

Please sign in to comment.