Follow Quickstart to generate the Data-Plane Client from OpenAPI specs.
It is advised to update OpenAPI specs with security: AADToken
. And then re-generate the SDK.
If one does not wish to change the specs, add following configure to README_SPEC.md, and re-generate the SDK.
security: AADToken
security-scopes: https://cognitiveservices.azure.com/.default
Here is an example of the modification of README_SPEC.md and the resulted code changes.
Note that a new method credential(TokenCredential tokenCredential)
is generated in builder class.
Usually security: AzureKey
can provide implementation of API key authentication.
For more complex API key authentication, one can customize the builder class.
Here is an example of the modification of builder to support subscription key and API key.
- Create
MetricsAdvisorKeys
andMetricsAdvisorKeyCredential
class inmodels
package. - Modify
MetricsAdvisorClientBuilder
to acceptMetricsAdvisorKeyCredential
from user, and then pass the keys in it to HTTP pipeline.
Note that the Generated
annotation on createHttpPipeline()
is removed, as we customized this method.
This ensures that future code generate will not override this customized method.
Generated client methods accept RequestOptions
for request parameters.
For frequently invoked methods, one can customize them for better user-experience.
Here is an example of the modification of client to support options for client methods.
- Create
ListDataFeedFilter
andListDataFeedOptions
class inmodels
package. - Modify
MetricsAdvisorAsyncClient
andMetricsAdvisorClient
to provide overloadedlistDataFeeds
method that takesListDataFeedOptions
options. - Convert options from
ListDataFeedOptions
toRequestOptions
inlistDataFeeds
method.
Note that the conversion only happen once in package private MetricsAdvisorAsyncClient.listDataFeeds(ListDataFeedOptions, Context)
method, which is invoked by all added listDataFeeds
methods.
Generated client methods accept and produce BinaryData
for request payload and response body.
For frequently invoked methods, one can customize them for better user-experience.
Here is an example of the modification of client to support DataFeedDetail
as response of paged operation.
- Create
DataFeedDetail
class and all related classed inmodels
package. - Modify
MetricsAdvisorAsyncClient
andMetricsAdvisorClient
to provide overloadedlistDataFeeds
method that produce paged response ofDataFeedDetail
. (as these are already customized method, in example we only modify them in place) BinaryData.toObject(Class<T>)
convertBinaryData
toDataFeedDetail
.- Utility method
mapPage(PagedFlux<T> pagedFlux, Function<T, S> mapper)
is provided to convertPagedFlux
. - Convert response of
PagedFlux<BinaryData>
toPagedFlux<DataFeedDetail>
inlistDataFeeds
method.
Note that the conversion only happen once in package private MetricsAdvisorAsyncClient.listDataFeeds(ListDataFeedOptions, Context)
method, which is invoked by all added listDataFeeds
methods.
Here is an example of the modification of client to support DataFeedDetail
as request payload.
- Create
DataFeedDetail
class and all related classed inmodels
package. - Modify
MetricsAdvisorAsyncClient
andMetricsAdvisorClient
to provide overloadedcreateDataFeed
method that acceptDataFeedDetail
. BinaryData.fromObject(Class<T>)
convertDataFeedDetail
toBinaryData
.
Note that the conversion only happen once in package private createDataFeed(DataFeedDetail dataFeed, Context context)
method, which is invoked by all added createDataFeed
methods.
In this special scenario, service only return a "Location" header of the resource URL of the created data feed. For better user-experience, SDK send another GET request to retrieve the detail of the created data feed, following the resource URL.
When one create models
package to house the model classes, one need to consider:
- Add a
package-info.java
inmodels
package. - Modify
module-info.java
to expose it to user, and optionally open it to JSON serialization. See Java Modules.
A typical section in module-info.java
:
exports com.azure.ai.metricsadvisor.models;
opens com.azure.ai.metricsadvisor.models to
com.azure.core,
com.fasterxml.jackson.databind;