diff --git a/sdk/schemaregistry/azure-data-schemaregistry/CHANGELOG.md b/sdk/schemaregistry/azure-data-schemaregistry/CHANGELOG.md index e3f543d09ef5..0a17beefead0 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/CHANGELOG.md +++ b/sdk/schemaregistry/azure-data-schemaregistry/CHANGELOG.md @@ -1,403 +1,13 @@ # Release History -## 1.6.0-beta.1 (Unreleased) +## 1.0.0-beta.1 (Unreleased) -### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes - -## 1.5.1 (2024-10-25) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.15.4` to version `1.15.5`. -- Upgraded `azure-core` from `1.52.0` to version `1.53.0`. - - -## 1.5.0 (2024-09-12) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.15.2` to version `1.15.3`. -- Upgraded `azure-core` from `1.50.0` to version `1.51.0`. - -## 1.4.8 (2024-07-26) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.15.1` to version `1.15.2`. -- Upgraded `azure-core` from `1.49.1` to version `1.50.0`. - -## 1.4.7 (2024-06-27) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.15.0` to version `1.15.1`. -- Upgraded `azure-core` from `1.49.0` to version `1.49.1`. - - -## 1.4.6 (2024-05-28) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.48.0` to version `1.49.0`. -- Upgraded `azure-core-http-netty` from `1.14.2` to version `1.15.0`. - - -## 1.4.5 (2024-04-23) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.47.0` to version `1.48.0`. -- Upgraded `azure-core-http-netty` from `1.14.1` to version `1.14.2`. - - -## 1.4.4 (2024-03-20) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.46.0` to version `1.47.0`. -- Upgraded `azure-core-http-netty` from `1.14.0` to version `1.14.1`. - - -## 1.4.3 (2024-02-22) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.45.1` to version `1.46.0`. -- Upgraded `azure-core-http-netty` from `1.13.11` to version `1.14.0`. - - -## 1.4.2 (2023-12-04) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.13.10` to version `1.13.11`. -- Upgraded `azure-core` from `1.45.0` to version `1.45.1`. - - -## 1.4.1 (2023-11-20) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.44.1` to version `1.45.0`. -- Upgraded `azure-core-http-netty` from `1.13.9` to version `1.13.10`. - - -## 1.4.0 (2023-10-24) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.43.0` to version `1.44.1`. -- Upgraded `azure-core-http-netty` from `1.13.7` to version `1.13.9`. - -## 1.3.10 (2023-09-19) +- Azure SchemaRegistry client library for Java. This package contains Microsoft Azure SchemaRegistry client library. ### Features Added -- Add support for protobuf schema format. - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.42.0` to version `1.43.0`. -- Upgraded `azure-core-http-netty` from `1.13.6` to version `1.13.7`. - -## 1.3.9 (2023-08-18) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.41.0` to version `1.42.0`. -- Upgraded `azure-core-http-netty` from `1.13.5` to version `1.13.6`. - -## 1.3.8 (2023-07-25) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.40.0` to version `1.41.0`. -- Upgraded `azure-core-http-netty` from `1.13.4` to version `1.13.5`. - - -## 1.3.7 (2023-06-20) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core` from `1.39.0` to version `1.40.0`. -- Upgraded `azure-core-http-netty` from `1.13.3` to version `1.13.4`. - -## 1.3.6 (2023-05-23) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.13.2` to version `1.13.3`. -- Upgraded `azure-core` from `1.38.0` to version `1.39.0`. - -## 1.3.5 (2023-04-21) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.13.1` to version `1.13.2`. -- Upgraded `azure-core` from `1.37.0` to version `1.38.0`. - -## 1.3.4 (2023-03-16) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.13.0` to version `1.13.1`. -- Upgraded `azure-core` from `1.36.0` to version `1.37.0`. - -## 1.3.3 (2023-02-16) - -### Other Changes - -#### Dependency Updates - -- Upgraded `azure-core-http-netty` from `1.12.8` to version `1.13.0`. -- Upgraded `azure-core` from `1.35.0` to version `1.36.0`. - -## 1.4.0-beta.2 (2023-02-13) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.36.0`. -- Update `azure-core-http-netty` dependency to `1.13.0`. - -## 1.4.0-beta.1 (2023-01-26) - -### Features Added - -- Added additional `SchemaFormat`s, `SchemaFormat.JSON`, and `SchemaFormat.CUSTOM`. -- Added new service version, `SchemaRegistryVersion.V2022_10`. -- Updated the latest service version to `SchemaRegistryVersion.V2022_10`. - -## 1.3.2 (2023-01-18) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.35.0`. -- Update `azure-core-http-netty` dependency to `1.12.8`. - -## 1.3.1 (2022-11-16) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.34.0`. -- Update `azure-core-http-netty` dependency to `1.12.7`. - -## 1.3.0 (2022-10-11) - -### Features Added - -- Added `getVersion` to `SchemaProperties`. -- Added the following methods in `SchemaRegistryAsyncClient`: - - `Mono getSchema(String groupName, String schemaName, int schemaVersion)` - - `Mono> getSchemaWithResponse(String groupName, String schemaName, int schemaVersion)` -- Added the following methods in `SchemaRegistryClient`: - - `SchemaRegistrySchema getSchema(String groupName, String schemaName, int schemaVersion)` - - `Response getSchemaWithResponse(String groupName, String schemaName, int schemaVersion, Context context)` - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.33.0`. -- Update `azure-core-http-netty` dependency to `1.12.6`. - -## 1.2.4 (2022-09-12) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.32.0`. -- Update `azure-core-http-netty` dependency to `1.12.5`. - -## 1.2.3 (2022-08-10) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.31.0`. -- Update `azure-core-http-netty` dependency to `1.12.4`. - -## 1.2.2 (2022-07-12) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.30.0`. -- Update `azure-core-http-netty` dependency to `1.12.3`. - -## 1.2.1 (2022-06-10) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.29.1`. -- Update `azure-core-http-netty` dependency to `1.12.2`. - -## 1.2.0 (2022-05-13) - -### Features Added - -- Added `SchemaProperties.getGroupName()`. -- Added `SchemaProperties.getName()`. - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.28.0`. -- Update `azure-core-http-netty` dependency to `1.12.0`. - -## 1.1.1 (2022-04-07) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.27.0`. -- Update `azure-core-http-netty` dependency to `1.11.9`. - -## 1.1.0 (2022-03-15) - -### Features Added - -- Added interfaces from `com.azure.core.client.traits` to `SchemaRegistryClientBuilder`. -- Added `retryOptions` to `SchemaRegistryClientBuilder`. - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.26.0`. -- Update `azure-core-http-netty` dependency to `1.11.8`. - -## 1.0.2 (2022-02-12) - -### Other Changes - -#### Dependency Updates - -- Update `azure-core` dependency to `1.25.0`. - -## 1.0.1 (2022-01-18) - -### Bugs Fixed - -- Fixed double serialization of JSON when publishing/reading schemas. #25789 - -## 1.0.0 (2021-11-12) - ### Breaking Changes -- Removed preview `SchemaRegistryVersion.2017_04`. -- Renamed `SchemaRegistrySchema.getSchemaDefinition` to `SchemaRegistrySchema.getDefinition`. - ### Bugs Fixed -- Added correct User Agent string for client. - -### Other Changes - -- Regenerated REST API based off 2021-10 swagger. -- An `HttpResponseException` with status code 415 is returned if an invalid `SchemaFormat` is passed for `registerSchema` or `getSchemaById` calls. - -## 1.0.0-beta.6 (2021-10-08) - -### Features added - -- Added `SchemaRegistrySchema`. -- Added `SchemaRegistryVersion`. -- Added back `Response` overloads for `getSchema`, `getSchemaProperties`. - -### Breaking changes - -- Removed client-side caching. -- Changed `getSchemaId` to `getSchemaProperties`. -- Moved `SchemaProperties.getSchema()` to `SchemaRegistrySchema.getSchemaDefinition()`. -- Changed `getSchema()` to return `String` instead of `byte[]`. -- Changed `SerializationType` to `SchemaFormat`. - ### Other Changes - -#### Dependency Updates - -- Update `azure-core-serializer-avro-apache` dependency to `1.0.0-beta.13`. - -## 1.0.0-beta.5 (2021-08-17) - -### Features added -- Caching schemas based on schemaId. - -### Breaking changes -- 4xx responses return their respective `HttpResponseException` rather than `IllegalStateException` -- Removed `Response` overloads for getSchema and getSchemaId because response could be cached. -- `SchemaRegistryClientBuilder.maxCacheSize` is package-private. - -### Other Changes - -#### Dependency Updates - -- Update `azure-core-serializer-avro-apache` dependency to `1.0.0-beta.13`. - -## 1.0.0-beta.4 (2020-09-21) -- Minor code cleanup and refactoring - -## 1.0.0-beta.3 (2020-09-10) -- Removed `SchemaRegistryCodec` and `SchemaRegistrySerializer` -- Updated Schema Registry client APIs to use `SchemaProperties` - -## 1.0.0-beta.2 (2020-06-19) -- Fix 4xx HTTP response handling - -## 1.0.0-beta.1 (2020-06-04) -- Initial add diff --git a/sdk/schemaregistry/azure-data-schemaregistry/README.md b/sdk/schemaregistry/azure-data-schemaregistry/README.md index b6e06eddc01d..7618d57ee8f0 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/README.md +++ b/sdk/schemaregistry/azure-data-schemaregistry/README.md @@ -1,221 +1,80 @@ -# Azure Schema Registry client library for Java +# Azure SchemaRegistry client library for Java -Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning, -and management. The registry is leveraged by applications to reduce payload size while describing payload structure with -schema identifiers rather than full schemas. +Azure SchemaRegistry client library for Java. -[Source code][source_code] | [Package (Maven)][package_maven] | [API reference documentation][api_reference_doc] | [Product Documentation][product_documentation] | [Samples][sample_readme] +This package contains Microsoft Azure SchemaRegistry client library. -## Getting started - -### Prerequisites - -- A [Java Development Kit (JDK)][jdk_link], version 8 or later. -- [Azure Subscription][azure_subscription] -- An [Event Hubs schema registry][event_hubs_namespace] +## Documentation -### Include the package +Various documentation is available to help you get started -#### Include the BOM file +- [API reference documentation][docs] +- [Product documentation][product_documentation] -Please include the azure-sdk-bom to your project to take dependency on the General Availability (GA) version of the library. In the following snippet, replace the {bom_version_to_target} placeholder with the version number. -To learn more about the BOM, see the [AZURE SDK BOM README](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/boms/azure-sdk-bom/README.md). +## Getting started -```xml - - - - com.azure - azure-sdk-bom - {bom_version_to_target} - pom - import - - - -``` -and then include the direct dependency in the dependencies section without the version tag as shown below. +### Prerequisites -```xml - - - com.azure - azure-data-schemaregistry - - -``` +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] -#### Include direct dependency -If you want to take dependency on a particular version of the library that is not present in the BOM, -add the direct dependency to your project as follows. +### Adding the package to your product [//]: # ({x-version-update-start;com.azure:azure-data-schemaregistry;current}) ```xml - - com.azure - azure-data-schemaregistry - 1.5.0 - -``` -[//]: # ({x-version-update-end}) - -### Authenticate the client -In order to interact with the Azure Schema Registry service, you'll need to create an instance of the -`SchemaRegistryClient` class through the `SchemaRegistryClientBuilder`. You will need an **endpoint** and an -**API key** to instantiate a client object. - -#### Create SchemaRegistryClient with Azure Active Directory Credential - -You can authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. Note that regional endpoints do not support AAD authentication. Create a [custom subdomain][custom_subdomain] for your resource in order to use this type of authentication. - -To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below, or other credential providers provided with the Azure SDK, please include the `azure-identity` package: - -[//]: # ({x-version-update-start;com.azure:azure-identity;dependency}) -```xml com.azure - azure-identity - 1.14.2 + azure-data-schemaregistry + 1.0.0-beta.1 ``` +[//]: # ({x-version-update-end}) -You will also need to [register a new AAD application][register_aad_app] and [grant access][aad_grant_access] to - Schema Registry service. - -Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET. - -##### Async client - -```java com.azure.data.schemaregistry.schemaregistryasyncclient.construct -DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() - .build(); -SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("https://.servicebus.windows.net") - .credential(azureCredential) - .buildAsyncClient(); -``` - -##### Sync client +### Authentication -```java com.azure.data.schemaregistry.schemaregistryclient.construct -DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() - .build(); -SchemaRegistryClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("https://.servicebus.windows.net") - .credential(azureCredential) - .buildClient(); -``` +[Azure Identity][azure_identity] package provides the default implementation for authenticating the client. ## Key concepts -### Schemas - -A schema has 6 components: -- Group Name: The name of the group of schemas in the Schema Registry instance. -- Schema Name: The name of the schema. -- Schema ID: The ID assigned by the Schema Registry instance for the schema. -- Serialization Type: The format used for serialization of the schema. For example, Avro. -- Schema Content: The string representation of the schema. -- Schema Version: The version assigned to the schema in the Schema Registry instance. - -These components play different roles. Some are used as input into the operations and some are outputs. Currently, -[SchemaProperties][schema_properties] only exposes those properties that are potential outputs that are used in -SchemaRegistry operations. Those exposed properties are `Content` and `Id`. ## Examples -* [Register a schema](#register-a-schema) -* [Retrieve a schema's properties](#retrieve-a-schemas-properties) -* [Retrieve a schema](#retrieve-a-schema) - -### Register a schema -Register a schema to be stored in the Azure Schema Registry. - -```java com.azure.data.schemaregistry.schemaregistryclient.registerschema-avro -String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}"; -SchemaProperties properties = client.registerSchema("{schema-group}", "{schema-name}", schema, - SchemaFormat.AVRO); - -System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), properties.getFormat()); +```java com.azure.data.schemaregistry.readme ``` -### Retrieve a schema's properties -Retrieve a previously registered schema's properties from the Azure Schema Registry. +### Service API versions -```java com.azure.data.schemaregistry.schemaregistryclient.getschema -SchemaRegistrySchema schema = client.getSchema("{schema-id}"); +The client library targets the latest service API version by default. +The service client builder accepts an optional service API version parameter to specify which API version to communicate. -System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(), - schema.getProperties().getFormat()); -System.out.println("Schema contents: " + schema.getDefinition()); -``` +#### Select a service API version -### Retrieve a schema -Retrieve a previously registered schema's content and properties from the Azure Schema Registry. - -```java com.azure.data.schemaregistry.schemaregistryclient.getschemaproperties -String schemaContent = "{\n" - + " \"type\" : \"record\", \n" - + " \"namespace\" : \"SampleSchemaNameSpace\", \n" - + " \"name\" : \"Person\", \n" - + " \"fields\" : [\n" - + " { \n" - + " \"name\" : \"FirstName\" , \"type\" : \"string\" \n" - + " }, \n" - + " { \n" - + " \"name\" : \"LastName\", \"type\" : \"string\" \n" - + " }\n" - + " ]\n" - + "}"; -SchemaProperties properties = client.getSchemaProperties("{schema-group}", "{schema-name}", - schemaContent, SchemaFormat.AVRO); - -System.out.println("Schema id: " + properties.getId()); -System.out.println("Format: " + properties.getFormat()); -System.out.println("Version: " + properties.getVersion()); -``` +You have the flexibility to explicitly select a supported service API version when initializing a service client via the service client builder. +This ensures that the client can communicate with services using the specified API version. -## Troubleshooting +When selecting an API version, it is important to verify that there are no breaking changes compared to the latest API version. +If there are significant differences, API calls may fail due to incompatibility. -### Enabling Logging +Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy. -Azure SDKs for Java offer a consistent logging story to help aid in troubleshooting application errors and expedite -their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help -locate the root issue. View the [logging][logging] wiki for guidance about enabling logging. +## Troubleshooting ## Next steps -More samples can be found [here][samples]. ## Contributing -This project welcomes contributions and suggestions. Most contributions require you to agree to a [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights to use your contribution. - -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. +For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md). -This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments. +1. Fork it +1. Create your feature branch (`git checkout -b my-new-feature`) +1. Commit your changes (`git commit -am 'Add some feature'`) +1. Push to the branch (`git push origin my-new-feature`) +1. Create new Pull Request -[package_maven]: https://central.sonatype.com/artifact/com.azure/azure-data-schemaregistry -[sample_readme]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples -[samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry -[source_code]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/src -[samples_code]: src/samples/ +[product_documentation]: https://azure.microsoft.com/services/ +[docs]: https://azure.github.io/azure-sdk-for-java/ +[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/ [azure_subscription]: https://azure.microsoft.com/free/ -[api_reference_doc]: https://azure.github.io/azure-sdk-for-java/ -[azure_cli]: https://docs.microsoft.com/cli/azure -[azure_portal]: https://portal.azure.com -[azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity -[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential -[event_hubs_namespace]: https://learn.microsoft.com/azure/event-hubs/create-schema-registry -[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable -[product_documentation]: https://aka.ms/schemaregistry -[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain -[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal -[aad_grant_access]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal -[schema_properties]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaProperties.java -[logging]: https://github.com/Azure/azure-sdk-for-java/wiki/Logging-in-Azure-SDK -[cla]: https://cla.microsoft.com -[coc]: https://opensource.microsoft.com/codeofconduct/ -[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ -[coc_contact]: mailto:opencode@microsoft.com +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fschemaregistry%2Fazure-data-schemaregistry%2FREADME.png) diff --git a/sdk/schemaregistry/azure-data-schemaregistry/assets.json b/sdk/schemaregistry/azure-data-schemaregistry/assets.json index 1a25c51be077..b12ba2acfc9d 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/assets.json +++ b/sdk/schemaregistry/azure-data-schemaregistry/assets.json @@ -1,6 +1 @@ -{ - "AssetsRepo": "Azure/azure-sdk-assets", - "AssetsRepoPrefixPath": "java", - "TagPrefix": "java/schemaregistry/azure-data-schemaregistry", - "Tag": "java/schemaregistry/azure-data-schemaregistry_1eb85e2a8b" -} +{"AssetsRepo":"Azure/azure-sdk-assets","AssetsRepoPrefixPath":"java","TagPrefix":"java/schemaregistry/azure-data-schemaregistry","Tag":""} \ No newline at end of file diff --git a/sdk/schemaregistry/azure-data-schemaregistry/checkstyle-suppressions.xml b/sdk/schemaregistry/azure-data-schemaregistry/checkstyle-suppressions.xml deleted file mode 100644 index 4e18c6ea8bca..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/checkstyle-suppressions.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/sdk/schemaregistry/azure-data-schemaregistry/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry/pom.xml index 6cf7ec564b24..03e3b3bcef5a 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry/pom.xml @@ -1,12 +1,10 @@ - - + ~ Copyright (c) Microsoft Corporation. All rights reserved. + ~ Licensed under the MIT License. + ~ Code generated by Microsoft (R) TypeSpec Code Generator. + --> + 4.0.0 - com.azure azure-client-sdk-parent @@ -16,42 +14,37 @@ com.azure azure-data-schemaregistry + 1.0.0-beta.1 jar - 1.6.0-beta.1 - Microsoft Azure client library for Schema Registry - This package contains the Microsoft Azure Schema Registry client library + Microsoft Azure SDK for SchemaRegistry + This package contains Microsoft Azure SchemaRegistry client library. https://github.com/Azure/azure-sdk-for-java - - - azure-java-build-docs - ${site.url}/site/${project.artifactId} - - + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + - scm:git:https://github.com/Azure/azure-sdk-for-java + https://github.com/Azure/azure-sdk-for-java scm:git:git@github.com:Azure/azure-sdk-for-java.git + scm:git:git@github.com:Azure/azure-sdk-for-java.git HEAD - + + + microsoft + Microsoft + + - - - --add-opens com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED - --add-opens com.azure.data.schemaregistry/com.azure.data.schemaregistry=ALL-UNNAMED - - --add-exports com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED - --add-exports com.azure.data.schemaregistry/com.azure.data.schemaregistry.implementation.models=ALL-UNNAMED - - **/implementation/**/*.java - - checkstyle-suppressions.xml - false - spotbugs-exclude.xml + UTF-8 + false - com.azure @@ -63,14 +56,6 @@ azure-core-http-netty 1.15.7 - - - - org.apache.avro - avro - 1.11.4 - test - com.azure azure-core-test diff --git a/sdk/schemaregistry/azure-data-schemaregistry/resources/azure-data-schemaregistry-client.properties b/sdk/schemaregistry/azure-data-schemaregistry/resources/azure-data-schemaregistry-client.properties deleted file mode 100644 index ca812989b4f2..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/resources/azure-data-schemaregistry-client.properties +++ /dev/null @@ -1,2 +0,0 @@ -name=${project.artifactId} -version=${project.version} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/spotbugs-exclude.xml b/sdk/schemaregistry/azure-data-schemaregistry/spotbugs-exclude.xml deleted file mode 100644 index f994f09e116f..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/spotbugs-exclude.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java index 57ad8c1e8dc5..f3df1e43f2db 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java @@ -1,527 +1,355 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.data.schemaregistry; +import com.azure.core.annotation.Generated; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; import com.azure.core.exception.ResourceNotFoundException; -import com.azure.core.http.HttpHeaders; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.BinaryData; -import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; -import com.azure.core.util.logging.ClientLogger; -import com.azure.data.schemaregistry.implementation.AzureSchemaRegistryImpl; -import com.azure.data.schemaregistry.implementation.SchemaRegistryHelper; -import com.azure.data.schemaregistry.implementation.models.ErrorException; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.data.schemaregistry.models.SchemaRegistrySchema; +import com.azure.data.schemaregistry.implementation.SchemaRegistryClientImpl; +import java.util.stream.Collectors; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Objects; - -import static com.azure.core.util.FluxUtil.monoError; - /** - * {@link SchemaRegistryAsyncClient} is an HTTP-based client that interacts with Azure Schema Registry service to store - * and retrieve schemas on demand. Azure Schema Registry supports multiple schema formats such as Avro, JSON, and - * custom formats. - * - *

Sample: Construct a {@link SchemaRegistryAsyncClient}

- * - *

The following code sample demonstrates the creation of the asynchronous client {@link SchemaRegistryAsyncClient}. - * The {@code fullyQualifiedNamespace} is the Event Hubs Namespace's host name. It is listed under the "Essentials" - * panel after navigating to the Event Hubs Namespace via Azure Portal. The credential used is - * {@code DefaultAzureCredential} for authentication, which is appropriate for most scenarios, including local - * development and production environments. Additionally, we recommend using - * managed identity - * for authentication in production environments. You can find more information on different ways of authenticating and - * their corresponding credential types in the - * Azure Identity documentation". - *

- * - * - *
- * DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder()
- *     .build();
- * SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder()
- *     .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net")
- *     .credential(azureCredential)
- *     .buildAsyncClient();
- * 
- * - * - *

Sample: Register a schema

- * - *

Registering a schema returns a unique schema id that can be used to quickly associate payloads with that schema. - * The credential used is {@code DefaultAzureCredential} because it combines commonly used credentials in deployment - * and development and chooses the credential to used based on its running environment. Reactive operations must be - * subscribed to; this kicks off the operation. {@link #registerSchema(String, String, String, SchemaFormat)} is a - * non-blocking call, the program will move onto the next line of code after setting up the async operation.

- * - * - *
- * String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}";
- * client.registerSchema("{schema-group}", "{schema-name}", schema, SchemaFormat.AVRO)
- *     .subscribe(properties -> {
- *         System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(),
- *             properties.getFormat());
- *     }, error -> {
- *         System.err.println("Error occurred registering schema: " + error);
- *     }, () -> {
- *         System.out.println("Register schema completed.");
- *     });
- * 
- * - * - *

Sample: Get a schema using a schema id

- * - *

The following code sample demonstrates how to fetch a schema using its schema id. The schema id can be found in - * {@link SchemaProperties#getId()} when a schema is registered or using - * {@link #getSchemaProperties(String, String, String, SchemaFormat)}. Reactive operations must be subscribed to; this - * kicks off the operation. {@link #getSchema(String)} is a non-blocking call, the program will move onto the next line - * of code after setting up the async operation.

- * - * - *
- * client.getSchema("{schema-id}")
- *     .subscribe(schema -> {
- *         System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(),
- *             schema.getProperties().getFormat());
- *         System.out.println("Schema contents: " + schema.getDefinition());
- *     }, error -> {
- *         System.err.println("Error occurred getting schema: " + error);
- *     }, () -> {
- *         System.out.println("Get schema completed.");
- *     });
- * 
- * - * - *

Sample: Get a schema's properties

- * - *

The following code sample demonstrates how to get a schema's properties given its schema contents. Fetching - * schema properties is useful in cases where developers want to get the unique schema id. - * {@link #getSchemaProperties(String, String, String, SchemaFormat)} is a non-blocking call, the program will move - * onto the next line of code after setting up the async operation.

- * - * - *
- * String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}";
- * client.getSchemaProperties("{schema-group}", "{schema-name}", schema, SchemaFormat.AVRO)
- *     .subscribe(properties -> {
- *         System.out.println("Schema id: " + properties.getId());
- *         System.out.println("Format: " + properties.getFormat());
- *         System.out.println("Version: " + properties.getVersion());
- *     }, error -> {
- *         System.err.println("Error occurred getting schema: " + error);
- *     }, () -> {
- *         System.out.println("Get schema completed.");
- *     });
- * 
- * - * - *

Sample: Get a schema with its HTTP response

- * - *

The following code sample demonstrates how to get a schema using its group name, schema name, and version number. - * In addition, it gets the underlying HTTP response that backs this service call. This is useful in cases where - * customers want more insight into the HTTP request/response. -{@link #getSchemaWithResponse(String, String, int, Context)} is a non-blocking call, the program will move onto the - * next line of code after setting up the async operation.

- * - * - *
- * client.getSchemaWithResponse("{group-name}", "{schema-name}", 1)
- *     .subscribe(response -> {
- *         System.out.println("Headers in HTTP response: ");
- *
- *         for (HttpHeader header : response.getHeaders()) {
- *             System.out.printf("%s: %s%n", header.getName(), header.getValue());
- *         }
- *
- *         SchemaRegistrySchema schema = response.getValue();
- *
- *         System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(),
- *             schema.getProperties().getFormat());
- *         System.out.println("Schema contents: " + schema.getDefinition());
- *     }, error -> {
- *         System.err.println("Error occurred getting schema: " + error);
- *     }, () -> {
- *         System.out.println("Get schema with response completed.");
- *     });
- * 
- * - * - * @see SchemaRegistryClientBuilder - * @see SchemaRegistryClient + * Initializes a new instance of the asynchronous SchemaRegistryClient type. */ @ServiceClient(builder = SchemaRegistryClientBuilder.class, isAsync = true) public final class SchemaRegistryAsyncClient { - private final ClientLogger logger = new ClientLogger(SchemaRegistryAsyncClient.class); - private final AzureSchemaRegistryImpl restService; - - SchemaRegistryAsyncClient(AzureSchemaRegistryImpl restService) { - this.restService = restService; - - // So the accessor is initialised because there were NullPointerExceptions before. - new SchemaProperties("", SchemaFormat.AVRO); - } - - /** - * Gets the fully qualified namespace of the Schema Registry instance. - * - * @return The fully qualified namespace of the Schema Registry instance. - */ - public String getFullyQualifiedNamespace() { - return this.restService.getEndpoint(); - } + @Generated + private final SchemaRegistryClientImpl serviceClient; /** - * Registers a new schema in the specified schema group with the given schema name. If a schema: - * - *
    - *
  • does not exist with the same {@code groupName}, {@code name}, {@code format}, and - * {@code schemaDefinition}, it is added to the Schema Registry Instance and assigned a new schema id.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, {@code format}, and {@code schemaDefinition}, - * the id of that existing schema is returned.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, and {@code format} but the {@code schemaDefinition} - * is different, it is considered a new version. A new schema id is assigned to the schema and its schema id is - * returned.
  • - *
- * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * - * @return The {@link SchemaProperties} of a successfully registered schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code format}, or {@code schemaDefinition} - * are null. - * @throws HttpResponseException if an issue was encountered while registering the schema. + * Initializes an instance of SchemaRegistryAsyncClient class. + * + * @param serviceClient the service client implementation. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerSchema(String groupName, String name, String schemaDefinition, - SchemaFormat format) { - return registerSchemaWithResponse(groupName, name, schemaDefinition, format).map(Response::getValue); + @Generated + SchemaRegistryAsyncClient(SchemaRegistryClientImpl serviceClient) { + this.serviceClient = serviceClient; } /** - * Registers a new schema in the specified schema group with the given schema name. If a schema: - * - *
    - *
  • does not exist with the same {@code groupName}, {@code name}, {@code format}, and - * {@code schemaDefinition}, it is added to the Schema Registry Instance and assigned a new schema id.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, {@code format}, and {@code schemaDefinition}, - * the id of that existing schema is returned.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, and {@code format} but the {@code schemaDefinition} - * is different, it is considered a new version. A new schema id is assigned to the schema and its schema id is - * returned.
  • - *
- * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * - * @return The schema properties on successful registration of the schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code format}, or {@code schemaDefinition} - * are null. - * @throws HttpResponseException if an issue was encountered while registering the schema. + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access as paginated response with {@link PagedFlux}. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerSchemaWithResponse(String groupName, String name, - String schemaDefinition, SchemaFormat format) { - return FluxUtil - .withContext(context -> registerSchemaWithResponse(groupName, name, schemaDefinition, format, context)); - } - - Mono> registerSchemaWithResponse(String groupName, String name, String schemaDefinition, - SchemaFormat format, Context context) { - if (Objects.isNull(groupName)) { - return monoError(logger, new NullPointerException("'groupName' should not be null.")); - } else if (Objects.isNull(name)) { - return monoError(logger, new NullPointerException("'name' should not be null.")); - } else if (Objects.isNull(schemaDefinition)) { - return monoError(logger, new NullPointerException("'schemaDefinition' should not be null.")); - } else if (Objects.isNull(format)) { - return monoError(logger, new NullPointerException("'format' should not be null.")); - } - - logger.verbose("Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", - groupName, name, format, schemaDefinition); - - final BinaryData binaryData = BinaryData.fromString(schemaDefinition); - final com.azure.data.schemaregistry.implementation.models.SchemaFormat contentType - = SchemaRegistryHelper.getContentType(format); - - return restService.getSchemas() - .registerWithResponseAsync(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), - context) - .map(response -> { - final SchemaProperties registered = SchemaRegistryHelper - .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); - return new SimpleResponse<>(response, registered); - }); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedFlux listSchemaGroups(RequestOptions requestOptions) { + return this.serviceClient.listSchemaGroupsAsync(requestOptions); } /** - * Gets the schema properties of the schema associated with the unique schema id. - * - * @param schemaId The unique identifier of the schema. - * - * @return The {@link SchemaRegistrySchema} associated with the given {@code schemaId}. - * - * @throws NullPointerException if {@code schemaId} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code schemaId} could not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * List schema versions. + * + * Gets the list of all versions of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support as paginated response with {@link PagedFlux}. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchema(String schemaId) { - return getSchemaWithResponse(schemaId).map(Response::getValue); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedFlux listSchemaVersions(String groupName, String schemaName, RequestOptions requestOptions) { + return this.serviceClient.listSchemaVersionsAsync(groupName, schemaName, requestOptions); } /** - * Gets the schema properties of the schema associated with the group name, schema name, and schema version. - * - * @param groupName Group name for the schema - * @param schemaName Name of the schema - * @param schemaVersion Version of schema - * - * @return The {@link SchemaRegistrySchema} matching the parameters. - * - * @throws NullPointerException if {@code groupName} or {@code schemaName} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code groupName} or {@code schemaName} could - * not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Get a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + * Operation response type is based on serialization of schema requested. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param id Schema ID that uniquely identifies a schema in the registry namespace. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID along with {@link Response} on successful completion of {@link Mono}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchema(String groupName, String schemaName, int schemaVersion) { - return getSchemaWithResponse(groupName, schemaName, schemaVersion).map(Response::getValue); + Mono> getSchemaByIdWithResponse(String id, String accept, RequestOptions requestOptions) { + return this.serviceClient.getSchemaByIdWithResponseAsync(id, accept, requestOptions); } /** - * Gets the schema properties of the schema associated with the unique schema id. - * - * @param schemaId The unique identifier of the schema. - * - * @return The {@link SchemaRegistrySchema} associated with the given {@code schemaId} along with the HTTP response. - * - * @throws NullPointerException if {@code schemaId} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code schemaId} could not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Get specific schema versions. + * + * Gets one specific version of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param schemaVersion Version number of specific schema. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return specific schema versions. + * + * Gets one specific version of one schema along with {@link Response} on successful completion of {@link Mono}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSchemaWithResponse(String schemaId) { - return FluxUtil.withContext(context -> getSchemaWithResponse(schemaId, context)); + Mono> getSchemaByVersionWithResponse(String groupName, String schemaName, int schemaVersion, + String accept, RequestOptions requestOptions) { + return this.serviceClient.getSchemaByVersionWithResponseAsync(groupName, schemaName, schemaVersion, accept, + requestOptions); } /** - * Gets the schema properties of the schema associated with the group name, schema name, and schema version. - * - * @param groupName Group name for the schema - * @param schemaName Name of the schema - * @param schemaVersion Version of schema - * - * @return The {@link SchemaRegistrySchema} matching the parameters. - * - * @throws NullPointerException if {@code groupName} or {@code schemaName} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code groupName} or {@code schemaName} could - * not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Get properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison along with {@link Response} on successful completion of {@link Mono}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSchemaWithResponse(String groupName, String schemaName, - int schemaVersion) { - - return FluxUtil.withContext(context -> getSchemaWithResponse(groupName, schemaName, schemaVersion, context)); - } - - Mono> getSchemaWithResponse(String schemaId, Context context) { - if (Objects.isNull(schemaId)) { - return monoError(logger, new NullPointerException("'schemaId' should not be null.")); - } - - return this.restService.getSchemas() - .getByIdWithResponseAsync(schemaId, context) - .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) - .flatMap(response -> { - SchemaProperties schemaObject = SchemaRegistryHelper - .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); - return convertToString(response.getValue(), response.getHeaders()) - .map(schema -> new SimpleResponse<>(response, new SchemaRegistrySchema(schemaObject, schema))); - }); - } - - Mono> getSchemaWithResponse(String groupName, String schemaName, int schemaVersion, - Context context) { - - if (Objects.isNull(groupName)) { - return monoError(logger, new NullPointerException("'groupName' should not be null.")); - } - - return this.restService.getSchemas() - .getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion, context) - .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) - .flatMap(response -> { - final Flux schemaFlux = response.getValue(); - SchemaProperties schemaObject = SchemaRegistryHelper - .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); - - if (schemaFlux == null) { - return Mono.error(new IllegalArgumentException(String.format( - "Schema definition should not be null. Group Name: %s. Schema Name: %s. Version: %d", groupName, - schemaName, schemaVersion))); - } - return convertToString(schemaFlux, response.getHeaders()) - .map(schema -> new SimpleResponse<>(response.getRequest(), response.getStatusCode(), - response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema))); - }); + Mono> getSchemaPropertiesByContentWithResponse(String groupName, String schemaName, + String contentType, BinaryData schemaContent, RequestOptions requestOptions) { + // Convenience API is not generated, as operation 'getSchemaPropertiesByContent' is multiple content-type + return this.serviceClient.getSchemaPropertiesByContentWithResponseAsync(groupName, schemaName, contentType, + schemaContent, requestOptions); } /** - * Gets the schema identifier associated with the given schema. Gets a cached value if it exists, otherwise makes a - * call to the service. - * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * - * @return A mono that completes with the properties for a matching schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code schemaDefinition}, or {@code format} - * is null. - * @throws ResourceNotFoundException if a schema with matching parameters could not be located. - * @throws HttpResponseException if an issue was encountered while finding a matching schema. + * Register new schema + * + * Register new schema. If schema of specified name does not exist in specified group, schema is created at version + * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchemaProperties(String groupName, String name, String schemaDefinition, - SchemaFormat format) { - - return getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format) - .map(response -> response.getValue()); + Mono> registerSchemaWithResponse(String groupName, String schemaName, String contentType, + BinaryData schemaContent, RequestOptions requestOptions) { + // Convenience API is not generated, as operation 'registerSchema' is multiple content-type + return this.serviceClient.registerSchemaWithResponseAsync(groupName, schemaName, contentType, schemaContent, + requestOptions); } /** - * Gets the schema identifier associated with the given schema. Always makes a call to the service. - * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * - * @return A mono that completes with the properties for a matching schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code schemaDefinition}, or {@code format} - * is null. - * @throws ResourceNotFoundException if a schema with matching parameters could not be located. - * @throws HttpResponseException if an issue was encountered while finding a matching schema. + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access as paginated response with {@link PagedFlux}. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSchemaPropertiesWithResponse(String groupName, String name, - String schemaDefinition, SchemaFormat format) { - - return FluxUtil.withContext( - context -> getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format, context)); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedFlux listSchemaGroups() { + // Generated convenience method for listSchemaGroups + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listSchemaGroups(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(String.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); } /** - * Gets the schema id associated with the schema name a string representation of the schema. - * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * @param context Context to pass along with this request. - * - * @return A mono that completes with the properties for a matching schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code schemaDefinition}, or {@code format} - * is null. - * @throws ResourceNotFoundException if a schema with matching parameters could not be located. - * @throws HttpResponseException if an issue was encountered while finding a matching schema. + * List schema versions. + * + * Gets the list of all versions of one schema. + * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the list of schema versions with server paging support as paginated response with {@link PagedFlux}. */ - Mono> getSchemaPropertiesWithResponse(String groupName, String name, - String schemaDefinition, SchemaFormat format, Context context) { - - if (Objects.isNull(groupName)) { - return monoError(logger, new NullPointerException("'groupName' cannot be null.")); - } else if (Objects.isNull(name)) { - return monoError(logger, new NullPointerException("'name' cannot be null.")); - } else if (Objects.isNull(schemaDefinition)) { - return monoError(logger, new NullPointerException("'schemaDefinition' cannot be null.")); - } else if (Objects.isNull(format)) { - return monoError(logger, new NullPointerException("'format' cannot be null.")); - } - - if (context == null) { - context = Context.NONE; - } - - final BinaryData binaryData = BinaryData.fromString(schemaDefinition); - final com.azure.data.schemaregistry.implementation.models.SchemaFormat contentType - = SchemaRegistryHelper.getContentType(format); - - return restService.getSchemas() - .queryIdByContentWithResponseAsync(groupName, name, contentType, binaryData, binaryData.getLength(), - context) - .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) - .map(response -> { - final SchemaProperties properties = SchemaRegistryHelper - .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); - - return new SimpleResponse<>(response, properties); - }); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedFlux listSchemaVersions(String groupName, String schemaName) { + // Generated convenience method for listSchemaVersions + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listSchemaVersions(groupName, schemaName, requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Integer.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); } /** - * Remaps a generic ErrorException to more specific HTTP exceptions. - * - * @param error Error to map. - * - * @return The remapped error. + * Get a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + * Operation response type is based on serialization of schema requested. + * + * @param id Schema ID that uniquely identifies a schema in the registry namespace. + * @param accept The accept parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID on successful completion of {@link Mono}. */ - static HttpResponseException remapError(ErrorException error) { - if (error.getResponse().getStatusCode() == 404) { - final String message; - if (error.getValue() != null && error.getValue().getError() != null) { - message = error.getValue().getError().getMessage(); - } else { - message = error.getMessage(); - } - return new ResourceNotFoundException(message, error.getResponse(), error); - } - - return error; + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono getSchemaById(String id, String accept) { + // Generated convenience method for getSchemaByIdWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSchemaByIdWithResponse(id, accept, requestOptions).flatMap(FluxUtil::toMono); } /** - * Converts a Flux of Byte Buffer into its string representation. - * - * @param byteBufferFlux the Byte Buffer Flux input. - * @param headers the HTTP headers. - * @return A string representation. + * Get specific schema versions. + * + * Gets one specific version of one schema. + * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param schemaVersion Version number of specific schema. + * @param accept The accept parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return specific schema versions. + * + * Gets one specific version of one schema on successful completion of {@link Mono}. */ - static Mono convertToString(Flux byteBufferFlux, HttpHeaders headers) { - return FluxUtil.collectBytesFromNetworkResponse(byteBufferFlux, headers) - .map(bytes -> new String(bytes, StandardCharsets.UTF_8)); + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono getSchemaByVersion(String groupName, String schemaName, int schemaVersion, String accept) { + // Generated convenience method for getSchemaByVersionWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSchemaByVersionWithResponse(groupName, schemaName, schemaVersion, accept, requestOptions) + .flatMap(FluxUtil::toMono); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java index 4546b398293b..225af32c3fb4 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java @@ -1,463 +1,326 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.data.schemaregistry; +import com.azure.core.annotation.Generated; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.ResponseBase; -import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.BinaryData; -import com.azure.core.util.Context; -import com.azure.core.util.logging.ClientLogger; -import com.azure.data.schemaregistry.implementation.AzureSchemaRegistryImpl; -import com.azure.data.schemaregistry.implementation.SchemaRegistryHelper; -import com.azure.data.schemaregistry.implementation.models.ErrorException; -import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasRegisterHeaders; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.data.schemaregistry.models.SchemaRegistrySchema; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; -import java.util.Objects; +import com.azure.data.schemaregistry.implementation.SchemaRegistryClientImpl; /** - * {@link SchemaRegistryClient} is an HTTP-based client that interacts with Azure Schema Registry service to store and - * retrieve schemas on demand. Azure Schema Registry supports multiple schema formats such as Avro, JSON, and custom - * formats. - * - *

Sample: Construct a {@link SchemaRegistryClient}

- * - *

The following code sample demonstrates the creation of the synchronous client {@link SchemaRegistryClient}. The - * {@code fullyQualifiedNamespace} is the Event Hubs Namespace's host name. It is listed under the "Essentials" panel - * after navigating to the Event Hubs Namespace via Azure Portal. The credential used is {@code DefaultAzureCredential} - * for authentication, which is appropriate for most scenarios, including local development and production environments. - * Additionally, we recommend using - * managed identity - * for authentication in production environments. You can find more information on different ways of authenticating and - * their corresponding credential types in the - * Azure Identity documentation". - *

- * - * - *
- * DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder()
- *     .build();
- * SchemaRegistryClient client = new SchemaRegistryClientBuilder()
- *     .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net")
- *     .credential(azureCredential)
- *     .buildClient();
- * 
- * - * - *

Sample: Register a schema

- * - *

The following code sample demonstrates registering an Avro schema. The {@link SchemaProperties} returned contains - * the schema's id. This id uniquely identifies the schema and can be used to quickly associate payloads with that - * schema.

- * - * - *
- * String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}";
- * SchemaProperties properties = client.registerSchema("{schema-group}", "{schema-name}", schema,
- *     SchemaFormat.AVRO);
- *
- * System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), properties.getFormat());
- * 
- * - * - *

Sample: Getting the schema using a schema id

- * - *

The following code sample demonstrates how to fetch a schema using its schema id. The schema id can be found in - * {@link SchemaProperties#getId()} when a schema is registered or using - * {@link #getSchemaProperties(String, String, String, SchemaFormat)}. - *

- * - * - *
- * SchemaRegistrySchema schema = client.getSchema("{schema-id}");
- *
- * System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(),
- *     schema.getProperties().getFormat());
- * System.out.println("Schema contents: " + schema.getDefinition());
- * 
- * - * - *

Sample: Get a schema's properties

- * - *

The following code sample demonstrates how to get a schema's properties given its schema contents. Fetching - * schema properties is useful in cases where developers want to get the unique schema id.

- * - * - *
- * String schemaContent = "{\n"
- *     + "    \"type\" : \"record\",  \n"
- *     + "    \"namespace\" : \"SampleSchemaNameSpace\", \n"
- *     + "    \"name\" : \"Person\", \n"
- *     + "    \"fields\" : [\n"
- *     + "        { \n"
- *     + "            \"name\" : \"FirstName\" , \"type\" : \"string\" \n"
- *     + "        }, \n"
- *     + "        { \n"
- *     + "            \"name\" : \"LastName\", \"type\" : \"string\" \n"
- *     + "        }\n"
- *     + "    ]\n"
- *     + "}";
- * SchemaProperties properties = client.getSchemaProperties("{schema-group}", "{schema-name}",
- *     schemaContent, SchemaFormat.AVRO);
- *
- * System.out.println("Schema id: " + properties.getId());
- * System.out.println("Format: " + properties.getFormat());
- * System.out.println("Version: " + properties.getVersion());
- * 
- * - * - *

Sample: Get a schema with its HTTP response

- * - *

The following code sample demonstrates how to get a schema using its group name, schema name, and version number. - * In addition, it gets the underlying HTTP response that backs this service call. This is useful in cases where - * customers want more insight into the HTTP request/response.

- * - * - *
- * Response<SchemaRegistrySchema> response = client.getSchemaWithResponse("{group-name}",
- *     "{schema-name}", 1, Context.NONE);
- *
- * System.out.println("Headers in HTTP response: ");
- * response.getHeaders().forEach(header -> System.out.printf("%s: %s%n", header.getName(), header.getValue()));
- *
- * SchemaRegistrySchema schema = response.getValue();
- *
- * System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(),
- *     schema.getProperties().getFormat());
- * System.out.println("Schema contents: " + schema.getDefinition());
- * 
- * - * - * @see SchemaRegistryClientBuilder - * @see SchemaRegistryAsyncClient + * Initializes a new instance of the synchronous SchemaRegistryClient type. */ @ServiceClient(builder = SchemaRegistryClientBuilder.class) public final class SchemaRegistryClient { - private static final String HTTP_REST_PROXY_SYNC_PROXY_ENABLE = "com.azure.core.http.restproxy.syncproxy.enable"; - private final ClientLogger logger = new ClientLogger(SchemaRegistryClient.class); - private final AzureSchemaRegistryImpl restService; - - SchemaRegistryClient(AzureSchemaRegistryImpl restService) { - this.restService = restService; + @Generated + private final SchemaRegistryClientImpl serviceClient; - // So the accessor is initialised because there were NullPointerExceptions before. - new SchemaProperties("", SchemaFormat.AVRO); + /** + * Initializes an instance of SchemaRegistryClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + SchemaRegistryClient(SchemaRegistryClientImpl serviceClient) { + this.serviceClient = serviceClient; } /** - * Gets the fully qualified namespace of the Schema Registry instance. - * - * @return The fully qualified namespace of the Schema Registry instance. + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access as paginated response with {@link PagedIterable}. */ - public String getFullyQualifiedNamespace() { - return this.restService.getEndpoint(); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listSchemaGroups(RequestOptions requestOptions) { + return this.serviceClient.listSchemaGroups(requestOptions); } /** - * Registers a new schema in the specified schema group with the given schema name. If a schema: - * - *
    - *
  • does not exist with the same {@code groupName}, {@code name}, {@code format}, and - * {@code schemaDefinition}, it is added to the Schema Registry Instance and assigned a new schema id.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, {@code format}, and {@code schemaDefinition}, - * the id of that existing schema is returned.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, and {@code format} but the {@code schemaDefinition} - * is different, it is considered a new version. A new schema id is assigned to the schema and its schema id is - * returned.
  • - *
- * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * - * @return The schema properties on successful registration of the schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code format}, or - * {@code schemaDefinition} are null. - * @throws HttpResponseException if an issue was encountered while registering the schema. + * List schema versions. + * + * Gets the list of all versions of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support as paginated response with {@link PagedIterable}. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public SchemaProperties registerSchema(String groupName, String name, String schemaDefinition, - SchemaFormat format) { - return registerSchemaWithResponse(groupName, name, schemaDefinition, format, Context.NONE).getValue(); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listSchemaVersions(String groupName, String schemaName, RequestOptions requestOptions) { + return this.serviceClient.listSchemaVersions(groupName, schemaName, requestOptions); } /** - * Registers a new schema in the specified schema group with the given schema name. If a schema: - * - *
    - *
  • does not exist with the same {@code groupName}, {@code name}, {@code format}, and - * {@code schemaDefinition}, it is added to the Schema Registry Instance and assigned a new schema id.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, {@code format}, and {@code schemaDefinition}, - * the id of that existing schema is returned.
  • - * - *
  • exists with the same {@code groupName}, {@code name}, and {@code format} but the {@code schemaDefinition} - * is different, it is considered a new version. A new schema id is assigned to the schema and its schema id is - * returned.
  • - *
- * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * @param context The context to pass to the HTTP pipeline. - * - * @return The schema properties on successful registration of the schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code format}, or - * {@code schemaDefinition} are null. - * @throws HttpResponseException if an issue was encountered while registering the schema. + * Get a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + * Operation response type is based on serialization of schema requested. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param id Schema ID that uniquely identifies a schema in the registry namespace. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID along with {@link Response}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Response registerSchemaWithResponse(String groupName, String name, String schemaDefinition, - SchemaFormat format, Context context) { - if (Objects.isNull(groupName)) { - throw logger.logExceptionAsError(new NullPointerException("'groupName' should not be null.")); - } else if (Objects.isNull(name)) { - throw logger.logExceptionAsError(new NullPointerException("'name' should not be null.")); - } else if (Objects.isNull(schemaDefinition)) { - throw logger.logExceptionAsError(new NullPointerException("'schemaDefinition' should not be null.")); - } else if (Objects.isNull(format)) { - throw logger.logExceptionAsError(new NullPointerException("'format' should not be null.")); - } - - logger.verbose("Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", - groupName, name, format, schemaDefinition); - - final BinaryData binaryData = BinaryData.fromString(schemaDefinition); - final com.azure.data.schemaregistry.implementation.models.SchemaFormat contentType - = SchemaRegistryHelper.getContentType(format); - - ResponseBase response = restService.getSchemas() - .registerWithResponse(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), context); - final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), - response.getHeaders(), format); - - return new SimpleResponse<>(response, registered); + Response getSchemaByIdWithResponse(String id, String accept, RequestOptions requestOptions) { + return this.serviceClient.getSchemaByIdWithResponse(id, accept, requestOptions); } /** - * Gets the schema properties of the schema associated with the unique schema id. - * - * @param schemaId The unique identifier of the schema. - * - * @return The {@link SchemaRegistrySchema} associated with the given {@code schemaId}. - * - * @throws NullPointerException if {@code schemaId} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code schemaId} could not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Get specific schema versions. + * + * Gets one specific version of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param schemaVersion Version number of specific schema. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return specific schema versions. + * + * Gets one specific version of one schema along with {@link Response}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public SchemaRegistrySchema getSchema(String schemaId) { - return getSchemaWithResponse(schemaId, Context.NONE).getValue(); + Response getSchemaByVersionWithResponse(String groupName, String schemaName, int schemaVersion, + String accept, RequestOptions requestOptions) { + return this.serviceClient.getSchemaByVersionWithResponse(groupName, schemaName, schemaVersion, accept, + requestOptions); } /** - * Gets the schema properties of the schema associated with the group name, schema name, and schema version. - * - * @param groupName Group name for the schema - * @param schemaName Name of the schema - * @param schemaVersion Version of schema - * - * @return The {@link SchemaRegistrySchema} matching the parameters. - * - * @throws NullPointerException if {@code groupName} or {@code schemaName} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code groupName} or {@code schemaName} could - * not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Get properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison along with {@link Response}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public SchemaRegistrySchema getSchema(String groupName, String schemaName, int schemaVersion) { - return getSchemaWithResponse(groupName, schemaName, schemaVersion, Context.NONE).getValue(); + Response getSchemaPropertiesByContentWithResponse(String groupName, String schemaName, String contentType, + BinaryData schemaContent, RequestOptions requestOptions) { + // Convenience API is not generated, as operation 'getSchemaPropertiesByContent' is multiple content-type + return this.serviceClient.getSchemaPropertiesByContentWithResponse(groupName, schemaName, contentType, + schemaContent, requestOptions); } /** - * Gets the schema properties of the schema associated with the unique schema id. - * - * @param schemaId The unique identifier of the schema. - * @param context The context to pass to the Http pipeline. - * - * @return The {@link SchemaRegistrySchema} associated with the given {@code schemaId} and its HTTP response. - * - * @throws NullPointerException if {@code schemaId} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code schemaId} could not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Register new schema + * + * Register new schema. If schema of specified name does not exist in specified group, schema is created at version + * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Response getSchemaWithResponse(String schemaId, Context context) { - if (Objects.isNull(schemaId)) { - throw logger.logExceptionAsError(new NullPointerException("'schemaId' should not be null.")); - } - - try { - ResponseBase response - = this.restService.getSchemas().getByIdWithResponse(schemaId, context); - SchemaProperties schemaObject - = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); - - return new SimpleResponse<>(response, - new SchemaRegistrySchema(schemaObject, convertToString(response.getValue().toStream()))); - } catch (ErrorException ex) { - throw logger.logExceptionAsError(SchemaRegistryAsyncClient.remapError(ex)); - } + Response registerSchemaWithResponse(String groupName, String schemaName, String contentType, + BinaryData schemaContent, RequestOptions requestOptions) { + // Convenience API is not generated, as operation 'registerSchema' is multiple content-type + return this.serviceClient.registerSchemaWithResponse(groupName, schemaName, contentType, schemaContent, + requestOptions); } /** - * Gets the schema properties of the schema associated with the group name, schema name, and schema version. - * - * @param groupName Group name for the schema - * @param schemaName Name of the schema - * @param schemaVersion Version of schema - * @param context The context to pass to the Http pipeline. - * - * @return The {@link SchemaRegistrySchema} matching the parameters. - * - * @throws NullPointerException if {@code groupName} or {@code schemaName} is null. - * @throws ResourceNotFoundException if a schema with the matching {@code groupName} or {@code schemaName} could - * not be found. - * @throws HttpResponseException if an issue was encountered while fetching the schema. - * @throws UncheckedIOException if an error occurred while deserializing response. + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access as paginated response with {@link PagedIterable}. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response getSchemaWithResponse(String groupName, String schemaName, int schemaVersion, - Context context) { - if (Objects.isNull(groupName)) { - throw logger.logExceptionAsError(new NullPointerException("'groupName' should not be null.")); - } - - ResponseBase response - = this.restService.getSchemas().getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, context); - InputStream schemaInputStream = response.getValue().toStream(); - SchemaProperties schemaObject - = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); - - if (schemaInputStream == null) { - throw logger.logExceptionAsError(new IllegalArgumentException( - String.format("Schema definition should not be null. Group Name: %s. Schema Name: %s. Version: %d", - groupName, schemaName, schemaVersion))); - } - - return new SimpleResponse<>(response, - new SchemaRegistrySchema(schemaObject, convertToString(schemaInputStream))); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listSchemaGroups() { + // Generated convenience method for listSchemaGroups + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listSchemaGroups(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(String.class)); } /** - * Gets schema properties for a schema with matching {@code groupName}, {@code name}, {@code schemaDefinition}, and - * {@code format}. - * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * - * @return The properties for a matching schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code schemaDefinition}, or {@code format} is - * null. - * @throws ResourceNotFoundException if a schema with matching parameters could not be located. - * @throws HttpResponseException if an issue was encountered while finding a matching schema. + * List schema versions. + * + * Gets the list of all versions of one schema. + * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the list of schema versions with server paging support as paginated response with {@link PagedIterable}. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public SchemaProperties getSchemaProperties(String groupName, String name, String schemaDefinition, - SchemaFormat format) { - return getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format, Context.NONE).getValue(); + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listSchemaVersions(String groupName, String schemaName) { + // Generated convenience method for listSchemaVersions + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listSchemaVersions(groupName, schemaName, requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Integer.class)); } /** - * Gets schema properties for a schema with matching {@code groupName}, {@code name}, {@code schemaDefinition}, and - * {@code format} along with its HTTP response. - * - * @param groupName The schema group. - * @param name The schema name. - * @param schemaDefinition The string representation of the schema. - * @param format The serialization type of this schema. - * @param context The context to pass to the Http pipeline. - * - * @return A mono that completes with the properties for a matching schema. - * - * @throws NullPointerException if {@code groupName}, {@code name}, {@code schemaDefinition}, or {@code format} is - * null. - * @throws ResourceNotFoundException if a schema with matching parameters could not be located. - * @throws HttpResponseException if an issue was encountered while finding a matching schema. + * Get a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + * Operation response type is based on serialization of schema requested. + * + * @param id Schema ID that uniquely identifies a schema in the registry namespace. + * @param accept The accept parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. */ + @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Response getSchemaPropertiesWithResponse(String groupName, String name, - String schemaDefinition, SchemaFormat format, Context context) { - if (Objects.isNull(groupName)) { - throw logger.logExceptionAsError(new NullPointerException("'groupName' cannot be null.")); - } else if (Objects.isNull(name)) { - throw logger.logExceptionAsError(new NullPointerException("'name' cannot be null.")); - } else if (Objects.isNull(schemaDefinition)) { - throw logger.logExceptionAsError(new NullPointerException("'schemaDefinition' cannot be null.")); - } else if (Objects.isNull(format)) { - throw logger.logExceptionAsError(new NullPointerException("'format' cannot be null.")); - } - - if (context == null) { - context = Context.NONE; - } - - final BinaryData binaryData = BinaryData.fromString(schemaDefinition); - final com.azure.data.schemaregistry.implementation.models.SchemaFormat contentType - = SchemaRegistryHelper.getContentType(format); - - try { - ResponseBase response = restService.getSchemas() - .queryIdByContentWithResponse(groupName, name, contentType, binaryData, binaryData.getLength(), - context); - final SchemaProperties properties = SchemaRegistryHelper - .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); - return new SimpleResponse<>(response, properties); - } catch (ErrorException ex) { - throw logger.logExceptionAsError(SchemaRegistryAsyncClient.remapError(ex)); - } + BinaryData getSchemaById(String id, String accept) { + // Generated convenience method for getSchemaByIdWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSchemaByIdWithResponse(id, accept, requestOptions).getValue(); } /** - * Converts an input stream into its string representation. - * - * @param inputStream Input stream. - * - * @return A string representation. - * - * @throws UncheckedIOException if an {@link IOException} is thrown when creating the readers. + * Get specific schema versions. + * + * Gets one specific version of one schema. + * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param schemaVersion Version number of specific schema. + * @param accept The accept parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return specific schema versions. + * + * Gets one specific version of one schema. */ - static String convertToString(InputStream inputStream) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[4096]; - int read; - try { - while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) { - outputStream.write(buffer, 0, read); - } - - return outputStream.toString(StandardCharsets.UTF_8.name()); - } catch (IOException exception) { - throw new UncheckedIOException("Error occurred while deserializing schemaContent.", exception); - } + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + BinaryData getSchemaByVersion(String groupName, String schemaName, int schemaVersion, String accept) { + // Generated convenience method for getSchemaByVersionWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSchemaByVersionWithResponse(groupName, schemaName, schemaVersion, accept, requestOptions).getValue(); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java index 71ee5fc14922..05146408a52f 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java @@ -1,15 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.data.schemaregistry; +import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.client.traits.ConfigurationTrait; import com.azure.core.client.traits.HttpTrait; import com.azure.core.client.traits.TokenCredentialTrait; import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpHeader; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; @@ -18,7 +19,6 @@ import com.azure.core.http.policy.AddHeadersFromContextPolicy; import com.azure.core.http.policy.AddHeadersPolicy; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; -import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpLoggingPolicy; import com.azure.core.http.policy.HttpPipelinePolicy; @@ -30,432 +30,305 @@ import com.azure.core.util.ClientOptions; import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; -import com.azure.core.util.HttpClientOptions; -import com.azure.core.util.ServiceVersion; import com.azure.core.util.builder.ClientBuilderUtil; import com.azure.core.util.logging.ClientLogger; -import com.azure.core.util.serializer.SerializerAdapter; -import com.azure.data.schemaregistry.implementation.AzureSchemaRegistryImpl; - -import java.net.MalformedURLException; -import java.net.URL; -import java.time.temporal.ChronoUnit; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.data.schemaregistry.implementation.SchemaRegistryClientImpl; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; /** - * Fluent builder for interacting with the Schema Registry service via {@link SchemaRegistryAsyncClient} and - * {@link SchemaRegistryClient}. To build the client, the builder requires the service endpoint of the Schema Registry - * and an Azure AD credential. - * - *

Sample: Construct a sync service client

- * - *

The following code sample demonstrates the creation of the synchronous client {@link SchemaRegistryClient}. The - * credential used is {@code DefaultAzureCredential} because it combines commonly used credentials in deployment and - * development and chooses the credential to used based on its running environment.

- * - * - *
- * DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder()
- *     .build();
- * SchemaRegistryClient client = new SchemaRegistryClientBuilder()
- *     .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net")
- *     .credential(azureCredential)
- *     .buildClient();
- * 
- * - - *

Sample: Construct an async service client

- * - *

The following code sample demonstrates the creation of the asynchronous client {@link SchemaRegistryAsyncClient}. - * The credential used is {@code DefaultAzureCredential} because it combines commonly used credentials in deployment and - * development and chooses the credential to used based on its running environment.

- * - * - *
- * DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder()
- *     .build();
- * SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder()
- *     .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net")
- *     .credential(azureCredential)
- *     .buildAsyncClient();
- * 
- * - * - *

Sample: Instantiating with custom retry policy and HTTP log options

- * - *

The following code sample demonstrates customizing parts of the HTTP pipeline and client behavior such as - * outputting the body of the HTTP request and response or using another retry policy.

- * - * - *
- * DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder()
- *     .build();
- *
- * HttpLogOptions httpLogOptions = new HttpLogOptions()
- *     .setLogLevel(HttpLogDetailLevel.BODY)
- *     .setPrettyPrintBody(true);
- *
- * RetryPolicy retryPolicy = new RetryPolicy(new FixedDelay(5, Duration.ofSeconds(30)));
- * SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder()
- *     .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net")
- *     .httpLogOptions(httpLogOptions)
- *     .retryPolicy(retryPolicy)
- *     .credential(azureCredential)
- *     .buildAsyncClient();
- * 
- * + * A builder for creating a new instance of the SchemaRegistryClient type. */ -@ServiceClientBuilder(serviceClients = { SchemaRegistryAsyncClient.class, SchemaRegistryClient.class }) -public class SchemaRegistryClientBuilder implements ConfigurationTrait, - HttpTrait, TokenCredentialTrait { - private final ClientLogger logger = new ClientLogger(SchemaRegistryClientBuilder.class); - - private static final String DEFAULT_SCOPE = "https://eventhubs.azure.net/.default"; - private static final String CLIENT_PROPERTIES = "azure-data-schemaregistry.properties"; - private static final String CLIENT_NAME; - private static final String CLIENT_VERSION; - private static final RetryPolicy DEFAULT_RETRY_POLICY = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS); - - static { - Map properties = CoreUtils.getProperties(CLIENT_PROPERTIES); - CLIENT_NAME = properties.getOrDefault("name", "UnknownName"); - CLIENT_VERSION = properties.getOrDefault("version", "UnknownVersion"); - } +@ServiceClientBuilder(serviceClients = { SchemaRegistryClient.class, SchemaRegistryAsyncClient.class }) +public final class SchemaRegistryClientBuilder implements HttpTrait, + ConfigurationTrait, TokenCredentialTrait { + @Generated + private static final String SDK_NAME = "name"; - private final List perCallPolicies = new ArrayList<>(); - private final List perRetryPolicies = new ArrayList<>(); + @Generated + private static final String SDK_VERSION = "version"; - private String fullyQualifiedNamespace; - private HttpClient httpClient; - private TokenCredential credential; - private ClientOptions clientOptions; - private HttpLogOptions httpLogOptions; - private HttpPipeline httpPipeline; - private RetryPolicy retryPolicy; - private RetryOptions retryOptions; - private Configuration configuration; - private ServiceVersion serviceVersion; + @Generated + private static final String[] DEFAULT_SCOPES = new String[] { "https://eventhubs.azure.net/.default" }; + + @Generated + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-data-schemaregistry.properties"); + + @Generated + private final List pipelinePolicies; /** - * Constructor for SchemaRegistryClientBuilder. Supplies client defaults. + * Create an instance of the SchemaRegistryClientBuilder. */ + @Generated public SchemaRegistryClientBuilder() { - this.httpLogOptions = new HttpLogOptions(); - this.httpClient = null; - this.credential = null; + this.pipelinePolicies = new ArrayList<>(); } + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + /** - * Sets the fully qualified namespace for the Azure Schema Registry instance. This is likely to be - * similar to {@literal "{your-namespace}.servicebus.windows.net}". - * - * @param fullyQualifiedNamespace The fully qualified namespace of the Azure Schema Registry instance. - * @return The updated {@link SchemaRegistryClientBuilder} object. - * @throws NullPointerException if {@code fullyQualifiedNamespace} is null - * @throws IllegalArgumentException if {@code fullyQualifiedNamespace} cannot be parsed into a valid URL + * {@inheritDoc}. */ - public SchemaRegistryClientBuilder fullyQualifiedNamespace(String fullyQualifiedNamespace) { - Objects.requireNonNull(fullyQualifiedNamespace, "'fullyQualifiedNamespace' cannot be null."); - try { - URL url = new URL(fullyQualifiedNamespace); - this.fullyQualifiedNamespace = url.getHost(); - } catch (MalformedURLException ex) { - logger.verbose("Fully qualified namespace did not contain protocol."); - this.fullyQualifiedNamespace = fullyQualifiedNamespace; + @Generated + @Override + public SchemaRegistryClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); } - + this.pipeline = pipeline; return this; } + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + /** - * Sets the {@link HttpClient} to use for sending and receiving requests to and from the service. - * - *

Note: It is important to understand the precedence order of the HttpTrait APIs. In - * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and - * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally - * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this - * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the - * documentation of types that implement this trait to understand the full set of implications.

- * - * @param httpClient The {@link HttpClient} to use for requests. - * @return The updated {@link SchemaRegistryClientBuilder} object. + * {@inheritDoc}. */ + @Generated @Override public SchemaRegistryClientBuilder httpClient(HttpClient httpClient) { this.httpClient = httpClient; return this; } + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + /** - * Sets the {@link HttpPipeline} to use for the service client. - * - *

Note: It is important to understand the precedence order of the HttpTrait APIs. In - * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and - * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally - * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this - * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the - * documentation of types that implement this trait to understand the full set of implications.

- *

- * If {@code pipeline} is set, all other HTTP settings are ignored to build {@link SchemaRegistryAsyncClient}. - * - * @param httpPipeline {@link HttpPipeline} to use for sending service requests and receiving responses. - * @return The updated {@link SchemaRegistryClientBuilder} object. + * {@inheritDoc}. */ + @Generated @Override - public SchemaRegistryClientBuilder pipeline(HttpPipeline httpPipeline) { - if (this.httpPipeline != null && httpPipeline == null) { - logger.info("HttpPipeline is being set to 'null' when it was previously configured."); - } - - this.httpPipeline = httpPipeline; + public SchemaRegistryClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; return this; } + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + /** - * Sets the configuration store that is used during construction of the service client. - * - * The default configuration store is a clone of the {@link Configuration#getGlobalConfiguration() global - * configuration store}, use {@link Configuration#NONE} to bypass using configuration settings during construction. - * - * @param configuration The configuration store used to - * @return The updated SchemaRegistryClientBuilder object. + * {@inheritDoc}. */ + @Generated @Override - public SchemaRegistryClientBuilder configuration(Configuration configuration) { - this.configuration = configuration; + public SchemaRegistryClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; return this; } + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + /** - * Sets the {@link TokenCredential} used to authorize requests sent to the service. Refer to the Azure SDK for Java - * identity and authentication - * documentation for more details on proper usage of the {@link TokenCredential} type. - * - * @param credential {@link TokenCredential} used to authorize requests sent to the service. - * @return The updated {@link SchemaRegistryClientBuilder} object. - * @throws NullPointerException If {@code credential} is {@code null} + * {@inheritDoc}. */ + @Generated @Override - public SchemaRegistryClientBuilder credential(TokenCredential credential) { - this.credential = Objects.requireNonNull(credential, "'credential' cannot be null."); + public SchemaRegistryClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; return this; } /** - * Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is - * recommended that this method be called with an instance of the {@link HttpClientOptions} - * class (a subclass of the {@link ClientOptions} base class). The HttpClientOptions subclass provides more - * configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait - * interface. - * - *

Note: It is important to understand the precedence order of the HttpTrait APIs. In - * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and - * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally - * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this - * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the - * documentation of types that implement this trait to understand the full set of implications.

- * - * @param clientOptions A configured instance of {@link HttpClientOptions}. - * @return The updated SchemaRegistryClientBuilder object. - * @see HttpClientOptions + * {@inheritDoc}. */ + @Generated @Override - public SchemaRegistryClientBuilder clientOptions(ClientOptions clientOptions) { - this.clientOptions = clientOptions; + public SchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); return this; } + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + /** - * Sets the {@link HttpLogOptions logging configuration} to use when sending and receiving requests to and from - * the service. If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set. - * - *

Note: It is important to understand the precedence order of the HttpTrait APIs. In - * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and - * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally - * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this - * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the - * documentation of types that implement this trait to understand the full set of implications.

- * - * @param logOptions The {@link HttpLogOptions logging configuration} to use when sending and receiving requests to - * and from the service. - * @return The updated {@link SchemaRegistryClientBuilder} object. + * {@inheritDoc}. */ + @Generated @Override - public SchemaRegistryClientBuilder httpLogOptions(HttpLogOptions logOptions) { - this.httpLogOptions = logOptions; + public SchemaRegistryClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; return this; } + /* + * The TokenCredential used for authentication. + */ + @Generated + private TokenCredential tokenCredential; + /** - * Sets the {@link RetryPolicy} that is used when each request is sent. - *

- * The default retry policy will be used if not provided to build {@link SchemaRegistryAsyncClient} . - *

- * Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}. - * - * @param retryPolicy user's retry policy applied to each request. - * @return The updated {@link SchemaRegistryClientBuilder} object. + * {@inheritDoc}. */ - public SchemaRegistryClientBuilder retryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; + @Generated + @Override + public SchemaRegistryClientBuilder credential(TokenCredential tokenCredential) { + this.tokenCredential = tokenCredential; return this; } + /* + * The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'. + */ + @Generated + private String fullyQualifiedNamespace; + /** - * Sets the {@link RetryOptions} for all the requests made through the client. - * - *

Note: It is important to understand the precedence order of the HttpTrait APIs. In - * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and - * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally - * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this - * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the - * documentation of types that implement this trait to understand the full set of implications.

- *

- * Setting this is mutually exclusive with using {@link #retryPolicy(RetryPolicy)}. - * - * @param retryOptions The {@link RetryOptions} to use for all the requests made through the client. - * @return The updated {@link SchemaRegistryClientBuilder} object. + * Sets The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'. + * + * @param fullyQualifiedNamespace the fullyQualifiedNamespace value. + * @return the SchemaRegistryClientBuilder. */ - @Override - public SchemaRegistryClientBuilder retryOptions(RetryOptions retryOptions) { - this.retryOptions = retryOptions; + @Generated + public SchemaRegistryClientBuilder fullyQualifiedNamespace(String fullyQualifiedNamespace) { + this.fullyQualifiedNamespace = fullyQualifiedNamespace; return this; } + /* + * Service version + */ + @Generated + private SchemaRegistryServiceVersion serviceVersion; + /** - * Sets the service version to use. - * - * @param serviceVersion Service version. - * @return The updated instance. + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the SchemaRegistryClientBuilder. */ - public SchemaRegistryClientBuilder serviceVersion(ServiceVersion serviceVersion) { + @Generated + public SchemaRegistryClientBuilder serviceVersion(SchemaRegistryServiceVersion serviceVersion) { this.serviceVersion = serviceVersion; return this; } - /** - * Adds a {@link HttpPipelinePolicy pipeline policy} to apply on each request sent. - * - *

Note: It is important to understand the precedence order of the HttpTrait APIs. In - * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and - * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally - * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this - * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the - * documentation of types that implement this trait to understand the full set of implications.

- * - * @param policy A {@link HttpPipelinePolicy pipeline policy}. - * @return The updated {@link SchemaRegistryClientBuilder} object. - * @throws NullPointerException If {@code policy} is {@code null}. + /* + * The retry policy that will attempt to retry failed requests, if applicable. */ - @Override - public SchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { - Objects.requireNonNull(policy, "'policy' cannot be null."); - - if (policy.getPipelinePosition() == HttpPipelinePosition.PER_CALL) { - perCallPolicies.add(policy); - } else { - perRetryPolicies.add(policy); - } + @Generated + private RetryPolicy retryPolicy; + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the SchemaRegistryClientBuilder. + */ + @Generated + public SchemaRegistryClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; return this; } /** - * Creates a {@link SchemaRegistryAsyncClient} based on options set in the builder. Every time {@code buildClient()} - * is called a new instance of {@link SchemaRegistryAsyncClient} is created. - *

- * If {@link #pipeline(HttpPipeline) pipeline} is set, then all HTTP pipeline related settings are ignored. - * - * @return A {@link SchemaRegistryAsyncClient} with the options set from the builder. - * @throws NullPointerException if {@link #fullyQualifiedNamespace(String) fullyQualifiedNamespace} and - * {@link #credential(TokenCredential) credential} are not set. - * @throws IllegalArgumentException if {@link #fullyQualifiedNamespace(String) fullyQualifiedNamespace} is an empty - * string. - * @throws IllegalStateException If both {@link #retryOptions(RetryOptions)} - * and {@link #retryPolicy(RetryPolicy)} have been set. + * Builds an instance of SchemaRegistryClientImpl with the provided parameters. + * + * @return an instance of SchemaRegistryClientImpl. */ - public SchemaRegistryAsyncClient buildAsyncClient() { - AzureSchemaRegistryImpl restService = getAzureSchemaRegistryImplService(); - - return new SchemaRegistryAsyncClient(restService); + @Generated + private SchemaRegistryClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + SchemaRegistryServiceVersion localServiceVersion + = (serviceVersion != null) ? serviceVersion : SchemaRegistryServiceVersion.getLatest(); + SchemaRegistryClientImpl client = new SchemaRegistryClientImpl(localPipeline, + JacksonAdapter.createDefaultSerializerAdapter(), this.fullyQualifiedNamespace, localServiceVersion); + return client; } - private AzureSchemaRegistryImpl getAzureSchemaRegistryImplService() { - Objects.requireNonNull(credential, - "'credential' cannot be null and must be set via builder.credential(TokenCredential)"); - Objects.requireNonNull(fullyQualifiedNamespace, - "'fullyQualifiedNamespace' cannot be null and must be set via builder.fullyQualifiedNamespace(String)"); - - if (CoreUtils.isNullOrEmpty(fullyQualifiedNamespace)) { - throw logger.logExceptionAsError( - new IllegalArgumentException("'fullyQualifiedNamespace' cannot be an empty string.")); - } + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(fullyQualifiedNamespace, "'fullyQualifiedNamespace' cannot be null."); + } + @Generated + private HttpPipeline createHttpPipeline() { Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; - - HttpPipeline buildPipeline = this.httpPipeline; - // Create a default Pipeline if it is not given - if (buildPipeline == null) { - // Closest to API goes first, closest to wire goes last. - final List policies = new ArrayList<>(); - - policies.add(new UserAgentPolicy(CoreUtils.getApplicationId(clientOptions, httpLogOptions), CLIENT_NAME, - CLIENT_VERSION, buildConfiguration)); - policies.add(new RequestIdPolicy()); - policies.add(new AddHeadersFromContextPolicy()); - - policies.addAll(perCallPolicies); - HttpPolicyProviders.addBeforeRetryPolicies(policies); - - policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, DEFAULT_RETRY_POLICY)); - - policies.add(new AddDatePolicy()); - policies.add(new BearerTokenAuthenticationPolicy(credential, DEFAULT_SCOPE)); - - policies.addAll(perRetryPolicies); - - if (clientOptions != null) { - List clientOptionsHeaders = new ArrayList<>(); - clientOptions.getHeaders() - .forEach(header -> clientOptionsHeaders.add(new HttpHeader(header.getName(), header.getValue()))); - - if (!CoreUtils.isNullOrEmpty(clientOptionsHeaders)) { - policies.add(new AddHeadersPolicy(new HttpHeaders(clientOptionsHeaders))); - } - } - - HttpPolicyProviders.addAfterRetryPolicies(policies); - - policies.add(new HttpLoggingPolicy(httpLogOptions)); - - buildPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient) - .clientOptions(clientOptions) - .build(); + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + if (tokenCredential != null) { + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } - ServiceVersion version = (serviceVersion == null) ? SchemaRegistryVersion.getLatest() : serviceVersion; - SerializerAdapter serializerAdapter = new SchemaRegistryJsonSerializer(); - - return new AzureSchemaRegistryImpl(buildPipeline, serializerAdapter, fullyQualifiedNamespace, - version.getVersion()); + /** + * Builds an instance of SchemaRegistryAsyncClient class. + * + * @return an instance of SchemaRegistryAsyncClient. + */ + @Generated + public SchemaRegistryAsyncClient buildAsyncClient() { + return new SchemaRegistryAsyncClient(buildInnerClient()); } /** - * Creates synchronous {@link SchemaRegistryClient} instance. See async builder method for options validation. - * - * @return {@link SchemaRegistryClient} with the options set from the builder. - * @throws NullPointerException if {@link #fullyQualifiedNamespace(String) endpoint} and {@link #credential(TokenCredential) - * credential} are not set. - * @throws IllegalStateException If both {@link #retryOptions(RetryOptions)} - * and {@link #retryPolicy(RetryPolicy)} have been set. + * Builds an instance of SchemaRegistryClient class. + * + * @return an instance of SchemaRegistryClient. */ + @Generated public SchemaRegistryClient buildClient() { - AzureSchemaRegistryImpl restService = getAzureSchemaRegistryImplService(); - return new SchemaRegistryClient(restService); + return new SchemaRegistryClient(buildInnerClient()); } + + private static final ClientLogger LOGGER = new ClientLogger(SchemaRegistryClientBuilder.class); } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryJsonSerializer.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryJsonSerializer.java deleted file mode 100644 index 2b09280a10dd..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryJsonSerializer.java +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.http.HttpHeaders; -import com.azure.core.util.serializer.CollectionFormat; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; -import com.azure.core.util.serializer.SerializerEncoding; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.List; - -/** - * Package-private serializer for Schema Registry. - * Overrides {@link #serialize(Object, SerializerEncoding)} behaviour because the default serializer tries to serialise - * an already serialised JSON object. - */ -class SchemaRegistryJsonSerializer implements SerializerAdapter { - private final SerializerAdapter adapter = JacksonAdapter.createDefaultSerializerAdapter(); - - /** - * Serializes an object. If {@code encoding} is JSON and the {@code object} is a string, it passed through as-is. - * Otherwise, the object is serialized through the default serializer. The reason is that Schema Registry schemas - * are JSON strings, we don't want to double serialize them, resulting in an incorrect schema. - */ - @Override - public String serialize(Object object, SerializerEncoding encoding) throws IOException { - if (encoding != SerializerEncoding.JSON) { - return adapter.serialize(object, encoding); - } - - if (object instanceof String) { - return (String) object; - } else { - return adapter.serialize(object, encoding); - } - } - - /** - * {@inheritDoc} - */ - @Override - public String serializeRaw(Object object) { - return adapter.serializeRaw(object); - } - - /** - * {@inheritDoc} - */ - @Override - public String serializeList(List list, CollectionFormat format) { - return adapter.serializeList(list, format); - } - - /** - * {@inheritDoc} - */ - @Override - public T deserialize(String value, Type type, SerializerEncoding encoding) throws IOException { - return adapter.deserialize(value, type, encoding); - } - - /** - * {@inheritDoc} - */ - @Override - public T deserialize(HttpHeaders headers, Type type) throws IOException { - return adapter.deserialize(headers, type); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryServiceVersion.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryServiceVersion.java new file mode 100644 index 000000000000..ed092ff9449b --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryServiceVersion.java @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.data.schemaregistry; + +import com.azure.core.util.ServiceVersion; + +/** + * Service version of SchemaRegistryClient. + */ +public enum SchemaRegistryServiceVersion implements ServiceVersion { + /** + * Enum value 2021-10. + */ + V2021_10("2021-10"), + + /** + * Enum value 2022-10. + */ + V2022_10("2022-10"), + + /** + * Enum value 2023-07-01. + */ + V2023_07_01("2023-07-01"); + + private final String version; + + SchemaRegistryServiceVersion(String version) { + this.version = version; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link SchemaRegistryServiceVersion}. + */ + public static SchemaRegistryServiceVersion getLatest() { + return V2023_07_01; + } +} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryVersion.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryVersion.java deleted file mode 100644 index e9cef6939335..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryVersion.java +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.util.ServiceVersion; - -/** - * Schema registry service version. - */ -public enum SchemaRegistryVersion implements ServiceVersion { - /** - * 2021 version. - */ - V2021_10("2021-10"), - - /** - * 2022 version. - */ - V2022_10("2022-10"); - - private final String version; - - SchemaRegistryVersion(String version) { - this.version = version; - } - - @Override - public String getVersion() { - return version; - } - - /** - * Gets the latest version. - * - * @return The latest version. - */ - public static SchemaRegistryVersion getLatest() { - return V2022_10; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImpl.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImpl.java deleted file mode 100644 index 1dbd0cc716ec..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImpl.java +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation; - -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; - -/** - * Initializes a new instance of the AzureSchemaRegistry type. - */ -public final class AzureSchemaRegistryImpl { - /** - * The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. - */ - private final String endpoint; - - /** - * Gets The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. - * - * @return the endpoint value. - */ - public String getEndpoint() { - return this.endpoint; - } - - /** - * Api Version. - */ - private final String apiVersion; - - /** - * Gets Api Version. - * - * @return the apiVersion value. - */ - public String getApiVersion() { - return this.apiVersion; - } - - /** - * The HTTP pipeline to send requests through. - */ - private final HttpPipeline httpPipeline; - - /** - * Gets The HTTP pipeline to send requests through. - * - * @return the httpPipeline value. - */ - public HttpPipeline getHttpPipeline() { - return this.httpPipeline; - } - - /** - * The serializer to serialize an object into a string. - */ - private final SerializerAdapter serializerAdapter; - - /** - * Gets The serializer to serialize an object into a string. - * - * @return the serializerAdapter value. - */ - public SerializerAdapter getSerializerAdapter() { - return this.serializerAdapter; - } - - /** - * The SchemaGroupsOperationsImpl object to access its operations. - */ - private final SchemaGroupsOperationsImpl schemaGroupsOperations; - - /** - * Gets the SchemaGroupsOperationsImpl object to access its operations. - * - * @return the SchemaGroupsOperationsImpl object. - */ - public SchemaGroupsOperationsImpl getSchemaGroupsOperations() { - return this.schemaGroupsOperations; - } - - /** - * The SchemasImpl object to access its operations. - */ - private final SchemasImpl schemas; - - /** - * Gets the SchemasImpl object to access its operations. - * - * @return the SchemasImpl object. - */ - public SchemasImpl getSchemas() { - return this.schemas; - } - - /** - * Initializes an instance of AzureSchemaRegistry client. - * - * @param endpoint The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. - * @param apiVersion Api Version. - */ - public AzureSchemaRegistryImpl(String endpoint, String apiVersion) { - this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), - JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); - } - - /** - * Initializes an instance of AzureSchemaRegistry client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param endpoint The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. - * @param apiVersion Api Version. - */ - public AzureSchemaRegistryImpl(HttpPipeline httpPipeline, String endpoint, String apiVersion) { - this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); - } - - /** - * Initializes an instance of AzureSchemaRegistry client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param serializerAdapter The serializer to serialize an object into a string. - * @param endpoint The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net. - * @param apiVersion Api Version. - */ - public AzureSchemaRegistryImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, - String apiVersion) { - this.httpPipeline = httpPipeline; - this.serializerAdapter = serializerAdapter; - this.endpoint = endpoint; - this.apiVersion = apiVersion; - this.schemaGroupsOperations = new SchemaGroupsOperationsImpl(this); - this.schemas = new SchemasImpl(this); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaGroupsOperationsImpl.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaGroupsOperationsImpl.java deleted file mode 100644 index 08caac215bf3..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaGroupsOperationsImpl.java +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation; - -import com.azure.core.annotation.ExpectedResponses; -import com.azure.core.annotation.Get; -import com.azure.core.annotation.HeaderParam; -import com.azure.core.annotation.Host; -import com.azure.core.annotation.HostParam; -import com.azure.core.annotation.PathParam; -import com.azure.core.annotation.QueryParam; -import com.azure.core.annotation.ReturnType; -import com.azure.core.annotation.ServiceInterface; -import com.azure.core.annotation.ServiceMethod; -import com.azure.core.annotation.UnexpectedResponseExceptionType; -import com.azure.core.http.rest.PagedFlux; -import com.azure.core.http.rest.PagedIterable; -import com.azure.core.http.rest.PagedResponse; -import com.azure.core.http.rest.PagedResponseBase; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.RestProxy; -import com.azure.core.util.Context; -import com.azure.core.util.FluxUtil; -import com.azure.data.schemaregistry.implementation.models.ErrorException; -import com.azure.data.schemaregistry.implementation.models.SchemaGroups; -import reactor.core.publisher.Mono; - -/** - * An instance of this class provides access to all the operations defined in SchemaGroupsOperations. - */ -public final class SchemaGroupsOperationsImpl { - /** - * The proxy service used to perform REST calls. - */ - private final SchemaGroupsService service; - - /** - * The service client containing this operation class. - */ - private final AzureSchemaRegistryImpl client; - - /** - * Initializes an instance of SchemaGroupsOperationsImpl. - * - * @param client the instance of the service client containing this operation class. - */ - SchemaGroupsOperationsImpl(AzureSchemaRegistryImpl client) { - this.service - = RestProxy.create(SchemaGroupsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); - this.client = client; - } - - /** - * The interface defining all the services for AzureSchemaRegistrySchemaGroupsOperations to be used by the proxy - * service to perform REST calls. - */ - @Host("https://{endpoint}") - @ServiceInterface(name = "AzureSchemaRegistryS") - public interface SchemaGroupsService { - @Get("/$schemaGroups") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> list(@HostParam("endpoint") String endpoint, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Get("/$schemaGroups") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Response listSync(@HostParam("endpoint") String endpoint, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Get("{nextLink}") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> listNext(@PathParam(value = "nextLink", encoded = true) String nextLink, - @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context); - - @Get("{nextLink}") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Response listNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, - @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access along with {@link PagedResponse} on successful - * completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listSinglePageAsync() { - final String accept = "application/json"; - return FluxUtil - .withContext( - context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context)) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null)); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access along with {@link PagedResponse} on successful - * completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listSinglePageAsync(Context context) { - final String accept = "application/json"; - return service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null)); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access as paginated response with {@link PagedFlux}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listAsync() { - return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink)); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access as paginated response with {@link PagedFlux}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listAsync(Context context) { - return new PagedFlux<>(() -> listSinglePageAsync(context), - nextLink -> listNextSinglePageAsync(nextLink, context)); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access along with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse listSinglePage() { - final String accept = "application/json"; - Response res - = service.listSync(this.client.getEndpoint(), this.client.getApiVersion(), accept, Context.NONE); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access along with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse listSinglePage(Context context) { - final String accept = "application/json"; - Response res - = service.listSync(this.client.getEndpoint(), this.client.getApiVersion(), accept, context); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access as paginated response with {@link PagedIterable}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable list() { - return new PagedIterable<>(() -> listSinglePage(Context.NONE), nextLink -> listNextSinglePage(nextLink)); - } - - /** - * Get list of schema groups. - * - * Gets the list of schema groups user is authorized to access. - * - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of schema groups user is authorized to access as paginated response with {@link PagedIterable}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable list(Context context) { - return new PagedIterable<>(() -> listSinglePage(context), nextLink -> listNextSinglePage(nextLink, context)); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema groups and link to next batch page along - * with {@link PagedResponse} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listNextSinglePageAsync(String nextLink) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context)) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null)); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema groups and link to next batch page along - * with {@link PagedResponse} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listNextSinglePageAsync(String nextLink, Context context) { - final String accept = "application/json"; - return service.listNext(nextLink, this.client.getEndpoint(), accept, context) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null)); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema groups and link to next batch page along - * with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse listNextSinglePage(String nextLink) { - final String accept = "application/json"; - Response res = service.listNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema groups and link to next batch page along - * with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse listNextSinglePage(String nextLink, Context context) { - final String accept = "application/json"; - Response res = service.listNextSync(nextLink, this.client.getEndpoint(), accept, context); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getGroups(), res.getValue().getNextLink(), null); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryClientImpl.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryClientImpl.java new file mode 100644 index 000000000000..2d6491067750 --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryClientImpl.java @@ -0,0 +1,999 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.data.schemaregistry.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.data.schemaregistry.SchemaRegistryServiceVersion; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the SchemaRegistryClient type. + */ +public final class SchemaRegistryClientImpl { + /** + * The proxy service used to perform REST calls. + */ + private final SchemaRegistryClientService service; + + /** + * The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'. + */ + private final String fullyQualifiedNamespace; + + /** + * Gets The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'. + * + * @return the fullyQualifiedNamespace value. + */ + public String getFullyQualifiedNamespace() { + return this.fullyQualifiedNamespace; + } + + /** + * Service version. + */ + private final SchemaRegistryServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public SchemaRegistryServiceVersion getServiceVersion() { + return this.serviceVersion; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * Initializes an instance of SchemaRegistryClient client. + * + * @param fullyQualifiedNamespace The Schema Registry service endpoint, for example + * 'my-namespace.servicebus.windows.net'. + * @param serviceVersion Service version. + */ + public SchemaRegistryClientImpl(String fullyQualifiedNamespace, SchemaRegistryServiceVersion serviceVersion) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), fullyQualifiedNamespace, serviceVersion); + } + + /** + * Initializes an instance of SchemaRegistryClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param fullyQualifiedNamespace The Schema Registry service endpoint, for example + * 'my-namespace.servicebus.windows.net'. + * @param serviceVersion Service version. + */ + public SchemaRegistryClientImpl(HttpPipeline httpPipeline, String fullyQualifiedNamespace, + SchemaRegistryServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), fullyQualifiedNamespace, serviceVersion); + } + + /** + * Initializes an instance of SchemaRegistryClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param fullyQualifiedNamespace The Schema Registry service endpoint, for example + * 'my-namespace.servicebus.windows.net'. + * @param serviceVersion Service version. + */ + public SchemaRegistryClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, + String fullyQualifiedNamespace, SchemaRegistryServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.fullyQualifiedNamespace = fullyQualifiedNamespace; + this.serviceVersion = serviceVersion; + this.service + = RestProxy.create(SchemaRegistryClientService.class, this.httpPipeline, this.getSerializerAdapter()); + } + + /** + * The interface defining all the services for SchemaRegistryClient to be used by the proxy service to perform REST + * calls. + */ + @Host("https://{fullyQualifiedNamespace}") + @ServiceInterface(name = "SchemaRegistryClient") + public interface SchemaRegistryClientService { + @Get("/$schemaGroups") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listSchemaGroups( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listSchemaGroupsSync(@HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listSchemaVersions( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listSchemaVersionsSync( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups/$schemas/{id}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSchemaById(@HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups/$schemas/{id}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getSchemaByIdSync(@HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions/{schemaVersion}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSchemaByVersion( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @PathParam("schemaVersion") int schemaVersion, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions/{schemaVersion}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getSchemaByVersionSync( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @PathParam("schemaVersion") int schemaVersion, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSchemaPropertiesByContent( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData schemaContent, + RequestOptions requestOptions, Context context); + + @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getSchemaPropertiesByContentSync( + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData schemaContent, + RequestOptions requestOptions, Context context); + + @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> registerSchema(@HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData schemaContent, + RequestOptions requestOptions, Context context); + + @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response registerSchemaSync(@HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, + @QueryParam("api-version") String apiVersion, @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData schemaContent, + RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listSchemaGroupsNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listSchemaGroupsNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listSchemaVersionsNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listSchemaVersionsNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("fullyQualifiedNamespace") String fullyQualifiedNamespace, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + } + + /** + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSchemaGroupsSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listSchemaGroups(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null)); + } + + /** + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listSchemaGroupsAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> listSchemaGroupsSinglePageAsync(requestOptions), + nextLink -> listSchemaGroupsNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSchemaGroupsSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.listSchemaGroupsSync(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null); + } + + /** + * Get list of schema groups. + * + * Gets the list of schema groups user is authorized to access. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return list of schema groups. + * + * Gets the list of schema groups user is authorized to access as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listSchemaGroups(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> listSchemaGroupsSinglePage(requestOptions), + nextLink -> listSchemaGroupsNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * List schema versions. + * + * Gets the list of all versions of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSchemaVersionsSinglePageAsync(String groupName, String schemaName, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listSchemaVersions(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), groupName, schemaName, accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null)); + } + + /** + * List schema versions. + * + * Gets the list of all versions of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listSchemaVersionsAsync(String groupName, String schemaName, + RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> listSchemaVersionsSinglePageAsync(groupName, schemaName, requestOptions), + nextLink -> listSchemaVersionsNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * List schema versions. + * + * Gets the list of all versions of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSchemaVersionsSinglePage(String groupName, String schemaName, + RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.listSchemaVersionsSync(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), groupName, schemaName, accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null); + } + + /** + * List schema versions. + * + * Gets the list of all versions of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listSchemaVersions(String groupName, String schemaName, + RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> listSchemaVersionsSinglePage(groupName, schemaName, requestOptions), + nextLink -> listSchemaVersionsNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Get a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + * Operation response type is based on serialization of schema requested. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param id Schema ID that uniquely identifies a schema in the registry namespace. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSchemaByIdWithResponseAsync(String id, String accept, + RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.getSchemaById(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), id, accept, requestOptions, context)); + } + + /** + * Get a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. + * Operation response type is based on serialization of schema requested. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param id Schema ID that uniquely identifies a schema in the registry namespace. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a registered schema by its unique ID reference. + * + * Gets a registered schema by its unique ID along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSchemaByIdWithResponse(String id, String accept, RequestOptions requestOptions) { + return service.getSchemaByIdSync(this.getFullyQualifiedNamespace(), this.getServiceVersion().getVersion(), id, + accept, requestOptions, Context.NONE); + } + + /** + * Get specific schema versions. + * + * Gets one specific version of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param schemaVersion Version number of specific schema. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return specific schema versions. + * + * Gets one specific version of one schema along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSchemaByVersionWithResponseAsync(String groupName, String schemaName, + int schemaVersion, String accept, RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.getSchemaByVersion(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), groupName, schemaName, schemaVersion, accept, requestOptions, + context)); + } + + /** + * Get specific schema versions. + * + * Gets one specific version of one schema. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param schemaVersion Version number of specific schema. + * @param accept The accept parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return specific schema versions. + * + * Gets one specific version of one schema along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSchemaByVersionWithResponse(String groupName, String schemaName, int schemaVersion, + String accept, RequestOptions requestOptions) { + return service.getSchemaByVersionSync(this.getFullyQualifiedNamespace(), this.getServiceVersion().getVersion(), + groupName, schemaName, schemaVersion, accept, requestOptions, Context.NONE); + } + + /** + * Get properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSchemaPropertiesByContentWithResponseAsync(String groupName, String schemaName, + String contentType, BinaryData schemaContent, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.getSchemaPropertiesByContent(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), groupName, schemaName, contentType, accept, schemaContent, + requestOptions, context)); + } + + /** + * Get properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return properties for existing schema. + * + * Gets the properties referencing an existing schema within the specified schema group, as matched by schema + * content comparison along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSchemaPropertiesByContentWithResponse(String groupName, String schemaName, + String contentType, BinaryData schemaContent, RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getSchemaPropertiesByContentSync(this.getFullyQualifiedNamespace(), + this.getServiceVersion().getVersion(), groupName, schemaName, contentType, accept, schemaContent, + requestOptions, Context.NONE); + } + + /** + * Register new schema + * + * Register new schema. If schema of specified name does not exist in specified group, schema is created at version + * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> registerSchemaWithResponseAsync(String groupName, String schemaName, String contentType, + BinaryData schemaContent, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.registerSchema(this.getFullyQualifiedNamespace(), this.getServiceVersion().getVersion(), + groupName, schemaName, contentType, accept, schemaContent, requestOptions, context)); + } + + /** + * Register new schema + * + * Register new schema. If schema of specified name does not exist in specified group, schema is created at version + * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param groupName Name of schema group. + * @param schemaName Name of schema. + * @param contentType The content type for given schema. Allowed values: "application/json; serialization=Avro", + * "application/json; serialization=Json", "text/plain; charset=utf-8", "text/vnd.ms.protobuf". + * @param schemaContent String representation (UTF-8) of the schema. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response registerSchemaWithResponse(String groupName, String schemaName, String contentType, + BinaryData schemaContent, RequestOptions requestOptions) { + final String accept = "application/json"; + return service.registerSchemaSync(this.getFullyQualifiedNamespace(), this.getServiceVersion().getVersion(), + groupName, schemaName, contentType, accept, schemaContent, requestOptions, Context.NONE); + } + + /** + * Get list of schema groups. + * + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema group names with server paging support along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSchemaGroupsNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listSchemaGroupsNext(nextLink, this.getFullyQualifiedNamespace(), accept, + requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null)); + } + + /** + * Get list of schema groups. + * + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * String
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema group names with server paging support along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSchemaGroupsNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.listSchemaGroupsNextSync(nextLink, this.getFullyQualifiedNamespace(), accept, + requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null); + } + + /** + * List schema versions. + * + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSchemaVersionsNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listSchemaVersionsNext(nextLink, this.getFullyQualifiedNamespace(), accept, + requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null)); + } + + /** + * List schema versions. + * + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * int
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the list of schema versions with server paging support along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSchemaVersionsNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.listSchemaVersionsNextSync(nextLink, this.getFullyQualifiedNamespace(), + accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Value"), getNextLink(res.getValue(), "NextLink"), null); + } + + private List getValues(BinaryData binaryData, String path) { + try { + Map obj = binaryData.toObject(Map.class); + List values = (List) obj.get(path); + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String path) { + try { + Map obj = binaryData.toObject(Map.class); + return (String) obj.get(path); + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java deleted file mode 100644 index 7917f23d159d..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.data.schemaregistry.implementation; - -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasRegisterHeaders; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Objects; -import java.util.regex.Pattern; - -/** - * Helper to access private-package methods of models. - */ -public final class SchemaRegistryHelper { - private static final HashMap SCHEMA_FORMAT_HASH_MAP - = new HashMap<>(); - private static final Pattern SCHEMA_FORMAT_PATTERN = Pattern.compile("\\s"); - - private static SchemaRegistryModelsAccessor accessor; - - static { - com.azure.data.schemaregistry.implementation.models.SchemaFormat.values().forEach(value -> { - final String mimeTypeLower - = SCHEMA_FORMAT_PATTERN.matcher(value.toString()).replaceAll("").toLowerCase(Locale.ROOT); - - SCHEMA_FORMAT_HASH_MAP.put(mimeTypeLower, value); - }); - } - - /** - * Accessor interface. - */ - public interface SchemaRegistryModelsAccessor { - SchemaProperties getSchemaProperties(String id, SchemaFormat format, String groupName, String name, - int version); - } - - /** - * Sets the accessor - * - * @param modelsAccessor The accessor. - */ - public static void setAccessor(SchemaRegistryModelsAccessor modelsAccessor) { - accessor = Objects.requireNonNull(modelsAccessor, "'modelsAccessor' cannot be null."); - } - - public static SchemaProperties getSchemaProperties(SchemasRegisterHeaders deserializedHeaders, - HttpHeaders httpHeaders, SchemaFormat fallbackFormat) { - final SchemaFormat responseFormat = getSchemaFormat(httpHeaders); - final SchemaFormat schemaFormat = responseFormat != null ? responseFormat : fallbackFormat; - - return accessor.getSchemaProperties(deserializedHeaders.getSchemaId(), schemaFormat, - deserializedHeaders.getSchemaGroupName(), deserializedHeaders.getSchemaName(), - deserializedHeaders.getSchemaVersion()); - } - - public static SchemaProperties getSchemaProperties(SchemasQueryIdByContentHeaders deserializedHeaders, - HttpHeaders httpHeaders, SchemaFormat format) { - final SchemaFormat responseFormat = getSchemaFormat(httpHeaders); - final SchemaFormat schemaFormat = responseFormat != null ? responseFormat : format; - return accessor.getSchemaProperties(deserializedHeaders.getSchemaId(), schemaFormat, - deserializedHeaders.getSchemaGroupName(), deserializedHeaders.getSchemaName(), - deserializedHeaders.getSchemaVersion()); - } - - public static SchemaProperties getSchemaProperties(SchemasGetByIdHeaders deserializedHeaders, - HttpHeaders httpHeaders) { - final SchemaFormat schemaFormat = getSchemaFormat(httpHeaders); - return accessor.getSchemaProperties(deserializedHeaders.getSchemaId(), schemaFormat, - deserializedHeaders.getSchemaGroupName(), deserializedHeaders.getSchemaName(), - deserializedHeaders.getSchemaVersion()); - } - - public static SchemaProperties getSchemaProperties(SchemasGetSchemaVersionHeaders deserializedHeaders, - HttpHeaders httpHeaders) { - final SchemaFormat schemaFormat = getSchemaFormat(httpHeaders); - - return accessor.getSchemaProperties(deserializedHeaders.getSchemaId(), schemaFormat, - deserializedHeaders.getSchemaGroupName(), deserializedHeaders.getSchemaName(), - deserializedHeaders.getSchemaVersion()); - } - - public static com.azure.data.schemaregistry.implementation.models.SchemaFormat - getContentType(SchemaFormat schemaFormat) { - Objects.requireNonNull(schemaFormat, "'schemaFormat' cannot be null.'"); - - if (schemaFormat == SchemaFormat.AVRO) { - return com.azure.data.schemaregistry.implementation.models.SchemaFormat.APPLICATION_JSON_SERIALIZATION_AVRO; - } else if (schemaFormat == SchemaFormat.JSON) { - return com.azure.data.schemaregistry.implementation.models.SchemaFormat.APPLICATION_JSON_SERIALIZATION_JSON; - } else { - return com.azure.data.schemaregistry.implementation.models.SchemaFormat.TEXT_PLAIN_CHARSET_UTF8; - } - } - - /** - * Extracts "Content-Type" from HttpHeaders and translates it into {@link SchemaFormat}. - * - * @param headers Headers to read. - * @return The corresponding {@link SchemaFormat} or {@code null} if the header does not exist. - */ - public static SchemaFormat getSchemaFormat(HttpHeaders headers) { - final String contentType = headers.getValue(HttpHeaderName.CONTENT_TYPE); - - if (contentType == null) { - return null; - } - - final String replaced = SCHEMA_FORMAT_PATTERN.matcher(contentType).replaceAll("").toLowerCase(Locale.ROOT); - - // Default value if nothing matches is CUSTOM. - final com.azure.data.schemaregistry.implementation.models.SchemaFormat implementationFormat - = SCHEMA_FORMAT_HASH_MAP.getOrDefault(replaced, - com.azure.data.schemaregistry.implementation.models.SchemaFormat.TEXT_PLAIN_CHARSET_UTF8); - - if (com.azure.data.schemaregistry.implementation.models.SchemaFormat.APPLICATION_JSON_SERIALIZATION_AVRO - .equals(implementationFormat)) { - return SchemaFormat.AVRO; - } else if (com.azure.data.schemaregistry.implementation.models.SchemaFormat.APPLICATION_JSON_SERIALIZATION_JSON - .equals(implementationFormat)) { - return SchemaFormat.JSON; - } else { - return SchemaFormat.CUSTOM; - } - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemasImpl.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemasImpl.java deleted file mode 100644 index 56e4c346f580..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemasImpl.java +++ /dev/null @@ -1,1197 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation; - -import com.azure.core.annotation.BodyParam; -import com.azure.core.annotation.ExpectedResponses; -import com.azure.core.annotation.Get; -import com.azure.core.annotation.HeaderParam; -import com.azure.core.annotation.Host; -import com.azure.core.annotation.HostParam; -import com.azure.core.annotation.PathParam; -import com.azure.core.annotation.Post; -import com.azure.core.annotation.Put; -import com.azure.core.annotation.QueryParam; -import com.azure.core.annotation.ReturnType; -import com.azure.core.annotation.ServiceInterface; -import com.azure.core.annotation.ServiceMethod; -import com.azure.core.annotation.UnexpectedResponseExceptionType; -import com.azure.core.http.rest.PagedFlux; -import com.azure.core.http.rest.PagedIterable; -import com.azure.core.http.rest.PagedResponse; -import com.azure.core.http.rest.PagedResponseBase; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.ResponseBase; -import com.azure.core.http.rest.RestProxy; -import com.azure.core.util.BinaryData; -import com.azure.core.util.Context; -import com.azure.core.util.FluxUtil; -import com.azure.data.schemaregistry.implementation.models.ErrorException; -import com.azure.data.schemaregistry.implementation.models.SchemaFormat; -import com.azure.data.schemaregistry.implementation.models.SchemaVersions; -import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasRegisterHeaders; -import java.nio.ByteBuffer; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -/** - * An instance of this class provides access to all the operations defined in Schemas. - */ -public final class SchemasImpl { - /** - * The proxy service used to perform REST calls. - */ - private final SchemasService service; - - /** - * The service client containing this operation class. - */ - private final AzureSchemaRegistryImpl client; - - /** - * Initializes an instance of SchemasImpl. - * - * @param client the instance of the service client containing this operation class. - */ - SchemasImpl(AzureSchemaRegistryImpl client) { - this.service = RestProxy.create(SchemasService.class, client.getHttpPipeline(), client.getSerializerAdapter()); - this.client = client; - } - - /** - * The interface defining all the services for AzureSchemaRegistrySchemas to be used by the proxy service to - * perform REST calls. - */ - @Host("https://{endpoint}") - @ServiceInterface(name = "AzureSchemaRegistryS") - public interface SchemasService { - @Get("/$schemaGroups/$schemas/{id}") - @ExpectedResponses({ 200, 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono>> getById(@HostParam("endpoint") String endpoint, - @PathParam("id") String id, @QueryParam("api-version") String apiVersion, - @HeaderParam("Accept") String accept, Context context); - - @Get("/$schemaGroups/$schemas/{id}") - @ExpectedResponses({ 200, 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - ResponseBase getByIdSync(@HostParam("endpoint") String endpoint, - @PathParam("id") String id, @QueryParam("api-version") String apiVersion, - @HeaderParam("Accept") String accept, Context context); - - @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> getVersions(@HostParam("endpoint") String endpoint, - @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Response getVersionsSync(@HostParam("endpoint") String endpoint, - @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions/{schemaVersion}") - @ExpectedResponses({ 200, 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono>> getSchemaVersion( - @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, - @PathParam("schemaName") String schemaName, @PathParam("schemaVersion") int schemaVersion, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Get("/$schemaGroups/{groupName}/schemas/{schemaName}/versions/{schemaVersion}") - @ExpectedResponses({ 200, 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - ResponseBase getSchemaVersionSync( - @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, - @PathParam("schemaName") String schemaName, @PathParam("schemaVersion") int schemaVersion, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> queryIdByContent( - @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, - @PathParam("schemaName") String schemaName, @QueryParam("api-version") String apiVersion, - @HeaderParam("Content-Type") SchemaFormat contentType, - @BodyParam("application/octet-stream") Flux schemaContent, - @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, Context context); - - @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> queryIdByContent( - @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, - @PathParam("schemaName") String schemaName, @QueryParam("api-version") String apiVersion, - @HeaderParam("Content-Type") SchemaFormat contentType, - @BodyParam("application/octet-stream") BinaryData schemaContent, - @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, Context context); - - @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(ErrorException.class) - ResponseBase queryIdByContentSync(@HostParam("endpoint") String endpoint, - @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, - @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") SchemaFormat contentType, - @BodyParam("application/octet-stream") BinaryData schemaContent, - @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, Context context); - - @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> register(@HostParam("endpoint") String endpoint, - @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, - @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, - @BodyParam("application/octet-stream") Flux schemaContent, - @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, Context context); - - @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> register(@HostParam("endpoint") String endpoint, - @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, - @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, - @BodyParam("application/octet-stream") BinaryData schemaContent, - @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, Context context); - - @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(ErrorException.class) - ResponseBase registerSync(@HostParam("endpoint") String endpoint, - @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, - @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, - @BodyParam("application/octet-stream") BinaryData schemaContent, - @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, Context context); - - @Get("{nextLink}") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Mono> getVersionsNext(@PathParam(value = "nextLink", encoded = true) String nextLink, - @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context); - - @Get("{nextLink}") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorException.class) - Response getVersionsNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, - @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context); - } - - /** - * Get a registered schema by its unique ID reference. - * - * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. - * Operation response type is based on serialization of schema requested. - * - * @param id References specific schema in registry namespace. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a registered schema by its unique ID along with {@link ResponseBase} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> getByIdWithResponseAsync(String id) { - final String accept - = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8, text/vnd.ms.protobuf"; - return FluxUtil.withContext( - context -> service.getById(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context)); - } - - /** - * Get a registered schema by its unique ID reference. - * - * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. - * Operation response type is based on serialization of schema requested. - * - * @param id References specific schema in registry namespace. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a registered schema by its unique ID along with {@link ResponseBase} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> getByIdWithResponseAsync(String id, - Context context) { - final String accept - = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8, text/vnd.ms.protobuf"; - return service.getById(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context); - } - - /** - * Get a registered schema by its unique ID reference. - * - * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. - * Operation response type is based on serialization of schema requested. - * - * @param id References specific schema in registry namespace. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a registered schema by its unique ID on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getByIdAsync(String id) { - return getByIdWithResponseAsync(id).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Get a registered schema by its unique ID reference. - * - * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. - * Operation response type is based on serialization of schema requested. - * - * @param id References specific schema in registry namespace. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a registered schema by its unique ID on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getByIdAsync(String id, Context context) { - return getByIdWithResponseAsync(id, context).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Get a registered schema by its unique ID reference. - * - * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. - * Operation response type is based on serialization of schema requested. - * - * @param id References specific schema in registry namespace. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a registered schema by its unique ID along with {@link ResponseBase}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public ResponseBase getByIdWithResponse(String id, Context context) { - final String accept - = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8, text/vnd.ms.protobuf"; - return service.getByIdSync(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context); - } - - /** - * Get a registered schema by its unique ID reference. - * - * Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. - * Operation response type is based on serialization of schema requested. - * - * @param id References specific schema in registry namespace. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a registered schema by its unique ID. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public BinaryData getById(String id) { - return getByIdWithResponse(id, Context.NONE).getValue(); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema along with {@link PagedResponse} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getVersionsSinglePageAsync(String groupName, String schemaName) { - final String accept = "application/json"; - return FluxUtil - .withContext(context -> service.getVersions(this.client.getEndpoint(), groupName, schemaName, - this.client.getApiVersion(), accept, context)) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null)); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema along with {@link PagedResponse} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getVersionsSinglePageAsync(String groupName, String schemaName, - Context context) { - final String accept = "application/json"; - return service - .getVersions(this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), accept, context) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null)); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema as paginated response with {@link PagedFlux}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux getVersionsAsync(String groupName, String schemaName) { - return new PagedFlux<>(() -> getVersionsSinglePageAsync(groupName, schemaName), - nextLink -> getVersionsNextSinglePageAsync(nextLink)); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema as paginated response with {@link PagedFlux}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux getVersionsAsync(String groupName, String schemaName, Context context) { - return new PagedFlux<>(() -> getVersionsSinglePageAsync(groupName, schemaName, context), - nextLink -> getVersionsNextSinglePageAsync(nextLink, context)); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema along with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse getVersionsSinglePage(String groupName, String schemaName) { - final String accept = "application/json"; - Response res = service.getVersionsSync(this.client.getEndpoint(), groupName, schemaName, - this.client.getApiVersion(), accept, Context.NONE); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema along with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse getVersionsSinglePage(String groupName, String schemaName, Context context) { - final String accept = "application/json"; - Response res = service.getVersionsSync(this.client.getEndpoint(), groupName, schemaName, - this.client.getApiVersion(), accept, context); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema as paginated response with {@link PagedIterable}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable getVersions(String groupName, String schemaName) { - return new PagedIterable<>(() -> getVersionsSinglePage(groupName, schemaName, Context.NONE), - nextLink -> getVersionsNextSinglePage(nextLink)); - } - - /** - * Get list schema versions. - * - * Gets the list of all versions of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the list of all versions of one schema as paginated response with {@link PagedIterable}. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable getVersions(String groupName, String schemaName, Context context) { - return new PagedIterable<>(() -> getVersionsSinglePage(groupName, schemaName, context), - nextLink -> getVersionsNextSinglePage(nextLink, context)); - } - - /** - * Get specific schema versions. - * - * Gets one specific version of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param schemaVersion Version number of specific schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return one specific version of one schema along with {@link ResponseBase} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> - getSchemaVersionWithResponseAsync(String groupName, String schemaName, int schemaVersion) { - final String accept - = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8, text/vnd.ms.protobuf"; - return FluxUtil.withContext(context -> service.getSchemaVersion(this.client.getEndpoint(), groupName, - schemaName, schemaVersion, this.client.getApiVersion(), accept, context)); - } - - /** - * Get specific schema versions. - * - * Gets one specific version of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param schemaVersion Version number of specific schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return one specific version of one schema along with {@link ResponseBase} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> - getSchemaVersionWithResponseAsync(String groupName, String schemaName, int schemaVersion, Context context) { - final String accept - = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8, text/vnd.ms.protobuf"; - return service.getSchemaVersion(this.client.getEndpoint(), groupName, schemaName, schemaVersion, - this.client.getApiVersion(), accept, context); - } - - /** - * Get specific schema versions. - * - * Gets one specific version of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param schemaVersion Version number of specific schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return one specific version of one schema on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSchemaVersionAsync(String groupName, String schemaName, int schemaVersion) { - return getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Get specific schema versions. - * - * Gets one specific version of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param schemaVersion Version number of specific schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return one specific version of one schema on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSchemaVersionAsync(String groupName, String schemaName, int schemaVersion, - Context context) { - return getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion, context) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Get specific schema versions. - * - * Gets one specific version of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param schemaVersion Version number of specific schema. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return one specific version of one schema along with {@link ResponseBase}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public ResponseBase getSchemaVersionWithResponse(String groupName, - String schemaName, int schemaVersion, Context context) { - final String accept - = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8, text/vnd.ms.protobuf"; - return service.getSchemaVersionSync(this.client.getEndpoint(), groupName, schemaName, schemaVersion, - this.client.getApiVersion(), accept, context); - } - - /** - * Get specific schema versions. - * - * Gets one specific version of one schema. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param schemaVersion Version number of specific schema. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return one specific version of one schema. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public BinaryData getSchemaVersion(String groupName, String schemaName, int schemaVersion) { - return getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, Context.NONE).getValue(); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> queryIdByContentWithResponseAsync(String groupName, - String schemaName, SchemaFormat contentType, Flux schemaContent, long contentLength) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.queryIdByContent(this.client.getEndpoint(), groupName, - schemaName, this.client.getApiVersion(), contentType, schemaContent, contentLength, accept, context)); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> queryIdByContentWithResponseAsync(String groupName, - String schemaName, SchemaFormat contentType, Flux schemaContent, long contentLength, - Context context) { - final String accept = "application/json"; - return service.queryIdByContent(this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), - contentType, schemaContent, contentLength, accept, context); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentAsync(String groupName, String schemaName, SchemaFormat contentType, - Flux schemaContent, long contentLength) { - return queryIdByContentWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) - .flatMap(ignored -> Mono.empty()); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentAsync(String groupName, String schemaName, SchemaFormat contentType, - Flux schemaContent, long contentLength, Context context) { - return queryIdByContentWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength, - context).flatMap(ignored -> Mono.empty()); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> queryIdByContentWithResponseAsync(String groupName, - String schemaName, SchemaFormat contentType, BinaryData schemaContent, long contentLength) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.queryIdByContent(this.client.getEndpoint(), groupName, - schemaName, this.client.getApiVersion(), contentType, schemaContent, contentLength, accept, context)); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> queryIdByContentWithResponseAsync(String groupName, - String schemaName, SchemaFormat contentType, BinaryData schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.queryIdByContent(this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), - contentType, schemaContent, contentLength, accept, context); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentAsync(String groupName, String schemaName, SchemaFormat contentType, - BinaryData schemaContent, long contentLength) { - return queryIdByContentWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) - .flatMap(ignored -> Mono.empty()); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentAsync(String groupName, String schemaName, SchemaFormat contentType, - BinaryData schemaContent, long contentLength, Context context) { - return queryIdByContentWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength, - context).flatMap(ignored -> Mono.empty()); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison along with {@link ResponseBase}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public ResponseBase queryIdByContentWithResponse(String groupName, - String schemaName, SchemaFormat contentType, BinaryData schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.queryIdByContentSync(this.client.getEndpoint(), groupName, schemaName, - this.client.getApiVersion(), contentType, schemaContent, contentLength, accept, context); - } - - /** - * Get ID for existing schema. - * - * Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. - * - * @param groupName Schema group under which schema is registered. Group's serialization type should match the - * serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the registered schema. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public void queryIdByContent(String groupName, String schemaName, SchemaFormat contentType, - BinaryData schemaContent, long contentLength) { - queryIdByContentWithResponse(groupName, schemaName, contentType, schemaContent, contentLength, Context.NONE); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerWithResponseAsync(String groupName, - String schemaName, String contentType, Flux schemaContent, long contentLength) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.register(this.client.getEndpoint(), groupName, schemaName, - this.client.getApiVersion(), contentType, schemaContent, contentLength, accept, context)); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerWithResponseAsync(String groupName, - String schemaName, String contentType, Flux schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.register(this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), - contentType, schemaContent, contentLength, accept, context); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerAsync(String groupName, String schemaName, String contentType, - Flux schemaContent, long contentLength) { - return registerWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) - .flatMap(ignored -> Mono.empty()); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerAsync(String groupName, String schemaName, String contentType, - Flux schemaContent, long contentLength, Context context) { - return registerWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength, context) - .flatMap(ignored -> Mono.empty()); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerWithResponseAsync(String groupName, - String schemaName, String contentType, BinaryData schemaContent, long contentLength) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.register(this.client.getEndpoint(), groupName, schemaName, - this.client.getApiVersion(), contentType, schemaContent, contentLength, accept, context)); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link ResponseBase} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerWithResponseAsync(String groupName, - String schemaName, String contentType, BinaryData schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.register(this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), - contentType, schemaContent, contentLength, accept, context); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerAsync(String groupName, String schemaName, String contentType, BinaryData schemaContent, - long contentLength) { - return registerWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) - .flatMap(ignored -> Mono.empty()); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerAsync(String groupName, String schemaName, String contentType, BinaryData schemaContent, - long contentLength, Context context) { - return registerWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength, context) - .flatMap(ignored -> Mono.empty()); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link ResponseBase}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public ResponseBase registerWithResponse(String groupName, String schemaName, - String contentType, BinaryData schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.registerSync(this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), - contentType, schemaContent, contentLength, accept, context); - } - - /** - * Register new schema - * - * Register new schema. If schema of specified name does not exist in specified group, schema is created at version - * 1. If schema of specified name exists already in specified group, schema is created at latest version + 1. - * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. - * @param schemaName Name of schema. - * @param contentType Content type of the schema. - * @param schemaContent String representation (UTF-8) of the schema being registered. - * @param contentLength The Content-Length header for the request. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public void register(String groupName, String schemaName, String contentType, BinaryData schemaContent, - long contentLength) { - registerWithResponse(groupName, schemaName, contentType, schemaContent, contentLength, Context.NONE); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema versions and link to next batch page - * along with {@link PagedResponse} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getVersionsNextSinglePageAsync(String nextLink) { - final String accept = "application/json"; - return FluxUtil - .withContext(context -> service.getVersionsNext(nextLink, this.client.getEndpoint(), accept, context)) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null)); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema versions and link to next batch page - * along with {@link PagedResponse} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getVersionsNextSinglePageAsync(String nextLink, Context context) { - final String accept = "application/json"; - return service.getVersionsNext(nextLink, this.client.getEndpoint(), accept, context) - .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null)); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema versions and link to next batch page - * along with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse getVersionsNextSinglePage(String nextLink) { - final String accept = "application/json"; - Response res - = service.getVersionsNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null); - } - - /** - * Get the next page of items. - * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return object received from the registry containing the list of schema versions and link to next batch page - * along with {@link PagedResponse}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PagedResponse getVersionsNextSinglePage(String nextLink, Context context) { - final String accept = "application/json"; - Response res - = service.getVersionsNextSync(nextLink, this.client.getEndpoint(), accept, context); - return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - res.getValue().getVersions(), res.getValue().getNextLink(), null); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/Error.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/Error.java deleted file mode 100644 index 3b4d34676481..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/Error.java +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; - -/** - * An error response returned from Azure Schema Registry service. - */ -@Fluent -public final class Error implements JsonSerializable { - /* - * Error response returned from Azure Schema Registry service. - */ - private ErrorDetail error; - - /** - * Creates an instance of Error class. - */ - public Error() { - } - - /** - * Get the error property: Error response returned from Azure Schema Registry service. - * - * @return the error value. - */ - public ErrorDetail getError() { - return this.error; - } - - /** - * Set the error property: Error response returned from Azure Schema Registry service. - * - * @param error the error value to set. - * @return the Error object itself. - */ - public Error setError(ErrorDetail error) { - this.error = error; - return this; - } - - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeJsonField("error", this.error); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of Error from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of Error if the JsonReader was pointing to an instance of it, or null if it was pointing to - * JSON null. - * @throws IllegalStateException If the deserialized JSON object was missing any required properties. - * @throws IOException If an error occurs while reading the Error. - */ - public static Error fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - Error deserializedError = new Error(); - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("error".equals(fieldName)) { - deserializedError.error = ErrorDetail.fromJson(reader); - } else { - reader.skipChildren(); - } - } - - return deserializedError; - }); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorDetail.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorDetail.java deleted file mode 100644 index 00cf8e46b002..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorDetail.java +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; -import java.util.List; - -/** - * Error response returned from Azure Schema Registry service. - */ -@Fluent -public final class ErrorDetail implements JsonSerializable { - /* - * Server-defined error code. - */ - private String code; - - /* - * Brief description of error. - */ - private String message; - - /* - * Error message details to help user understand/debug failure. - */ - private List details; - - /** - * Creates an instance of ErrorDetail class. - */ - public ErrorDetail() { - } - - /** - * Get the code property: Server-defined error code. - * - * @return the code value. - */ - public String getCode() { - return this.code; - } - - /** - * Set the code property: Server-defined error code. - * - * @param code the code value to set. - * @return the ErrorDetail object itself. - */ - public ErrorDetail setCode(String code) { - this.code = code; - return this; - } - - /** - * Get the message property: Brief description of error. - * - * @return the message value. - */ - public String getMessage() { - return this.message; - } - - /** - * Set the message property: Brief description of error. - * - * @param message the message value to set. - * @return the ErrorDetail object itself. - */ - public ErrorDetail setMessage(String message) { - this.message = message; - return this; - } - - /** - * Get the details property: Error message details to help user understand/debug failure. - * - * @return the details value. - */ - public List getDetails() { - return this.details; - } - - /** - * Set the details property: Error message details to help user understand/debug failure. - * - * @param details the details value to set. - * @return the ErrorDetail object itself. - */ - public ErrorDetail setDetails(List details) { - this.details = details; - return this; - } - - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeStringField("code", this.code); - jsonWriter.writeStringField("message", this.message); - jsonWriter.writeArrayField("details", this.details, (writer, element) -> writer.writeJson(element)); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of ErrorDetail from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of ErrorDetail if the JsonReader was pointing to an instance of it, or null if it was - * pointing to JSON null. - * @throws IllegalStateException If the deserialized JSON object was missing any required properties. - * @throws IOException If an error occurs while reading the ErrorDetail. - */ - public static ErrorDetail fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - ErrorDetail deserializedErrorDetail = new ErrorDetail(); - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("code".equals(fieldName)) { - deserializedErrorDetail.code = reader.getString(); - } else if ("message".equals(fieldName)) { - deserializedErrorDetail.message = reader.getString(); - } else if ("details".equals(fieldName)) { - List details = reader.readArray(reader1 -> ErrorDetail.fromJson(reader1)); - deserializedErrorDetail.details = details; - } else { - reader.skipChildren(); - } - } - - return deserializedErrorDetail; - }); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorException.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorException.java deleted file mode 100644 index 78b2e8e3f389..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorException.java +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.exception.HttpResponseException; -import com.azure.core.http.HttpResponse; - -/** - * Exception thrown for an invalid response with Error information. - */ -public final class ErrorException extends HttpResponseException { - /** - * Initializes a new instance of the ErrorException class. - * - * @param message the exception message or the response content if a message is not available. - * @param response the HTTP response. - */ - public ErrorException(String message, HttpResponse response) { - super(message, response); - } - - /** - * Initializes a new instance of the ErrorException class. - * - * @param message the exception message or the response content if a message is not available. - * @param response the HTTP response. - * @param value the deserialized response value. - */ - public ErrorException(String message, HttpResponse response, Error value) { - super(message, response, value); - } - - /** - * {@inheritDoc} - */ - @Override - public Error getValue() { - return (Error) super.getValue(); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaFormat.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaFormat.java deleted file mode 100644 index e34fa1f1af26..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaFormat.java +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.util.ExpandableStringEnum; -import java.util.Collection; - -/** - * Defines values for SchemaFormat. - */ -public final class SchemaFormat extends ExpandableStringEnum { - /** - * Static value application/json; serialization=Avro for SchemaFormat. - */ - public static final SchemaFormat APPLICATION_JSON_SERIALIZATION_AVRO - = fromString("application/json; serialization=Avro"); - - /** - * Static value application/json; serialization=Json for SchemaFormat. - */ - public static final SchemaFormat APPLICATION_JSON_SERIALIZATION_JSON - = fromString("application/json; serialization=Json"); - - /** - * Static value text/plain; charset=utf-8 for SchemaFormat. - */ - public static final SchemaFormat TEXT_PLAIN_CHARSET_UTF8 = fromString("text/plain; charset=utf-8"); - - /** - * Creates a new instance of SchemaFormat value. - * - * @deprecated Use the {@link #fromString(String)} factory method. - */ - @Deprecated - public SchemaFormat() { - } - - /** - * Creates or finds a SchemaFormat from its string representation. - * - * @param name a name to look for. - * @return the corresponding SchemaFormat. - */ - public static SchemaFormat fromString(String name) { - return fromString(name, SchemaFormat.class); - } - - /** - * Gets known SchemaFormat values. - * - * @return known SchemaFormat values. - */ - public static Collection values() { - return values(SchemaFormat.class); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaGroups.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaGroups.java deleted file mode 100644 index 274f0082bd42..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaGroups.java +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; -import java.util.List; - -/** - * Object received from the registry containing the list of schema groups and link to next batch page. - */ -@Fluent -public final class SchemaGroups implements JsonSerializable { - /* - * Array of schema groups. - */ - private List groups; - - /* - * URl to next batch of schema groups - */ - private String nextLink; - - /** - * Creates an instance of SchemaGroups class. - */ - public SchemaGroups() { - } - - /** - * Get the groups property: Array of schema groups. - * - * @return the groups value. - */ - public List getGroups() { - return this.groups; - } - - /** - * Set the groups property: Array of schema groups. - * - * @param groups the groups value to set. - * @return the SchemaGroups object itself. - */ - public SchemaGroups setGroups(List groups) { - this.groups = groups; - return this; - } - - /** - * Get the nextLink property: URl to next batch of schema groups. - * - * @return the nextLink value. - */ - public String getNextLink() { - return this.nextLink; - } - - /** - * Set the nextLink property: URl to next batch of schema groups. - * - * @param nextLink the nextLink value to set. - * @return the SchemaGroups object itself. - */ - public SchemaGroups setNextLink(String nextLink) { - this.nextLink = nextLink; - return this; - } - - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeArrayField("schemaGroups", this.groups, (writer, element) -> writer.writeString(element)); - jsonWriter.writeStringField("nextLink", this.nextLink); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of SchemaGroups from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of SchemaGroups if the JsonReader was pointing to an instance of it, or null if it was - * pointing to JSON null. - * @throws IOException If an error occurs while reading the SchemaGroups. - */ - public static SchemaGroups fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - SchemaGroups deserializedSchemaGroups = new SchemaGroups(); - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("schemaGroups".equals(fieldName)) { - List groups = reader.readArray(reader1 -> reader1.getString()); - deserializedSchemaGroups.groups = groups; - } else if ("nextLink".equals(fieldName)) { - deserializedSchemaGroups.nextLink = reader.getString(); - } else { - reader.skipChildren(); - } - } - - return deserializedSchemaGroups; - }); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaId.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaId.java deleted file mode 100644 index 954a22b1551d..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaId.java +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; - -/** - * Object received from the registry containing schema identifiers. - */ -@Fluent -public final class SchemaId implements JsonSerializable { - /* - * Schema ID that uniquely identifies a schema in the registry namespace. - */ - private String id; - - /** - * Creates an instance of SchemaId class. - */ - public SchemaId() { - } - - /** - * Get the id property: Schema ID that uniquely identifies a schema in the registry namespace. - * - * @return the id value. - */ - public String getId() { - return this.id; - } - - /** - * Set the id property: Schema ID that uniquely identifies a schema in the registry namespace. - * - * @param id the id value to set. - * @return the SchemaId object itself. - */ - public SchemaId setId(String id) { - this.id = id; - return this; - } - - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeStringField("id", this.id); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of SchemaId from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of SchemaId if the JsonReader was pointing to an instance of it, or null if it was pointing - * to JSON null. - * @throws IOException If an error occurs while reading the SchemaId. - */ - public static SchemaId fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - SchemaId deserializedSchemaId = new SchemaId(); - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("id".equals(fieldName)) { - deserializedSchemaId.id = reader.getString(); - } else { - reader.skipChildren(); - } - } - - return deserializedSchemaId; - }); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaVersions.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaVersions.java deleted file mode 100644 index 0aedce55e739..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaVersions.java +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; -import java.util.List; - -/** - * Object received from the registry containing the list of schema versions and link to next batch page. - */ -@Fluent -public final class SchemaVersions implements JsonSerializable { - /* - * Array of schema version integers. - */ - private List versions; - - /* - * URl to next batch of schema versions - */ - private String nextLink; - - /** - * Creates an instance of SchemaVersions class. - */ - public SchemaVersions() { - } - - /** - * Get the versions property: Array of schema version integers. - * - * @return the versions value. - */ - public List getVersions() { - return this.versions; - } - - /** - * Set the versions property: Array of schema version integers. - * - * @param versions the versions value to set. - * @return the SchemaVersions object itself. - */ - public SchemaVersions setVersions(List versions) { - this.versions = versions; - return this; - } - - /** - * Get the nextLink property: URl to next batch of schema versions. - * - * @return the nextLink value. - */ - public String getNextLink() { - return this.nextLink; - } - - /** - * Set the nextLink property: URl to next batch of schema versions. - * - * @param nextLink the nextLink value to set. - * @return the SchemaVersions object itself. - */ - public SchemaVersions setNextLink(String nextLink) { - this.nextLink = nextLink; - return this; - } - - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeArrayField("schemaVersions", this.versions, (writer, element) -> writer.writeInt(element)); - jsonWriter.writeStringField("nextLink", this.nextLink); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of SchemaVersions from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of SchemaVersions if the JsonReader was pointing to an instance of it, or null if it was - * pointing to JSON null. - * @throws IOException If an error occurs while reading the SchemaVersions. - */ - public static SchemaVersions fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - SchemaVersions deserializedSchemaVersions = new SchemaVersions(); - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("schemaVersions".equals(fieldName)) { - List versions = reader.readArray(reader1 -> reader1.getInt()); - deserializedSchemaVersions.versions = versions; - } else if ("nextLink".equals(fieldName)) { - deserializedSchemaVersions.nextLink = reader.getString(); - } else { - reader.skipChildren(); - } - } - - return deserializedSchemaVersions; - }); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdHeaders.java deleted file mode 100644 index fc3bcdb401a1..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdHeaders.java +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpHeaders; - -/** - * The SchemasGetByIdHeaders model. - */ -@Fluent -public final class SchemasGetByIdHeaders { - /* - * The Schema-Version property. - */ - private Integer schemaVersion; - - /* - * The Schema-Id property. - */ - private String schemaId; - - /* - * The Schema-Group-Name property. - */ - private String schemaGroupName; - - /* - * The Schema-Name property. - */ - private String schemaName; - - /* - * The Schema-Id-Location property. - */ - private String schemaIdLocation; - - /* - * The Location property. - */ - private String location; - - /* - * The Content-Type property. - */ - private SchemaFormat contentType; - - private static final HttpHeaderName SCHEMA_VERSION = HttpHeaderName.fromString("Schema-Version"); - - private static final HttpHeaderName SCHEMA_ID = HttpHeaderName.fromString("Schema-Id"); - - private static final HttpHeaderName SCHEMA_GROUP_NAME = HttpHeaderName.fromString("Schema-Group-Name"); - - private static final HttpHeaderName SCHEMA_NAME = HttpHeaderName.fromString("Schema-Name"); - - private static final HttpHeaderName SCHEMA_ID_LOCATION = HttpHeaderName.fromString("Schema-Id-Location"); - - // HttpHeaders containing the raw property values. - /** - * Creates an instance of SchemasGetByIdHeaders class. - * - * @param rawHeaders The raw HttpHeaders that will be used to create the property values. - */ - public SchemasGetByIdHeaders(HttpHeaders rawHeaders) { - String schemaVersion = rawHeaders.getValue(SCHEMA_VERSION); - if (schemaVersion != null) { - this.schemaVersion = Integer.parseInt(schemaVersion); - } - this.schemaId = rawHeaders.getValue(SCHEMA_ID); - this.schemaGroupName = rawHeaders.getValue(SCHEMA_GROUP_NAME); - this.schemaName = rawHeaders.getValue(SCHEMA_NAME); - this.schemaIdLocation = rawHeaders.getValue(SCHEMA_ID_LOCATION); - this.location = rawHeaders.getValue(HttpHeaderName.LOCATION); - String contentType = rawHeaders.getValue(HttpHeaderName.CONTENT_TYPE); - if (contentType != null) { - this.contentType = SchemaFormat.fromString(contentType); - } - } - - /** - * Get the schemaVersion property: The Schema-Version property. - * - * @return the schemaVersion value. - */ - public Integer getSchemaVersion() { - return this.schemaVersion; - } - - /** - * Set the schemaVersion property: The Schema-Version property. - * - * @param schemaVersion the schemaVersion value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setSchemaVersion(Integer schemaVersion) { - this.schemaVersion = schemaVersion; - return this; - } - - /** - * Get the schemaId property: The Schema-Id property. - * - * @return the schemaId value. - */ - public String getSchemaId() { - return this.schemaId; - } - - /** - * Set the schemaId property: The Schema-Id property. - * - * @param schemaId the schemaId value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setSchemaId(String schemaId) { - this.schemaId = schemaId; - return this; - } - - /** - * Get the schemaGroupName property: The Schema-Group-Name property. - * - * @return the schemaGroupName value. - */ - public String getSchemaGroupName() { - return this.schemaGroupName; - } - - /** - * Set the schemaGroupName property: The Schema-Group-Name property. - * - * @param schemaGroupName the schemaGroupName value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setSchemaGroupName(String schemaGroupName) { - this.schemaGroupName = schemaGroupName; - return this; - } - - /** - * Get the schemaName property: The Schema-Name property. - * - * @return the schemaName value. - */ - public String getSchemaName() { - return this.schemaName; - } - - /** - * Set the schemaName property: The Schema-Name property. - * - * @param schemaName the schemaName value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setSchemaName(String schemaName) { - this.schemaName = schemaName; - return this; - } - - /** - * Get the schemaIdLocation property: The Schema-Id-Location property. - * - * @return the schemaIdLocation value. - */ - public String getSchemaIdLocation() { - return this.schemaIdLocation; - } - - /** - * Set the schemaIdLocation property: The Schema-Id-Location property. - * - * @param schemaIdLocation the schemaIdLocation value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setSchemaIdLocation(String schemaIdLocation) { - this.schemaIdLocation = schemaIdLocation; - return this; - } - - /** - * Get the location property: The Location property. - * - * @return the location value. - */ - public String getLocation() { - return this.location; - } - - /** - * Set the location property: The Location property. - * - * @param location the location value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setLocation(String location) { - this.location = location; - return this; - } - - /** - * Get the contentType property: The Content-Type property. - * - * @return the contentType value. - */ - public SchemaFormat getContentType() { - return this.contentType; - } - - /** - * Set the contentType property: The Content-Type property. - * - * @param contentType the contentType value to set. - * @return the SchemasGetByIdHeaders object itself. - */ - public SchemasGetByIdHeaders setContentType(SchemaFormat contentType) { - this.contentType = contentType; - return this; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionHeaders.java deleted file mode 100644 index 0429d888b51e..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionHeaders.java +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpHeaders; - -/** - * The SchemasGetSchemaVersionHeaders model. - */ -@Fluent -public final class SchemasGetSchemaVersionHeaders { - /* - * The Schema-Version property. - */ - private Integer schemaVersion; - - /* - * The Schema-Id property. - */ - private String schemaId; - - /* - * The Schema-Group-Name property. - */ - private String schemaGroupName; - - /* - * The Schema-Name property. - */ - private String schemaName; - - /* - * The Schema-Id-Location property. - */ - private String schemaIdLocation; - - /* - * The Location property. - */ - private String location; - - /* - * The Content-Type property. - */ - private SchemaFormat contentType; - - private static final HttpHeaderName SCHEMA_VERSION = HttpHeaderName.fromString("Schema-Version"); - - private static final HttpHeaderName SCHEMA_ID = HttpHeaderName.fromString("Schema-Id"); - - private static final HttpHeaderName SCHEMA_GROUP_NAME = HttpHeaderName.fromString("Schema-Group-Name"); - - private static final HttpHeaderName SCHEMA_NAME = HttpHeaderName.fromString("Schema-Name"); - - private static final HttpHeaderName SCHEMA_ID_LOCATION = HttpHeaderName.fromString("Schema-Id-Location"); - - // HttpHeaders containing the raw property values. - /** - * Creates an instance of SchemasGetSchemaVersionHeaders class. - * - * @param rawHeaders The raw HttpHeaders that will be used to create the property values. - */ - public SchemasGetSchemaVersionHeaders(HttpHeaders rawHeaders) { - String schemaVersion = rawHeaders.getValue(SCHEMA_VERSION); - if (schemaVersion != null) { - this.schemaVersion = Integer.parseInt(schemaVersion); - } - this.schemaId = rawHeaders.getValue(SCHEMA_ID); - this.schemaGroupName = rawHeaders.getValue(SCHEMA_GROUP_NAME); - this.schemaName = rawHeaders.getValue(SCHEMA_NAME); - this.schemaIdLocation = rawHeaders.getValue(SCHEMA_ID_LOCATION); - this.location = rawHeaders.getValue(HttpHeaderName.LOCATION); - String contentType = rawHeaders.getValue(HttpHeaderName.CONTENT_TYPE); - if (contentType != null) { - this.contentType = SchemaFormat.fromString(contentType); - } - } - - /** - * Get the schemaVersion property: The Schema-Version property. - * - * @return the schemaVersion value. - */ - public Integer getSchemaVersion() { - return this.schemaVersion; - } - - /** - * Set the schemaVersion property: The Schema-Version property. - * - * @param schemaVersion the schemaVersion value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setSchemaVersion(Integer schemaVersion) { - this.schemaVersion = schemaVersion; - return this; - } - - /** - * Get the schemaId property: The Schema-Id property. - * - * @return the schemaId value. - */ - public String getSchemaId() { - return this.schemaId; - } - - /** - * Set the schemaId property: The Schema-Id property. - * - * @param schemaId the schemaId value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setSchemaId(String schemaId) { - this.schemaId = schemaId; - return this; - } - - /** - * Get the schemaGroupName property: The Schema-Group-Name property. - * - * @return the schemaGroupName value. - */ - public String getSchemaGroupName() { - return this.schemaGroupName; - } - - /** - * Set the schemaGroupName property: The Schema-Group-Name property. - * - * @param schemaGroupName the schemaGroupName value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setSchemaGroupName(String schemaGroupName) { - this.schemaGroupName = schemaGroupName; - return this; - } - - /** - * Get the schemaName property: The Schema-Name property. - * - * @return the schemaName value. - */ - public String getSchemaName() { - return this.schemaName; - } - - /** - * Set the schemaName property: The Schema-Name property. - * - * @param schemaName the schemaName value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setSchemaName(String schemaName) { - this.schemaName = schemaName; - return this; - } - - /** - * Get the schemaIdLocation property: The Schema-Id-Location property. - * - * @return the schemaIdLocation value. - */ - public String getSchemaIdLocation() { - return this.schemaIdLocation; - } - - /** - * Set the schemaIdLocation property: The Schema-Id-Location property. - * - * @param schemaIdLocation the schemaIdLocation value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setSchemaIdLocation(String schemaIdLocation) { - this.schemaIdLocation = schemaIdLocation; - return this; - } - - /** - * Get the location property: The Location property. - * - * @return the location value. - */ - public String getLocation() { - return this.location; - } - - /** - * Set the location property: The Location property. - * - * @param location the location value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setLocation(String location) { - this.location = location; - return this; - } - - /** - * Get the contentType property: The Content-Type property. - * - * @return the contentType value. - */ - public SchemaFormat getContentType() { - return this.contentType; - } - - /** - * Set the contentType property: The Content-Type property. - * - * @param contentType the contentType value to set. - * @return the SchemasGetSchemaVersionHeaders object itself. - */ - public SchemasGetSchemaVersionHeaders setContentType(SchemaFormat contentType) { - this.contentType = contentType; - return this; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasQueryIdByContentHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasQueryIdByContentHeaders.java deleted file mode 100644 index f69ad09b076f..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasQueryIdByContentHeaders.java +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpHeaders; - -/** - * The SchemasQueryIdByContentHeaders model. - */ -@Fluent -public final class SchemasQueryIdByContentHeaders { - /* - * The Schema-Version property. - */ - private Integer schemaVersion; - - /* - * The Schema-Id property. - */ - private String schemaId; - - /* - * The Schema-Group-Name property. - */ - private String schemaGroupName; - - /* - * The Schema-Name property. - */ - private String schemaName; - - /* - * The Schema-Id-Location property. - */ - private String schemaIdLocation; - - /* - * The Location property. - */ - private String location; - - private static final HttpHeaderName SCHEMA_VERSION = HttpHeaderName.fromString("Schema-Version"); - - private static final HttpHeaderName SCHEMA_ID = HttpHeaderName.fromString("Schema-Id"); - - private static final HttpHeaderName SCHEMA_GROUP_NAME = HttpHeaderName.fromString("Schema-Group-Name"); - - private static final HttpHeaderName SCHEMA_NAME = HttpHeaderName.fromString("Schema-Name"); - - private static final HttpHeaderName SCHEMA_ID_LOCATION = HttpHeaderName.fromString("Schema-Id-Location"); - - // HttpHeaders containing the raw property values. - /** - * Creates an instance of SchemasQueryIdByContentHeaders class. - * - * @param rawHeaders The raw HttpHeaders that will be used to create the property values. - */ - public SchemasQueryIdByContentHeaders(HttpHeaders rawHeaders) { - String schemaVersion = rawHeaders.getValue(SCHEMA_VERSION); - if (schemaVersion != null) { - this.schemaVersion = Integer.parseInt(schemaVersion); - } - this.schemaId = rawHeaders.getValue(SCHEMA_ID); - this.schemaGroupName = rawHeaders.getValue(SCHEMA_GROUP_NAME); - this.schemaName = rawHeaders.getValue(SCHEMA_NAME); - this.schemaIdLocation = rawHeaders.getValue(SCHEMA_ID_LOCATION); - this.location = rawHeaders.getValue(HttpHeaderName.LOCATION); - } - - /** - * Get the schemaVersion property: The Schema-Version property. - * - * @return the schemaVersion value. - */ - public Integer getSchemaVersion() { - return this.schemaVersion; - } - - /** - * Set the schemaVersion property: The Schema-Version property. - * - * @param schemaVersion the schemaVersion value to set. - * @return the SchemasQueryIdByContentHeaders object itself. - */ - public SchemasQueryIdByContentHeaders setSchemaVersion(Integer schemaVersion) { - this.schemaVersion = schemaVersion; - return this; - } - - /** - * Get the schemaId property: The Schema-Id property. - * - * @return the schemaId value. - */ - public String getSchemaId() { - return this.schemaId; - } - - /** - * Set the schemaId property: The Schema-Id property. - * - * @param schemaId the schemaId value to set. - * @return the SchemasQueryIdByContentHeaders object itself. - */ - public SchemasQueryIdByContentHeaders setSchemaId(String schemaId) { - this.schemaId = schemaId; - return this; - } - - /** - * Get the schemaGroupName property: The Schema-Group-Name property. - * - * @return the schemaGroupName value. - */ - public String getSchemaGroupName() { - return this.schemaGroupName; - } - - /** - * Set the schemaGroupName property: The Schema-Group-Name property. - * - * @param schemaGroupName the schemaGroupName value to set. - * @return the SchemasQueryIdByContentHeaders object itself. - */ - public SchemasQueryIdByContentHeaders setSchemaGroupName(String schemaGroupName) { - this.schemaGroupName = schemaGroupName; - return this; - } - - /** - * Get the schemaName property: The Schema-Name property. - * - * @return the schemaName value. - */ - public String getSchemaName() { - return this.schemaName; - } - - /** - * Set the schemaName property: The Schema-Name property. - * - * @param schemaName the schemaName value to set. - * @return the SchemasQueryIdByContentHeaders object itself. - */ - public SchemasQueryIdByContentHeaders setSchemaName(String schemaName) { - this.schemaName = schemaName; - return this; - } - - /** - * Get the schemaIdLocation property: The Schema-Id-Location property. - * - * @return the schemaIdLocation value. - */ - public String getSchemaIdLocation() { - return this.schemaIdLocation; - } - - /** - * Set the schemaIdLocation property: The Schema-Id-Location property. - * - * @param schemaIdLocation the schemaIdLocation value to set. - * @return the SchemasQueryIdByContentHeaders object itself. - */ - public SchemasQueryIdByContentHeaders setSchemaIdLocation(String schemaIdLocation) { - this.schemaIdLocation = schemaIdLocation; - return this; - } - - /** - * Get the location property: The Location property. - * - * @return the location value. - */ - public String getLocation() { - return this.location; - } - - /** - * Set the location property: The Location property. - * - * @param location the location value to set. - * @return the SchemasQueryIdByContentHeaders object itself. - */ - public SchemasQueryIdByContentHeaders setLocation(String location) { - this.location = location; - return this; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasRegisterHeaders.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasRegisterHeaders.java deleted file mode 100644 index 0fedae1f434c..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasRegisterHeaders.java +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.data.schemaregistry.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpHeaders; - -/** - * The SchemasRegisterHeaders model. - */ -@Fluent -public final class SchemasRegisterHeaders { - /* - * The Schema-Version property. - */ - private Integer schemaVersion; - - /* - * The Schema-Id property. - */ - private String schemaId; - - /* - * The Schema-Group-Name property. - */ - private String schemaGroupName; - - /* - * The Schema-Name property. - */ - private String schemaName; - - /* - * The Schema-Id-Location property. - */ - private String schemaIdLocation; - - /* - * The Location property. - */ - private String location; - - private static final HttpHeaderName SCHEMA_VERSION = HttpHeaderName.fromString("Schema-Version"); - - private static final HttpHeaderName SCHEMA_ID = HttpHeaderName.fromString("Schema-Id"); - - private static final HttpHeaderName SCHEMA_GROUP_NAME = HttpHeaderName.fromString("Schema-Group-Name"); - - private static final HttpHeaderName SCHEMA_NAME = HttpHeaderName.fromString("Schema-Name"); - - private static final HttpHeaderName SCHEMA_ID_LOCATION = HttpHeaderName.fromString("Schema-Id-Location"); - - // HttpHeaders containing the raw property values. - /** - * Creates an instance of SchemasRegisterHeaders class. - * - * @param rawHeaders The raw HttpHeaders that will be used to create the property values. - */ - public SchemasRegisterHeaders(HttpHeaders rawHeaders) { - String schemaVersion = rawHeaders.getValue(SCHEMA_VERSION); - if (schemaVersion != null) { - this.schemaVersion = Integer.parseInt(schemaVersion); - } - this.schemaId = rawHeaders.getValue(SCHEMA_ID); - this.schemaGroupName = rawHeaders.getValue(SCHEMA_GROUP_NAME); - this.schemaName = rawHeaders.getValue(SCHEMA_NAME); - this.schemaIdLocation = rawHeaders.getValue(SCHEMA_ID_LOCATION); - this.location = rawHeaders.getValue(HttpHeaderName.LOCATION); - } - - /** - * Get the schemaVersion property: The Schema-Version property. - * - * @return the schemaVersion value. - */ - public Integer getSchemaVersion() { - return this.schemaVersion; - } - - /** - * Set the schemaVersion property: The Schema-Version property. - * - * @param schemaVersion the schemaVersion value to set. - * @return the SchemasRegisterHeaders object itself. - */ - public SchemasRegisterHeaders setSchemaVersion(Integer schemaVersion) { - this.schemaVersion = schemaVersion; - return this; - } - - /** - * Get the schemaId property: The Schema-Id property. - * - * @return the schemaId value. - */ - public String getSchemaId() { - return this.schemaId; - } - - /** - * Set the schemaId property: The Schema-Id property. - * - * @param schemaId the schemaId value to set. - * @return the SchemasRegisterHeaders object itself. - */ - public SchemasRegisterHeaders setSchemaId(String schemaId) { - this.schemaId = schemaId; - return this; - } - - /** - * Get the schemaGroupName property: The Schema-Group-Name property. - * - * @return the schemaGroupName value. - */ - public String getSchemaGroupName() { - return this.schemaGroupName; - } - - /** - * Set the schemaGroupName property: The Schema-Group-Name property. - * - * @param schemaGroupName the schemaGroupName value to set. - * @return the SchemasRegisterHeaders object itself. - */ - public SchemasRegisterHeaders setSchemaGroupName(String schemaGroupName) { - this.schemaGroupName = schemaGroupName; - return this; - } - - /** - * Get the schemaName property: The Schema-Name property. - * - * @return the schemaName value. - */ - public String getSchemaName() { - return this.schemaName; - } - - /** - * Set the schemaName property: The Schema-Name property. - * - * @param schemaName the schemaName value to set. - * @return the SchemasRegisterHeaders object itself. - */ - public SchemasRegisterHeaders setSchemaName(String schemaName) { - this.schemaName = schemaName; - return this; - } - - /** - * Get the schemaIdLocation property: The Schema-Id-Location property. - * - * @return the schemaIdLocation value. - */ - public String getSchemaIdLocation() { - return this.schemaIdLocation; - } - - /** - * Set the schemaIdLocation property: The Schema-Id-Location property. - * - * @param schemaIdLocation the schemaIdLocation value to set. - * @return the SchemasRegisterHeaders object itself. - */ - public SchemasRegisterHeaders setSchemaIdLocation(String schemaIdLocation) { - this.schemaIdLocation = schemaIdLocation; - return this; - } - - /** - * Get the location property: The Location property. - * - * @return the location value. - */ - public String getLocation() { - return this.location; - } - - /** - * Set the location property: The Location property. - * - * @param location the location value to set. - * @return the SchemasRegisterHeaders object itself. - */ - public SchemasRegisterHeaders setLocation(String location) { - this.location = location; - return this; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/package-info.java deleted file mode 100644 index 0dd021a863d0..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -/** - * Package containing the data models for AzureSchemaRegistry. - * Azure Schema Registry is as a central schema repository, with support for versioning, management, compatibility - * checking, and RBAC. - */ -package com.azure.data.schemaregistry.implementation.models; diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/package-info.java index 2287caacec8e..02f8ac422d8c 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/package-info.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/package-info.java @@ -1,10 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) TypeSpec Code Generator. /** - * Package containing the implementations for AzureSchemaRegistry. - * Azure Schema Registry is as a central schema repository, with support for versioning, management, compatibility - * checking, and RBAC. + * + * Package containing the implementations for SchemaRegistry. + * SchemaRegistryClient is a client for registering and retrieving schemas from the Azure Schema Registry service. + * */ package com.azure.data.schemaregistry.implementation; diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaFormat.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaFormat.java deleted file mode 100644 index 6b30e0abd2c3..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaFormat.java +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry.models; - -import com.azure.core.util.ExpandableStringEnum; - -import java.util.Locale; - -/** - * The list of all formats supported by Schema Registry. - */ -public final class SchemaFormat extends ExpandableStringEnum { - /** - * Apache Avro format - */ - public static final SchemaFormat AVRO = fromString("avro"); - - /** - * JSON schema format. - */ - public static final SchemaFormat JSON = fromString("json"); - - /** - * Custom schema format. - */ - public static final SchemaFormat CUSTOM = fromString("custom"); - - /** - * Returns the {@link SchemaFormat} associated with the name. - * @param name The name of the serialization type. - * @return The {@link SchemaFormat} associated with this name. - */ - public static SchemaFormat fromString(String name) { - return fromString(name.toLowerCase(Locale.ROOT), SchemaFormat.class); - } - - /** - * Creates a new instance of Schema Format. - * @deprecated Use the {@link #fromString(String)} factory method. - */ - @Deprecated - public SchemaFormat() { - super(); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaProperties.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaProperties.java deleted file mode 100644 index da5d0586d389..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaProperties.java +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry.models; - -import com.azure.core.annotation.Immutable; -import com.azure.data.schemaregistry.SchemaRegistryAsyncClient; -import com.azure.data.schemaregistry.SchemaRegistryClient; -import com.azure.data.schemaregistry.implementation.SchemaRegistryHelper; - -/** - * Stores properties of a schema stored in Schema Registry. - * - * @see SchemaRegistryAsyncClient - * @see SchemaRegistryClient - */ -@Immutable -public final class SchemaProperties { - - private final String id; - private final SchemaFormat format; - private final String groupName; - private final String name; - private final int version; - - static { - SchemaRegistryHelper.setAccessor(SchemaProperties::new); - } - - /** - * Initializes a new instance. - * - * @param id The schema id. - * @param format The type of schema, e.g. avro, json. - */ - public SchemaProperties(String id, SchemaFormat format) { - this(id, format, null, null, -1); - } - - /** - * Initializes a new instance. - * - * @param id The schema id. - * @param format The type of schema, e.g. avro, json. - * @param groupName The schema group for this schema. - * @param name The name of the schema. - */ - SchemaProperties(String id, SchemaFormat format, String groupName, String name, int version) { - this.id = id; - this.format = format; - this.groupName = groupName; - this.name = name; - this.version = version; - } - - /** - * Returns the unique identifier for this schema. - * - * @return the unique identifier for this schema. - */ - public String getId() { - return id; - } - - /** - * The format of this schema. - * - * @return The format associated with the schema payload. - */ - public SchemaFormat getFormat() { - return format; - } - - /** - * Gets the schema group of this schema. - * - * @return The schema group of this schema. - */ - public String getGroupName() { - return groupName; - } - - /** - * Gets the name of the schema. - * - * @return The name of the schema. - */ - public String getName() { - return name; - } - - /** - * Gets the version of the schema. - * - * @return The version of the schema. - */ - public int getVersion() { - return version; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaRegistrySchema.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaRegistrySchema.java deleted file mode 100644 index c52701899d01..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaRegistrySchema.java +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry.models; - -import com.azure.core.annotation.Immutable; -import com.azure.data.schemaregistry.SchemaRegistryAsyncClient; -import com.azure.data.schemaregistry.SchemaRegistryClient; - -/** - * Represents a schema in Schema Registry. - * - * @see SchemaRegistryAsyncClient - * @see SchemaRegistryClient - */ -@Immutable -public final class SchemaRegistrySchema { - private final SchemaProperties properties; - private final String definition; - - /** - * Creates a new instance. - * - * @param properties Schema's properties. - * @param definition The contents of the schema. - */ - public SchemaRegistrySchema(SchemaProperties properties, String definition) { - this.properties = properties; - this.definition = definition; - } - - /** - * Gets properties related to the schema. - * - * @return Properties of the schema. - */ - public SchemaProperties getProperties() { - return properties; - } - - /** - * Gets the content of the schema. - * - * @return The content of the schema. - */ - public String getDefinition() { - return definition; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/package-info.java deleted file mode 100644 index 4b5840e365ae..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -/** - * Package containing the model classes for Schema Registry. - */ -package com.azure.data.schemaregistry.models; diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/package-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/package-info.java index 339ac53b378a..ae42a19ade73 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/package-info.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/package-info.java @@ -1,103 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. /** - *

Azure Schema Registry is a - * service in Microsoft Azure that enables users to manage the schemas for their applications and data. A schema is a - * formal definition of the structure of data in a particular format, such as Avro or JSON. With Azure Schema Registry, - * users can store, version, and manage these schemas in a central location, making it easier to ensure consistency and - * compatibility across different applications and systems.

- * - *

In addition, Azure Schema Registry can integrate with other Azure services, such as Azure Event Hubs and - * Azure Stream Analytics, to provide a complete data processing and analytics solution. By using Azure Schema - * Registry, users can simplify the management of their data schemas, reduce errors and inconsistencies, and - * accelerate the development of data-driven applications.

- * - *

The Azure Schema Registry client library allows Java developers to interact with Azure Schema Registry. It - * provides a set of APIs that enable Java developers to perform operations such as registering, updating, and - * retrieving schemas from the Azure Schema Registry.

- * - *

Key Concepts

- * - *
    - *
  • Schema: Text describing the how to deserialize and serialize an object.
  • - *
  • Schema Registry: Centralized location for event producers and consumers to fetch schemas - * used to serialize and deserialized structured data.
  • - *
- * - *

Getting Started

- * - *

Service clients are the point of interaction for developers to use Azure Schema Registry. - * {@link com.azure.data.schemaregistry.SchemaRegistryClient} is the synchronous service client and - * {@link com.azure.data.schemaregistry.SchemaRegistryAsyncClient} is the asynchronous service client. The examples - * shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate - * for most scenarios, including local development and production environments. Additionally, we recommend using - * managed identity - * for authentication in production environments. - * You can find more information on different ways of authenticating and their corresponding credential types in the - * Azure Identity documentation". - *

- * - *

Sample: Construct a service client

- * - *

The following code sample demonstrates the creation of the synchronous client - * {@link com.azure.data.schemaregistry.SchemaRegistryClient}. The {@code fullyQualifiedNamespace} is the Event Hubs - * Namespace's host name. It is listed under the "Essentials" panel after navigating to the Event Hubs Namespace via - * Azure Portal. The credential used is {@code DefaultAzureCredential} because it combines commonly used credentials - * in deployment and development and chooses the credential to used based on its running environment.

- * - * - *
- * DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder()
- *     .build();
- * SchemaRegistryClient client = new SchemaRegistryClientBuilder()
- *     .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net")
- *     .credential(azureCredential)
- *     .buildClient();
- * 
- * - * - *

Using the Client

- * - *

The samples below use the synchronous client, {@link com.azure.data.schemaregistry.SchemaRegistryClient}. - * More samples can be found in the class's Javadoc. In addition, samples using the asynchronous - * {@link com.azure.data.schemaregistry.SchemaRegistryAsyncClient} can be found in the class's JavaDocs.

- * - *

Sample: Register a schema

- * - *

The following code sample demonstrates registering an Avro schema. The - * {@link com.azure.data.schemaregistry.models.SchemaProperties} returned contains the schema's id. This id uniquely - * identifies the schema and can be used to quickly associate payloads with that schema.

- * - * - *
- * String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}";
- * SchemaProperties properties = client.registerSchema("{schema-group}", "{schema-name}", schema,
- *     SchemaFormat.AVRO);
- *
- * System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), properties.getFormat());
- * 
- * - * - *

Sample: Getting the schema using a schema id

- * - *

The following code sample demonstrates how to fetch a schema using its schema id. The schema id can be found in - * {@link com.azure.data.schemaregistry.models.SchemaProperties#getId()} when a schema is registered or using - * {@link com.azure.data.schemaregistry.SchemaRegistryClient#getSchemaProperties(java.lang.String, java.lang.String, java.lang.String, com.azure.data.schemaregistry.models.SchemaFormat)}. - *

- * - * - *
- * SchemaRegistrySchema schema = client.getSchema("{schema-id}");
- *
- * System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(),
- *     schema.getProperties().getFormat());
- * System.out.println("Schema contents: " + schema.getDefinition());
- * 
- * - * - * @see com.azure.data.schemaregistry.SchemaRegistryClient - * @see com.azure.data.schemaregistry.SchemaRegistryAsyncClient - * @see Azure Schema Registry + * + * Package containing the classes for SchemaRegistry. + * SchemaRegistryClient is a client for registering and retrieving schemas from the Azure Schema Registry service. + * */ package com.azure.data.schemaregistry; diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/module-info.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/module-info.java index 487f74e30a25..f357b508359b 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/module-info.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/module-info.java @@ -1,13 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. module com.azure.data.schemaregistry { requires transitive com.azure.core; - requires com.azure.json; exports com.azure.data.schemaregistry; - exports com.azure.data.schemaregistry.models; - - opens com.azure.data.schemaregistry to com.azure.core; - opens com.azure.data.schemaregistry.implementation.models to com.azure.core; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/resources/META-INF/azure-data-schemaregistry_apiview_properties.json b/sdk/schemaregistry/azure-data-schemaregistry/src/main/resources/META-INF/azure-data-schemaregistry_apiview_properties.json new file mode 100644 index 000000000000..d9a1553d5d41 --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/resources/META-INF/azure-data-schemaregistry_apiview_properties.json @@ -0,0 +1,20 @@ +{ + "flavor": "azure", + "CrossLanguageDefinitionId": { + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient": "SchemaRegistry", + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient.getSchemaById": "SchemaRegistry.getSchemaById", + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient.getSchemaByIdWithResponse": "SchemaRegistry.getSchemaById", + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient.getSchemaByVersion": "SchemaRegistry.getSchemaByVersion", + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient.getSchemaByVersionWithResponse": "SchemaRegistry.getSchemaByVersion", + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient.listSchemaGroups": "SchemaRegistry.listSchemaGroups", + "com.azure.data.schemaregistry.SchemaRegistryAsyncClient.listSchemaVersions": "SchemaRegistry.listSchemaVersions", + "com.azure.data.schemaregistry.SchemaRegistryClient": "SchemaRegistry", + "com.azure.data.schemaregistry.SchemaRegistryClient.getSchemaById": "SchemaRegistry.getSchemaById", + "com.azure.data.schemaregistry.SchemaRegistryClient.getSchemaByIdWithResponse": "SchemaRegistry.getSchemaById", + "com.azure.data.schemaregistry.SchemaRegistryClient.getSchemaByVersion": "SchemaRegistry.getSchemaByVersion", + "com.azure.data.schemaregistry.SchemaRegistryClient.getSchemaByVersionWithResponse": "SchemaRegistry.getSchemaByVersion", + "com.azure.data.schemaregistry.SchemaRegistryClient.listSchemaGroups": "SchemaRegistry.listSchemaGroups", + "com.azure.data.schemaregistry.SchemaRegistryClient.listSchemaVersions": "SchemaRegistry.listSchemaVersions", + "com.azure.data.schemaregistry.SchemaRegistryClientBuilder": "SchemaRegistry" + } +} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/README.md b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/README.md deleted file mode 100644 index 023e90c3f17f..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/README.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -page_type: sample -languages: - - java -products: - - azure - - azure-event-hubs -urlFragment: schemaregistry-samples ---- - -# Azure Schema Registry library samples for Java - -Azure Schema Registry samples are a set of self-contained Java programs that demonstrate using the client library to -register schemas with Azure Schema Registry service and read from it. Each sample focuses on a specific scenario and -can be executed independently. - -## Key concepts -Key concepts are explained in detail [here][sdk_readme_key_concepts]. - -## Getting started -Please refer to the [Getting Started][sdk_readme_getting_started] section. - -## Examples - -- [Register a schema][sample_register_schema] -- [Register a schema using async client][sample_register_schema_async] -- [Get schema][sample_get_schema] -- [Get schema using async client][sample_get_schema_async] -- [Get schema id][sample_get_schema_id] -- [Get schema id using async client][sample_get_schema_id_async] - -## Troubleshooting -See [Troubleshooting][sdk_readme_troubleshooting]. - -## Next steps -See [Next steps][sdk_readme_next_steps]. - -## Contributing -This project welcomes contributions and suggestions. See [Contributing][sdk_readme_contributing] for guidelines. - - -[sdk_readme_key_concepts]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#key-concepts -[sdk_readme_getting_started]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#getting-started -[sdk_readme_troubleshooting]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#troubleshooting -[sdk_readme_next_steps]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#next-steps -[sdk_readme_contributing]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#contributing -[sample_register_schema]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSample.java -[sample_register_schema_async]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSampleAsync.java -[sample_get_schema]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSample.java -[sample_get_schema_async]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSampleAsync.java -[sample_get_schema_id]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSample.java -[sample_get_schema_id_async]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSampleAsync.java - -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%schemaregistry%2Fazure-data-schemaregistry%2Fsrc%2Fsamples%2README.png) diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSample.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSample.java deleted file mode 100644 index fdf782c6bf91..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSample.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.identity.DefaultAzureCredentialBuilder; - -/** - * Sample to demonstrate retrieving properties of a schema from Schema Registry. - * - * @see GetSchemaIdSampleAsync for the async sample. - */ -public class GetSchemaIdSample { - - /** - * The main method to run this program. - * @param args Ignored args. - */ - public static void main(String[] args) { - TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); - - SchemaRegistryClient schemaRegistryClient = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint") - .credential(tokenCredential) - .buildClient(); - - // Gets the properties of an existing schema. - SchemaProperties schemaProperties = schemaRegistryClient - .getSchemaProperties("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO); - - System.out.println("Successfully retrieved the schema id: " + schemaProperties.getId()); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSampleAsync.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSampleAsync.java deleted file mode 100644 index d116d44e71e5..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSampleAsync.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.identity.DefaultAzureCredentialBuilder; - -import java.util.concurrent.CountDownLatch; - -/** - * Sample to demonstrate retrieving properties of a schema from Schema Registry using async client. - * - * @see GetSchemaIdSample for the synchronous sample. - */ -public class GetSchemaIdSampleAsync { - - /** - * The main method to run this program. - * @param args Ignored args. - */ - public static void main(String[] args) throws InterruptedException { - TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); - - SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint") - .credential(tokenCredential) - .buildAsyncClient(); - - CountDownLatch countDownLatch = new CountDownLatch(1); - - // Gets the properties of an existing schema. - // `subscribe` is a non-blocking operation. It hooks up the callbacks and then moves onto the next line of code. - schemaRegistryAsyncClient - .getSchemaProperties("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO) - .subscribe(schemaId -> { - System.out.println("Successfully retrieved the schema id: " + schemaId); - countDownLatch.countDown(); - }); - - // wait for the async task to complete - countDownLatch.await(); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSample.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSample.java deleted file mode 100644 index 0f60e3e3ee20..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSample.java +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.data.schemaregistry.models.SchemaRegistrySchema; -import com.azure.identity.DefaultAzureCredentialBuilder; - -/** - * Sample to demonstrate retrieving a schema from Schema Registry using the sync client. - */ -public class GetSchemaSample { - /** - * The main method to run this program. - * - * @param args Ignored args. - */ - public static void main(String[] args) { - TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); - - SchemaRegistryClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint") - .credential(tokenCredential) - .buildClient(); - - // Get a schema using its id. The schema id is generated when it is registered via the client or Azure Portal. - SchemaRegistrySchema schema = client.getSchema("{schema-id}"); - - System.out.println("Successfully retrieved schema."); - System.out.printf("Id: %s%nContents: %s%n", schema.getProperties().getId(), schema.getDefinition()); - - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSampleAsync.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSampleAsync.java deleted file mode 100644 index e40edf0648a1..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSampleAsync.java +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.identity.DefaultAzureCredentialBuilder; - -import java.util.concurrent.CountDownLatch; - -/** - * Sample to demonstrate retrieving a schema from Schema Registry using the async client. - */ -public class GetSchemaSampleAsync { - /** - * The main method to run this program. - * @param args Ignored args. - */ - public static void main(String[] args) throws InterruptedException { - TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); - - SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint") - .credential(tokenCredential) - .buildAsyncClient(); - - CountDownLatch countDownLatch = new CountDownLatch(1); - - // Get a schema using its id. The schema id is generated when it is registered via the client or Azure Portal. - // `subscribe` is a non-blocking operation. It hooks up the callbacks and then moves onto the next line of code. - schemaRegistryAsyncClient - .getSchema("{schema-id}") - .subscribe(schema -> { - System.out.println("Successfully retrieved schema."); - System.out.printf("Id: %s%nContents: %s%n", schema.getProperties().getId(), schema.getDefinition()); - - countDownLatch.countDown(); - }); - - // wait for the async task to complete - countDownLatch.await(); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/ReadmeSamples.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/ReadmeSamples.java new file mode 100644 index 000000000000..70c8307fbff5 --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/ReadmeSamples.java @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.data.schemaregistry; + +public final class ReadmeSamples { + public void readmeSamples() { + // BEGIN: com.azure.data.schemaregistry.readme + // END: com.azure.data.schemaregistry.readme + } +} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSample.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSample.java deleted file mode 100644 index dd960f27a238..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSample.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.identity.DefaultAzureCredentialBuilder; - -/** - * Sample to demonstrate registering a schema with Schema Registry. - * - * @see RegisterSchemaSampleAsync for the async sample. - */ -public class RegisterSchemaSample { - /** - * The main method to run this program. - * @param args Ignored args. - */ - public static void main(String[] args) { - TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); - - SchemaRegistryClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint}") - .credential(tokenCredential) - .buildClient(); - - // Register a schema - SchemaProperties schemaProperties = client - .registerSchema("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO); - - System.out.println("Successfully registered a schema with id " + schemaProperties.getId()); - System.out.println("Schema Group: " + schemaProperties.getGroupName()); - System.out.println("Schema Name: " + schemaProperties.getName()); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSampleAsync.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSampleAsync.java deleted file mode 100644 index 55fdd188d13a..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSampleAsync.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.identity.DefaultAzureCredentialBuilder; - -import java.util.concurrent.CountDownLatch; - -/** - * Sample to demonstrate registering a schema with Schema Registry. - * - * @see RegisterSchemaSample for the sync sample. - */ -public class RegisterSchemaSampleAsync { - /** - * The main method to run this program. - * - * @param args Ignored args. - */ - public static void main(String[] args) throws InterruptedException { - TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); - - SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint}") - .credential(tokenCredential) - .buildAsyncClient(); - - CountDownLatch countDownLatch = new CountDownLatch(1); - - // Register a schema - // `subscribe` is a non-blocking operation. It hooks up the callbacks and then moves onto the next line of code. - schemaRegistryAsyncClient - .registerSchema("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO) - .subscribe(schemaProperties -> { - System.out.println("Successfully registered a schema with id " + schemaProperties.getId()); - System.out.println("Schema Group: " + schemaProperties.getGroupName()); - System.out.println("Schema Name: " + schemaProperties.getName()); - - countDownLatch.countDown(); - }); - - // wait for the async task to complete - countDownLatch.await(); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/SchemaRegistryClientJavaDocCodeSnippets.java b/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/SchemaRegistryClientJavaDocCodeSnippets.java deleted file mode 100644 index 694a94cd5a33..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/SchemaRegistryClientJavaDocCodeSnippets.java +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.http.HttpHeader; -import com.azure.core.http.policy.FixedDelay; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.http.policy.HttpLogOptions; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.rest.Response; -import com.azure.core.util.Context; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.data.schemaregistry.models.SchemaRegistrySchema; -import com.azure.identity.DefaultAzureCredential; -import com.azure.identity.DefaultAzureCredentialBuilder; - -import java.time.Duration; - -/** - * Snippets for building and using {@link SchemaRegistryClient} and {@link SchemaRegistryAsyncClient}. - */ -public class SchemaRegistryClientJavaDocCodeSnippets { - /** - * Instantiates {@link SchemaRegistryClient}. - */ - public void createClient() { - // BEGIN: com.azure.data.schemaregistry.schemaregistryclient.construct - DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() - .build(); - SchemaRegistryClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("https://.servicebus.windows.net") - .credential(azureCredential) - .buildClient(); - // END: com.azure.data.schemaregistry.schemaregistryclient.construct - } - - /** - * Instantiates {@link SchemaRegistryAsyncClient}. - */ - public void createAsyncClient() { - // BEGIN: com.azure.data.schemaregistry.schemaregistryasyncclient.construct - DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() - .build(); - SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("https://.servicebus.windows.net") - .credential(azureCredential) - .buildAsyncClient(); - // END: com.azure.data.schemaregistry.schemaregistryasyncclient.construct - } - - /** - * Updates retry policy and logging. - */ - public void retryPolicyAndLogging() { - // BEGIN: com.azure.data.schemaregistry.schemaregistryasyncclient.retrypolicy.construct - DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() - .build(); - - HttpLogOptions httpLogOptions = new HttpLogOptions() - .setLogLevel(HttpLogDetailLevel.BODY) - .setPrettyPrintBody(true); - - RetryPolicy retryPolicy = new RetryPolicy(new FixedDelay(5, Duration.ofSeconds(30))); - SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("https://.servicebus.windows.net") - .httpLogOptions(httpLogOptions) - .retryPolicy(retryPolicy) - .credential(azureCredential) - .buildAsyncClient(); - // END: com.azure.data.schemaregistry.schemaregistryasyncclient.retrypolicy.construct - } - - /** - * Shows how to register a schema. - */ - public void registerSchema() { - SchemaRegistryClient client = buildClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryclient.registerschema-avro - String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}"; - SchemaProperties properties = client.registerSchema("{schema-group}", "{schema-name}", schema, - SchemaFormat.AVRO); - - System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), properties.getFormat()); - // END: com.azure.data.schemaregistry.schemaregistryclient.registerschema-avro - } - - /** - * Shows how to register a schema using async client. - */ - public void registerSchemaAsync() { - SchemaRegistryAsyncClient client = buildAsyncClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryasyncclient.registerschema-avro - String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}"; - client.registerSchema("{schema-group}", "{schema-name}", schema, SchemaFormat.AVRO) - .subscribe(properties -> { - System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), - properties.getFormat()); - }, error -> { - System.err.println("Error occurred registering schema: " + error); - }, () -> { - System.out.println("Register schema completed."); - }); - // END: com.azure.data.schemaregistry.schemaregistryasyncclient.registerschema-avro - } - - /** - * Gets schema by id. - */ - public void getSchema() { - SchemaRegistryClient client = buildClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryclient.getschema - SchemaRegistrySchema schema = client.getSchema("{schema-id}"); - - System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(), - schema.getProperties().getFormat()); - System.out.println("Schema contents: " + schema.getDefinition()); - // END: com.azure.data.schemaregistry.schemaregistryclient.getschema - } - - /** - * Gets schema by name, group name, version. - */ - public void getSchemaWithResponse() { - SchemaRegistryClient client = buildClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryclient.getschemawithresponse - Response response = client.getSchemaWithResponse("{group-name}", - "{schema-name}", 1, Context.NONE); - - System.out.println("Headers in HTTP response: "); - response.getHeaders().forEach(header -> System.out.printf("%s: %s%n", header.getName(), header.getValue())); - - SchemaRegistrySchema schema = response.getValue(); - - System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(), - schema.getProperties().getFormat()); - System.out.println("Schema contents: " + schema.getDefinition()); - // END: com.azure.data.schemaregistry.schemaregistryclient.getschemawithresponse - } - - /** - * Gets schema by id using async client. - */ - public void getSchemaAsync() { - SchemaRegistryAsyncClient client = buildAsyncClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryasyncclient.getschema - client.getSchema("{schema-id}") - .subscribe(schema -> { - System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(), - schema.getProperties().getFormat()); - System.out.println("Schema contents: " + schema.getDefinition()); - }, error -> { - System.err.println("Error occurred getting schema: " + error); - }, () -> { - System.out.println("Get schema completed."); - }); - // END: com.azure.data.schemaregistry.schemaregistryasyncclient.getschema - } - - /** - * Gets schema by name, group name, version using async client. - */ - public void getSchemaWithResponseAsync() { - SchemaRegistryAsyncClient client = buildAsyncClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryasyncclient.getschemawithresponse - client.getSchemaWithResponse("{group-name}", "{schema-name}", 1) - .subscribe(response -> { - System.out.println("Headers in HTTP response: "); - - for (HttpHeader header : response.getHeaders()) { - System.out.printf("%s: %s%n", header.getName(), header.getValue()); - } - - SchemaRegistrySchema schema = response.getValue(); - - System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(), - schema.getProperties().getFormat()); - System.out.println("Schema contents: " + schema.getDefinition()); - }, error -> { - System.err.println("Error occurred getting schema: " + error); - }, () -> { - System.out.println("Get schema with response completed."); - }); - // END: com.azure.data.schemaregistry.schemaregistryasyncclient.getschemawithresponse - } - - /** - * Gets the schema properties. - */ - public void getSchemaProperties() { - SchemaRegistryClient client = buildClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryclient.getschemaproperties - String schemaContent = "{\n" - + " \"type\" : \"record\", \n" - + " \"namespace\" : \"SampleSchemaNameSpace\", \n" - + " \"name\" : \"Person\", \n" - + " \"fields\" : [\n" - + " { \n" - + " \"name\" : \"FirstName\" , \"type\" : \"string\" \n" - + " }, \n" - + " { \n" - + " \"name\" : \"LastName\", \"type\" : \"string\" \n" - + " }\n" - + " ]\n" - + "}"; - SchemaProperties properties = client.getSchemaProperties("{schema-group}", "{schema-name}", - schemaContent, SchemaFormat.AVRO); - - System.out.println("Schema id: " + properties.getId()); - System.out.println("Format: " + properties.getFormat()); - System.out.println("Version: " + properties.getVersion()); - // END: com.azure.data.schemaregistry.schemaregistryclient.getschemaproperties - } - - /** - * Gets the schema properties. - */ - public void getSchemaPropertiesAsync() { - SchemaRegistryAsyncClient client = buildAsyncClient(); - - // BEGIN: com.azure.data.schemaregistry.schemaregistryasyncclient.getschemaproperties - String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}"; - client.getSchemaProperties("{schema-group}", "{schema-name}", schema, SchemaFormat.AVRO) - .subscribe(properties -> { - System.out.println("Schema id: " + properties.getId()); - System.out.println("Format: " + properties.getFormat()); - System.out.println("Version: " + properties.getVersion()); - }, error -> { - System.err.println("Error occurred getting schema: " + error); - }, () -> { - System.out.println("Get schema completed."); - }); - // END: com.azure.data.schemaregistry.schemaregistryasyncclient.getschemaproperties - } - - private static SchemaRegistryAsyncClient buildAsyncClient() { - return new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint}") - .credential(new DefaultAzureCredentialBuilder().build()) - .buildAsyncClient(); - } - - private static SchemaRegistryClient buildClient() { - return new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace("{schema-registry-endpoint}") - .credential(new DefaultAzureCredentialBuilder().build()) - .buildClient(); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java deleted file mode 100644 index aea50c6c7593..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -/** - * Shared constants. - */ -class Constants { - static final int RESOURCE_LENGTH = 16; - - // When we regenerate recordings, make sure that the schema group matches what we are persisting. - static final String PLAYBACK_TEST_GROUP = "azsdk_java_group"; - - static final String PLAYBACK_ENDPOINT = "https://foo.servicebus.windows.net"; - - static final String SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE - = "SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE"; - - static final String SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE - = "SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE"; - - static final String SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE - = "SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"; - - static final String SCHEMA_REGISTRY_GROUP = "SCHEMA_REGISTRY_GROUP"; -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java deleted file mode 100644 index c6ed5a849061..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.AccessToken; -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpClient; -import com.azure.core.test.TestProxyTestBase; -import com.azure.core.test.http.AssertingHttpClientBuilder; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.identity.DefaultAzureCredentialBuilder; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import java.time.OffsetDateTime; - -import static com.azure.data.schemaregistry.Constants.PLAYBACK_ENDPOINT; -import static com.azure.data.schemaregistry.Constants.PLAYBACK_TEST_GROUP; -import static com.azure.data.schemaregistry.Constants.RESOURCE_LENGTH; -import static com.azure.data.schemaregistry.Constants.SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE; -import static com.azure.data.schemaregistry.Constants.SCHEMA_REGISTRY_GROUP; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class SchemaRegistryAsyncClientCustomTests extends TestProxyTestBase { - static final String SCHEMA_CONTENT = "Person: int, string, decimal"; - - private SchemaRegistryClientBuilder builder; - private SchemaRegistryAsyncClientTestsBase testBase; - - @Override - protected void beforeTest() { - TokenCredential tokenCredential; - String endpoint; - String schemaGroup; - if (interceptorManager.isPlaybackMode()) { - tokenCredential = tokenRequestContext -> Mono - .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); - schemaGroup = PLAYBACK_TEST_GROUP; - endpoint = PLAYBACK_ENDPOINT; - } else { - tokenCredential = new DefaultAzureCredentialBuilder().build(); - endpoint = System.getenv(SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE); - schemaGroup = System.getenv(SCHEMA_REGISTRY_GROUP); - - assertNotNull(endpoint, "'endpoint' cannot be null in LIVE/RECORD mode."); - assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); - } - - builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); - - if (interceptorManager.isPlaybackMode()) { - builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); - } else if (interceptorManager.isRecordMode()) { - builder.addPolicy(interceptorManager.getRecordPolicy()); - } - - testBase = new SchemaRegistryAsyncClientTestsBase(schemaGroup, SchemaFormat.CUSTOM); - } - - private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient).assertAsync() - .skipRequest((httpRequest, context) -> false) - .build(); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. - */ - @Test - public void registerAndGetSchema() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchema(client1, client2, schemaName, SCHEMA_CONTENT); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. Then add another version of it, and get - * that version. - */ - @Test - public void registerAndGetSchemaTwice() { - // Arrange - final String schemaContentModified = "Person: int, string, decimal, string"; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchemaTwice(client1, client2, schemaName, SCHEMA_CONTENT, schemaContentModified); - } - - /** - * Verifies that we can register a schema and then get it by its schema group, name, and content. - */ - @Test - public void registerAndGetSchemaId() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchemaId(client1, client2, schemaName, SCHEMA_CONTENT); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java deleted file mode 100644 index e616aa8653d7..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.AccessToken; -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpClient; -import com.azure.core.test.TestProxyTestBase; -import com.azure.core.test.http.AssertingHttpClientBuilder; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.identity.DefaultAzureCredentialBuilder; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import java.time.OffsetDateTime; - -import static com.azure.data.schemaregistry.Constants.PLAYBACK_ENDPOINT; -import static com.azure.data.schemaregistry.Constants.PLAYBACK_TEST_GROUP; -import static com.azure.data.schemaregistry.Constants.RESOURCE_LENGTH; -import static com.azure.data.schemaregistry.Constants.SCHEMA_REGISTRY_GROUP; -import static com.azure.data.schemaregistry.Constants.SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * Tests for {@link SchemaFormat#JSON} using {@link SchemaRegistryAsyncClient}. - */ -public class SchemaRegistryAsyncClientJsonTests extends TestProxyTestBase { - static final String SCHEMA_CONTENT = "{ \"$id\": \"https://example.com/person.schema.json\", " - + "\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", \"title\": \"Person\", \"type\": \"object\", " - + "\"properties\": { \"firstName\": { \"type\": \"string\", \"description\": \"The person's first name.\" }, " - + "\"lastName\": { \"type\": \"string\", \"description\": \"The person's last name.\" }, " - + "\"age\": { \"description\": \"Age in years which must be equal to or greater than zero.\", " - + "\"type\": \"integer\", \"minimum\": 0 } } }"; - - private SchemaRegistryClientBuilder builder; - private SchemaRegistryAsyncClientTestsBase testBase; - - @Override - protected void beforeTest() { - TokenCredential tokenCredential; - String endpoint; - String schemaGroup; - if (interceptorManager.isPlaybackMode()) { - tokenCredential = tokenRequestContext -> Mono - .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); - schemaGroup = PLAYBACK_TEST_GROUP; - endpoint = PLAYBACK_ENDPOINT; - } else { - tokenCredential = new DefaultAzureCredentialBuilder().build(); - endpoint = System.getenv(SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE); - schemaGroup = System.getenv(SCHEMA_REGISTRY_GROUP); - - assertNotNull(endpoint, "'endpoint' cannot be null in LIVE/RECORD mode."); - assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); - } - - builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); - - if (interceptorManager.isPlaybackMode()) { - builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); - } else if (interceptorManager.isRecordMode()) { - builder.addPolicy(interceptorManager.getRecordPolicy()); - } - - testBase = new SchemaRegistryAsyncClientTestsBase(schemaGroup, SchemaFormat.JSON); - } - - private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient).assertAsync() - .skipRequest((httpRequest, context) -> false) - .build(); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. - */ - @Test - public void registerAndGetSchema() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchema(client1, client2, schemaName, SCHEMA_CONTENT); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. Then add another version of it, and get - * that version. - */ - @Test - public void registerAndGetSchemaTwice() { - // Arrange - final String schemaContentModified = "{ \"$id\": \"https://example.com/person.schema.json\", " - + "\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", \"title\": \"Person\", " - + "\"type\": \"object\", \"properties\": { \"firstName\": { \"type\": \"string\", " - + "\"description\": \"The person's first name.\" }, \"lastName\": { \"type\": \"string\", " - + "\"description\": \"The person's last name.\" }, \"age\": { " - + "\"description\": \"Age in years which must be equal to or greater than 1.\", \"type\": \"integer\", " - + "\"minimum\": 1 } } }"; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchemaTwice(client1, client2, schemaName, SCHEMA_CONTENT, schemaContentModified); - } - - /** - * Verifies that we can register a schema and then get it by its schema group, name, and content. - */ - @Test - public void registerAndGetSchemaId() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchemaId(client1, client2, schemaName, SCHEMA_CONTENT); - } - - /** - * Verifies that an error is returned if we try to register an invalid schema. - */ - @Test - public void registerBadRequest() { - // Arrange - final String invalidContent = "{ \"$id\": \"https://example.com/person.schema.json\", " - + "\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", \"title\": 5\"Person2\", " - + "\"type\": \"object\", \"properties\": { \"firstName\": { \"type\": \"string\", " - + "\"description\": \"The person's first name.\" }, \"lastName\": { \"type\": \"string\", " - + "\"description\": \"The person's last name.\" }, \"age\": { " - + "\"description\": \"Age in years which must be equal to or greater than zero.\", \"type\": \"integer\", " - + "\"minimum\": 0 } } }"; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerBadRequest(client1, schemaName, invalidContent); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java deleted file mode 100644 index c28551a38935..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.AccessToken; -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpHeaders; -import com.azure.core.http.HttpResponse; -import com.azure.core.test.http.MockHttpResponse; -import com.azure.core.test.models.NetworkCallRecord; -import com.azure.core.test.models.RecordedData; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; -import com.azure.core.util.serializer.SerializerEncoding; -import com.azure.data.schemaregistry.models.SchemaFormat; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.time.OffsetDateTime; - -import static com.azure.data.schemaregistry.Constants.PLAYBACK_ENDPOINT; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * Tests that can only be played-back because they use a recording from the Portal or a back-compat issue that cannot be - * reproduced with the latest client. - */ -public class SchemaRegistryAsyncClientPlaybackTests { - private static final SerializerAdapter SERIALIZER = JacksonAdapter.createDefaultSerializerAdapter(); - private TokenCredential tokenCredential; - private String endpoint; - private RecordedData recordedData; - - @BeforeEach - public void setupTest(TestInfo testInfo) { - if (!testInfo.getTestMethod().isPresent()) { - throw new IllegalStateException( - "Expected testInfo.getTestMethod() not be empty since we need a method for TestContextManager."); - } - - this.tokenCredential = tokenRequestContext -> Mono - .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); - this.endpoint = PLAYBACK_ENDPOINT; - - final String resourceName = "/compat/" + testInfo.getTestMethod().get().getName() + ".json"; - - try (InputStream stream = SchemaRegistryAsyncClientPlaybackTests.class.getResourceAsStream(resourceName)) { - this.recordedData = SERIALIZER.deserialize(stream, RecordedData.class, SerializerEncoding.JSON); - } catch (IOException e) { - throw new UncheckedIOException("Unable to get resource input stream for: " + resourceName, e); - } - - assertNotNull(recordedData, "RecordedData should not be null. Resource: " + resourceName); - } - - /** - * This is run in playback mode because the GUID is unique for each schema. This is a schema that was previously - * registered in Azure Portal. - */ - @Test - public void getSchemaByIdFromPortal() { - - // Arrange - final HttpClient httpClientMock = setupHttpClient(recordedData); - final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder().fullyQualifiedNamespace(endpoint) - .credential(tokenCredential) - .httpClient(httpClientMock) - .serviceVersion(SchemaRegistryVersion.V2021_10) - .buildAsyncClient(); - final String schemaId = "f45b841fcb88401e961ca45477906be9"; - - // Act & Assert - StepVerifier.create(client.getSchema(schemaId)).assertNext(schema -> { - assertNotNull(schema.getProperties()); - assertEquals(schemaId, schema.getProperties().getId()); - assertEquals(SchemaFormat.AVRO, schema.getProperties().getFormat()); - }).verifyComplete(); - } - - /** - * Verifies that the new serializer works with 1.0.0 schema registry client. - * https://contral.sonatype.com/artifact/com.azure/azure-data-schemaregistry/1.0.0 - */ - @Test - public void getSchemaBackCompatibility() { - // Arrange - final HttpClient httpClientMock = setupHttpClient(recordedData); - - final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder().fullyQualifiedNamespace(endpoint) - .credential(tokenCredential) - .httpClient(httpClientMock) - .serviceVersion(SchemaRegistryVersion.V2021_10) - .buildAsyncClient(); - final String schemaId = "e5691f79e3964309ac712ec52abcccca"; - - // Act & Assert - StepVerifier.create(client.getSchema(schemaId)).assertNext(schema -> { - assertNotNull(schema.getProperties()); - assertEquals(schemaId, schema.getProperties().getId()); - assertEquals(SchemaFormat.AVRO, schema.getProperties().getFormat()); - }).verifyComplete(); - } - - private static HttpClient setupHttpClient(RecordedData recordedData) { - final NetworkCallRecord networkRecord = recordedData.findFirstAndRemoveNetworkCall(e -> true); - return request -> { - final String body = networkRecord.getResponse().remove("Body"); - final String statusCodeMessage = networkRecord.getResponse().remove("StatusCode"); - final int statusCode = Integer.parseInt(statusCodeMessage); - - assertNotNull(body, "Body cannot be null"); - - final HttpHeaders headers = new HttpHeaders(networkRecord.getResponse()); - - final HttpResponse response = new MockHttpResponse(request, statusCode, headers, body); - return Mono.just(response); - }; - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java deleted file mode 100644 index a6eb161ce9a4..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.AccessToken; -import com.azure.core.credential.TokenCredential; -import com.azure.core.exception.HttpResponseException; -import com.azure.core.exception.ResourceNotFoundException; -import com.azure.core.http.HttpClient; -import com.azure.core.test.TestProxyTestBase; -import com.azure.core.test.annotation.RecordWithoutRequestBody; -import com.azure.core.test.http.AssertingHttpClientBuilder; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.identity.DefaultAzureCredentialBuilder; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import java.time.Duration; -import java.time.OffsetDateTime; - -import static com.azure.data.schemaregistry.Constants.PLAYBACK_ENDPOINT; -import static com.azure.data.schemaregistry.Constants.PLAYBACK_TEST_GROUP; -import static com.azure.data.schemaregistry.Constants.RESOURCE_LENGTH; -import static com.azure.data.schemaregistry.Constants.SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE; -import static com.azure.data.schemaregistry.Constants.SCHEMA_REGISTRY_GROUP; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Tests for {@link SchemaFormat#AVRO} using {@link SchemaRegistryAsyncClient}. - */ -public class SchemaRegistryAsyncClientTests extends TestProxyTestBase { - static final String SCHEMA_CONTENT = "{\"type\" : \"record\",\"namespace\" : \"TestSchema\"," - + "\"name\" : \"Employee\",\"fields\" : [{ \"name\" : \"Name\" , \"type\" : \"string\" }," - + "{ \"name\" : \"Age\", \"type\" : \"int\" }]}"; - - private String schemaGroup; - private SchemaRegistryClientBuilder builder; - private SchemaRegistryAsyncClientTestsBase testBase; - - @Override - protected void beforeTest() { - TokenCredential tokenCredential; - String endpoint; - if (interceptorManager.isPlaybackMode()) { - tokenCredential = tokenRequestContext -> Mono - .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); - schemaGroup = PLAYBACK_TEST_GROUP; - endpoint = PLAYBACK_ENDPOINT; - } else { - tokenCredential = new DefaultAzureCredentialBuilder().build(); - endpoint = System.getenv(SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE); - schemaGroup = System.getenv(SCHEMA_REGISTRY_GROUP); - - assertNotNull(endpoint, "'endpoint' cannot be null in LIVE/RECORD mode."); - assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); - } - - builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); - - if (interceptorManager.isPlaybackMode()) { - builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); - } else if (interceptorManager.isRecordMode()) { - builder.addPolicy(interceptorManager.getRecordPolicy()); - } - - if (!interceptorManager.isLiveMode()) { - // Remove `name` sanitizers from the list of common sanitizers. - interceptorManager.removeSanitizers("AZSDK3493"); - } - - testBase = new SchemaRegistryAsyncClientTestsBase(schemaGroup, SchemaFormat.AVRO); - } - - private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient).assertAsync() - .skipRequest((httpRequest, context) -> false) - .build(); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. - */ - @Test - public void registerAndGetSchema() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchema(client1, client2, schemaName, SCHEMA_CONTENT); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. Then add another version of it, and get - * that version. - */ - @Test - public void registerAndGetSchemaTwice() { - // Arrange - final String schemaContentModified = "{\"type\" : \"record\",\"namespace\" : \"TestSchema\"," - + "\"name\" : \"Employee\",\"fields\" : [{ \"name\" : \"Name\" , \"type\" : \"string\" }," - + "{ \"name\" : \"Age\", \"type\" : \"int\" },{ \"name\" : \"Sign\", \"type\" : \"string\" }]}"; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchemaTwice(client1, client2, schemaName, SCHEMA_CONTENT, schemaContentModified); - } - - /** - * Verifies that we can register a schema and then get it by its schema group, name, and content. - */ - @Test - public void registerAndGetSchemaId() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerAndGetSchemaId(client1, client2, schemaName, SCHEMA_CONTENT); - } - - /** - * Verifies that a 4xx is returned if we use an invalid schema format. - */ - @Test - @RecordWithoutRequestBody - public void registerSchemaInvalidFormat() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client = builder.buildAsyncClient(); - final SchemaFormat unknownSchemaFormat = SchemaFormat.fromString("protobuf"); - - // Act & Assert - StepVerifier - .create(client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat)) - .expectErrorSatisfies(error -> { - assertTrue(error instanceof HttpResponseException); - - final HttpResponseException responseException = ((HttpResponseException) error); - assertEquals(415, responseException.getResponse().getStatusCode()); - }) - .verify(); - } - - /** - * Verifies that if we register a schema and try to fetch it using an invalid schema format, an error is returned. - */ - @Test - @RecordWithoutRequestBody - public void registerAndGetSchemaPropertiesWithInvalidFormat() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); - final SchemaFormat invalidFormat = SchemaFormat.fromString("protobuf"); - - final SchemaProperties schemaProperties - = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, SchemaFormat.AVRO) - .block(Duration.ofSeconds(10)); - - assertNotNull(schemaProperties); - - // Act & Assert - StepVerifier.create(client2.getSchemaProperties(schemaGroup, schemaName, SCHEMA_CONTENT, invalidFormat)) - .expectErrorSatisfies(error -> { - assertTrue(error instanceof HttpResponseException); - - final HttpResponseException responseException = ((HttpResponseException) error); - assertEquals(404, responseException.getResponse().getStatusCode()); - }) - .verify(); - } - - /** - * Verifies that an error is returned if we try to register an invalid schema. - */ - @Test - public void registerBadRequest() { - // Arrange - final String invalidContent = "\"{\"type\" : \"record\",\"namespace\" : \"TestSchema\"," - + "\"name\" : \"Employee\",\"fields\" : [{ \"name\" : \"Name\" , \"type\" : \"string\" }," - + "{ \"name\" : \"Age\" }]}\""; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - - // Act & Assert - testBase.registerBadRequest(client1, schemaName, invalidContent); - } - - /** - * Verifies that we get 404 when non-existent schema returned. - */ - @Test - public void getSchemaDoesNotExist() { - // Arrange - final String schemaId = "59f112cf-ff02-40e6-aca9-0d30ed7f7f94"; - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - - // Act & Assert - StepVerifier.create(client1.getSchema(schemaId)).expectErrorSatisfies(error -> { - assertTrue(error instanceof ResourceNotFoundException); - assertEquals(404, ((ResourceNotFoundException) error).getResponse().getStatusCode()); - }).verify(); - } - - /** - * Verifies that we get 404 when non-existent schema query is returned. - */ - @Test - public void getSchemaIdDoesNotExist() { - // Arrange - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - - // Act & Assert - StepVerifier.create(client1.getSchemaProperties(schemaGroup, "bar", SCHEMA_CONTENT, SchemaFormat.AVRO)) - .expectErrorSatisfies(error -> { - assertTrue(error instanceof ResourceNotFoundException); - assertEquals(404, ((ResourceNotFoundException) error).getResponse().getStatusCode()); - }) - .verify(); - } - - @Test - public void getSchemaByGroupNameVersion() { - // Arrange - final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - - // Register a schema first. - final SchemaProperties registeredSchema - = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, SchemaFormat.AVRO) - .block(Duration.ofSeconds(10)); - - assertNotNull(registeredSchema); - - // Act & Assert - StepVerifier.create(client1.getSchema(schemaGroup, schemaName, registeredSchema.getVersion())) - .assertNext(actual -> { - SchemaProperties properties = actual.getProperties(); - assertNotNull(properties); - - assertEquals(registeredSchema.getVersion(), properties.getVersion()); - assertEquals(schemaGroup, registeredSchema.getGroupName()); - assertEquals(schemaName, registeredSchema.getName()); - assertEquals(registeredSchema.getId(), properties.getId()); - }) - .expectComplete() - .verify(); - } - -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java deleted file mode 100644 index f87a4eef21e0..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.exception.HttpResponseException; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.data.schemaregistry.models.SchemaRegistrySchema; -import reactor.test.StepVerifier; - -import java.util.concurrent.atomic.AtomicReference; -import java.util.regex.Pattern; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Base class with common tests. - */ -class SchemaRegistryAsyncClientTestsBase { - static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+", Pattern.MULTILINE); - - private final String schemaGroup; - private final SchemaFormat schemaFormat; - - SchemaRegistryAsyncClientTestsBase(String schemaGroup, SchemaFormat schemaFormat) { - this.schemaGroup = schemaGroup; - this.schemaFormat = schemaFormat; - } - - /** - * 1. Registers a schema - * 2. Gets the schema - * 3. Verifies that the contents are the same. - */ - void registerAndGetSchema(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, String schemaName, - String schemaContent) { - - // Arrange - final String schemaContentNoWhitespace = WHITESPACE_PATTERN.matcher(schemaContent).replaceAll(""); - final AtomicReference schemaId = new AtomicReference<>(); - - // Act & Assert - StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, schemaContent, schemaFormat)) - .assertNext(response -> { - assertNotNull(response.getId()); - schemaId.set(response.getId()); - }) - .verifyComplete(); - - // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is - // cached, so it won't make a network call when getting the schema. client2 will not have this information. - final String schemaIdToGet = schemaId.get(); - assertNotNull(schemaIdToGet); - - // Act & Assert - StepVerifier.create(client2.getSchema(schemaIdToGet)).assertNext(schema -> { - assertNotNull(schema.getProperties()); - assertEquals(schemaIdToGet, schema.getProperties().getId()); - assertEquals(schemaFormat, schema.getProperties().getFormat()); - - // Replace white space. - final String actualContents = WHITESPACE_PATTERN.matcher(schema.getDefinition()).replaceAll(""); - assertEquals(schemaContentNoWhitespace, actualContents); - }).verifyComplete(); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. Then add another version of it, and get - * that version. - */ - void registerAndGetSchemaTwice(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, - String schemaName, String schemaContent, String schemaContentModified) { - - final AtomicReference schemaId = new AtomicReference<>(); - final AtomicReference schemaId2 = new AtomicReference<>(); - - // Act & Assert - StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, schemaContent, schemaFormat)) - .assertNext(response -> { - assertEquals(schemaFormat, response.getFormat()); - assertNotNull(response.getId()); - schemaId.set(response.getId()); - }) - .verifyComplete(); - - StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, schemaContentModified, schemaFormat)) - .assertNext(response -> { - assertEquals(schemaFormat, response.getFormat()); - assertNotNull(response.getId()); - schemaId2.set(response.getId()); - }) - .verifyComplete(); - - // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is - // cached, so it won't make a network call when getting the schema. client2 will not have this information. - assertNotEquals(schemaId.get(), schemaId2.get()); - - // Act & Assert - final String schemaIdToGet = schemaId2.get(); - StepVerifier.create(client2.getSchema(schemaIdToGet)) - .assertNext(schema -> assertSchemaRegistrySchema(schema, schemaIdToGet, schemaFormat, schemaContent)) - .verifyComplete(); - } - - /** - * Verifies that we can register a schema and then get it by its schema group, name, and content. - */ - void registerAndGetSchemaId(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, String schemaName, - String schemaContent) { - final AtomicReference schemaId = new AtomicReference<>(); - - // Act & Assert - StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, schemaContent, schemaFormat)) - .assertNext(response -> { - assertSchemaProperties(response, null, schemaFormat, schemaGroup, schemaName); - assertEquals(1, response.getVersion()); - schemaId.set(response.getId()); - }) - .verifyComplete(); - - // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is - // cached, so it won't make a network call when getting the schema. client2 will not have this information. - final String schemaIdToGet = schemaId.get(); - assertNotNull(schemaIdToGet); - - // Act & Assert - StepVerifier.create(client2.getSchemaProperties(schemaGroup, schemaName, schemaContent, schemaFormat)) - .assertNext(schema -> { - assertSchemaProperties(schema, schemaIdToGet, schemaFormat, schemaGroup, schemaName); - - // Should be the same version since we did not register a new one. - assertEquals(1, schema.getVersion()); - }) - .verifyComplete(); - } - - /** - * Verifies that an error is returned if we try to register an invalid schema. - */ - void registerBadRequest(SchemaRegistryAsyncClient client1, String schemaName, String invalidContent) { - // Act & Assert - StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, invalidContent, schemaFormat)) - .expectErrorSatisfies(error -> { - assertTrue(error instanceof HttpResponseException); - - final HttpResponseException exception = (HttpResponseException) error; - assertEquals(400, exception.getResponse().getStatusCode()); - }) - .verify(); - } - - /** - * Verifies the {@link SchemaRegistrySchema}. - * - * @param actual Result from service. - * @param expectedSchemaId Expected schema id. - * @param format Expected schema format. - * @param expectedContents Expected contents. - */ - static void assertSchemaRegistrySchema(SchemaRegistrySchema actual, String expectedSchemaId, SchemaFormat format, - String expectedContents) { - - assertNotEquals(expectedContents, "'expectedContents' should not be null."); - - assertEquals(format, actual.getProperties().getFormat()); - - assertNotNull(actual.getProperties().getId()); - - if (expectedSchemaId != null) { - assertEquals(expectedSchemaId, actual.getProperties().getId()); - } - - // Replace white space. - final String actualContents = WHITESPACE_PATTERN.matcher(actual.getDefinition()).replaceAll(""); - final String expectedContentsNoWhitespace = WHITESPACE_PATTERN.matcher(actualContents).replaceAll(""); - - assertEquals(expectedContentsNoWhitespace, actualContents); - } - - /** - * Verifies the {@link SchemaProperties}. - * - * @param actual Result from service. - * @param expectedSchemaId Expected schema id. - * @param schemaFormat Expected schema format. - * @param schemaGroup Expected group. - * @param schemaName Expected schema name. - */ - static void assertSchemaProperties(SchemaProperties actual, String expectedSchemaId, SchemaFormat schemaFormat, - String schemaGroup, String schemaName) { - assertNotNull(actual); - - if (expectedSchemaId != null) { - assertEquals(expectedSchemaId, actual.getId()); - } - - assertEquals(schemaGroup, actual.getGroupName()); - assertEquals(schemaName, actual.getName()); - assertEquals(schemaFormat, actual.getFormat()); - } - -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java deleted file mode 100644 index 45a93681ae7e..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.policy.ExponentialBackoffOptions; -import com.azure.core.http.policy.RetryOptions; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.test.http.MockHttpResponse; -import com.azure.core.test.utils.MockTokenCredential; -import com.azure.identity.ClientSecretCredential; -import com.azure.identity.ClientSecretCredentialBuilder; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * Unit tests for {@link SchemaRegistryClientBuilder}. - */ -public class SchemaRegistryClientBuilderTest { - @Test - public void testNullCredentials() { - assertThrows(NullPointerException.class, () -> new SchemaRegistryClientBuilder().buildAsyncClient()); - } - - @Test - public void testNullEndpoint() { - ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId("tenant-id") - .clientId("client-id") - .clientSecret("client-secret") - .build(); - assertThrows(NullPointerException.class, - () -> new SchemaRegistryClientBuilder().credential(credential).buildAsyncClient()); - } - - @Test - public void testInvalidEndpoint() { - // Arrange - final TokenCredential credential = new MockTokenCredential(); - - // Act & Assert - assertThrows(IllegalArgumentException.class, - () -> new SchemaRegistryClientBuilder().credential(credential) - .fullyQualifiedNamespace("") - .buildAsyncClient()); - } - - @Test - public void testSchemaRegistryClientCreation() { - - ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId("tenant-id") - .clientId("client-id") - .clientSecret("client-secret") - .build(); - - Assertions.assertNotNull(new SchemaRegistryClientBuilder().credential(credential) - .fullyQualifiedNamespace("https://localhost") - .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) - .buildAsyncClient()); - } - - @Test - public void bothRetryOptionsAndRetryPolicySet() { - ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId("tenant-id") - .clientId("client-id") - .clientSecret("client-secret") - .build(); - - assertThrows(IllegalStateException.class, - () -> new SchemaRegistryClientBuilder().credential(credential) - .fullyQualifiedNamespace("https://localhost") - .retryOptions(new RetryOptions(new ExponentialBackoffOptions())) - .retryPolicy(new RetryPolicy()) - .buildAsyncClient()); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java deleted file mode 100644 index 59a94297d591..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.schemaregistry; - -import com.azure.core.credential.AccessToken; -import com.azure.core.credential.TokenCredential; -import com.azure.core.credential.TokenRequestContext; -import com.azure.core.exception.HttpResponseException; -import com.azure.core.exception.ResourceNotFoundException; -import com.azure.core.http.HttpClient; -import com.azure.core.test.TestProxyTestBase; -import com.azure.core.test.annotation.RecordWithoutRequestBody; -import com.azure.core.test.http.AssertingHttpClientBuilder; -import com.azure.core.util.Context; -import com.azure.data.schemaregistry.models.SchemaFormat; -import com.azure.data.schemaregistry.models.SchemaProperties; -import com.azure.data.schemaregistry.models.SchemaRegistrySchema; -import com.azure.identity.DefaultAzureCredentialBuilder; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import java.time.OffsetDateTime; - -import static com.azure.data.schemaregistry.Constants.PLAYBACK_TEST_GROUP; -import static com.azure.data.schemaregistry.Constants.RESOURCE_LENGTH; -import static com.azure.data.schemaregistry.SchemaRegistryAsyncClientTests.SCHEMA_CONTENT; -import static com.azure.data.schemaregistry.SchemaRegistryAsyncClientTestsBase.assertSchemaProperties; -import static com.azure.data.schemaregistry.SchemaRegistryAsyncClientTestsBase.assertSchemaRegistrySchema; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * Tests {@link SchemaRegistryClient}. - */ -public class SchemaRegistryClientTests extends TestProxyTestBase { - - private String schemaGroup; - private SchemaRegistryClientBuilder builder; - - @Override - protected void beforeTest() { - final String endpoint; - TokenCredential tokenCredential; - if (interceptorManager.isPlaybackMode()) { - tokenCredential = new TokenCredential() { - @Override - public Mono getToken(TokenRequestContext tokenRequestContext) { - return Mono.fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); - } - - @Override - public AccessToken getTokenSync(TokenRequestContext request) { - return new AccessToken("foo", OffsetDateTime.now().plusMinutes(20)); - } - }; - schemaGroup = PLAYBACK_TEST_GROUP; - endpoint = "https://foo.servicebus.windows.net"; - } else { - tokenCredential = new DefaultAzureCredentialBuilder().build(); - endpoint = System.getenv(Constants.SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE); - schemaGroup = System.getenv(Constants.SCHEMA_REGISTRY_GROUP); - - assertNotNull(endpoint, "'endpoint' cannot be null in LIVE/RECORD mode."); - assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); - } - - builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); - - if (interceptorManager.isPlaybackMode()) { - builder.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient())); - } else if (interceptorManager.isRecordMode()) { - builder.addPolicy(interceptorManager.getRecordPolicy()); - } - } - - private HttpClient buildSyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient).assertSync() - .skipRequest((httpRequest, context) -> false) - .build(); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. - */ - @Test - public void registerAndGetSchema() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryClient client1 = builder.buildClient(); - final SchemaRegistryClient client2 = builder.buildClient(); - final SchemaFormat schemaFormat = SchemaFormat.AVRO; - - // Act - final SchemaProperties response = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, schemaFormat); - - // Assert - assertSchemaProperties(response, null, schemaFormat, schemaGroup, schemaName); - - // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is - // cached, so it won't make a network call when getting the schema. client2 will not have this information. - final String schemaIdToGet = response.getId(); - - // Act - final SchemaRegistrySchema schema1 = client2.getSchema(schemaIdToGet); - - // Assert - assertSchemaRegistrySchema(schema1, schemaIdToGet, schemaFormat, SCHEMA_CONTENT); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. Then add another version of it, and get - * that version. - */ - @Test - public void registerAndGetSchemaTwice() { - // Arrange - final String schemaContentModified = "{\"type\" : \"record\",\"namespace\" : \"TestSchema\"," - + "\"name\" : \"Employee\",\"fields\" : [{ \"name\" : \"Name\" , \"type\" : \"string\" }," - + "{ \"name\" : \"Age\", \"type\" : \"int\" },{ \"name\" : \"Sign\", \"type\" : \"string\" }]}"; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryClient client1 = builder.buildClient(); - final SchemaRegistryClient client2 = builder.buildClient(); - final SchemaFormat schemaFormat = SchemaFormat.AVRO; - - // Act & Assert - final SchemaProperties response = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, schemaFormat); - assertSchemaProperties(response, null, schemaFormat, schemaGroup, schemaName); - - // Expected that the second time we call this method, it will return a different schema because the contents - // are different. - final SchemaProperties response2 - = client1.registerSchema(schemaGroup, schemaName, schemaContentModified, schemaFormat); - assertSchemaProperties(response2, null, schemaFormat, schemaGroup, schemaName); - - // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is - // cached, so it won't make a network call when getting the schema. client2 will not have this information. - assertNotEquals(response.getId(), response2.getId()); - - // Act & Assert - final SchemaRegistrySchema response3 = client2.getSchema(response2.getId()); - assertSchemaRegistrySchema(response3, response2.getId(), schemaFormat, schemaContentModified); - } - - /** - * Verifies that we can register a schema and then get it by its schema group, name, and content. - */ - @Test - public void registerAndGetSchemaId() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryClient client1 = builder.buildClient(); - final SchemaRegistryClient client2 = builder.buildClient(); - final SchemaFormat schemaFormat = SchemaFormat.AVRO; - - // Act & Assert - final SchemaProperties response = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, schemaFormat); - assertSchemaProperties(response, null, schemaFormat, schemaGroup, schemaName); - - // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is - // cached, so it won't make a network call when getting the schema. client2 will not have this information. - final String schemaIdToGet = response.getId(); - assertNotNull(schemaIdToGet); - - // Act & Assert - final SchemaProperties schemaProperties - = client2.getSchemaProperties(schemaGroup, schemaName, SCHEMA_CONTENT, schemaFormat); - - assertEquals(schemaIdToGet, schemaProperties.getId()); - assertEquals(schemaFormat, schemaProperties.getFormat()); - } - - /** - * Verifies that we can register a schema and then get it by its schemaId. - */ - @Test - public void registerBadRequest() { - // Arrange - final String invalidContent = "\"{\"type\" : \"record\",\"namespace\" : \"TestSchema\"," - + "\"name\" : \"Employee\",\"fields\" : [{ \"name\" : \"Name\" , \"type\" : \"string\" }," - + "{ \"name\" : \"Age\" }]}\""; - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryClient client1 = builder.buildClient(); - - // Act - final HttpResponseException exception = assertThrows(HttpResponseException.class, - () -> client1.registerSchema(schemaGroup, schemaName, invalidContent, SchemaFormat.AVRO)); - - // Assert - assertEquals(400, exception.getResponse().getStatusCode()); - } - - /** - * Verifies that a 4xx is returned if we use an invalid schema format. - */ - - @Test - @RecordWithoutRequestBody - public void registerSchemaInvalidFormat() { - // Arrange - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryClient client = builder.buildClient(); - final SchemaFormat unknownSchemaFormat = SchemaFormat.fromString("protobuf"); - - // Act & Assert - HttpResponseException e = assertThrows(HttpResponseException.class, () -> client - .registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat, Context.NONE)); - assertEquals(415, e.getResponse().getStatusCode()); - } - - /** - * Verifies that we get 404 when non-existent schema returned. - */ - @Test - public void getSchemaDoesNotExist() { - // Arrange - final String schemaId = "59f112cf-ff02-40e6-aca9-0d30ed7f7f94"; - final SchemaRegistryClient client1 = builder.buildClient(); - - // Act & Assert - final ResourceNotFoundException error - = assertThrows(ResourceNotFoundException.class, () -> client1.getSchema(schemaId)); - - assertEquals(404, error.getResponse().getStatusCode()); - } - - /** - * Verifies that we get 404 when non-existent schema query is returned. - */ - @Test - public void getSchemaIdDoesNotExist() { - // Arrange - final SchemaRegistryClient client1 = builder.buildClient(); - - // Act & Assert - final ResourceNotFoundException error = assertThrows(ResourceNotFoundException.class, - () -> client1.getSchemaProperties(schemaGroup, "bar", SCHEMA_CONTENT, SchemaFormat.AVRO)); - - assertEquals(404, error.getResponse().getStatusCode()); - } - - @Test - public void getSchemaByGroupNameVersion() { - // Arrange - final SchemaRegistryClient client1 = builder.buildClient(); - final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - - // Register a schema first. - final SchemaProperties registeredSchema - = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, SchemaFormat.AVRO); - - assertNotNull(registeredSchema); - - // Act - final SchemaRegistrySchema actual = client1.getSchema(schemaGroup, schemaName, registeredSchema.getVersion()); - - // Assert - assertNotNull(schemaName); - - final SchemaProperties properties = actual.getProperties(); - assertNotNull(properties); - - assertEquals(registeredSchema.getVersion(), properties.getVersion()); - assertEquals(schemaGroup, registeredSchema.getGroupName()); - assertEquals(schemaName, registeredSchema.getName()); - assertEquals(registeredSchema.getId(), properties.getId()); - } -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/generated/SchemaRegistryClientTestBase.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/generated/SchemaRegistryClientTestBase.java new file mode 100644 index 000000000000..fee8e93cf91b --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/generated/SchemaRegistryClientTestBase.java @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.data.schemaregistry.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.test.utils.MockTokenCredential; +import com.azure.core.util.Configuration; +import com.azure.data.schemaregistry.SchemaRegistryClient; +import com.azure.data.schemaregistry.SchemaRegistryClientBuilder; +import com.azure.identity.DefaultAzureCredentialBuilder; + +class SchemaRegistryClientTestBase extends TestProxyTestBase { + protected SchemaRegistryClient schemaRegistryClient; + + @Override + protected void beforeTest() { + SchemaRegistryClientBuilder schemaRegistryClientbuilder = new SchemaRegistryClientBuilder() + .fullyQualifiedNamespace( + Configuration.getGlobalConfiguration().get("FULLYQUALIFIEDNAMESPACE", "fullyqualifiednamespace")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.PLAYBACK) { + schemaRegistryClientbuilder.credential(new MockTokenCredential()); + } else if (getTestMode() == TestMode.RECORD) { + schemaRegistryClientbuilder.addPolicy(interceptorManager.getRecordPolicy()) + .credential(new DefaultAzureCredentialBuilder().build()); + } else if (getTestMode() == TestMode.LIVE) { + schemaRegistryClientbuilder.credential(new DefaultAzureCredentialBuilder().build()); + } + schemaRegistryClient = schemaRegistryClientbuilder.buildClient(); + + } +} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/compat/getSchemaBackCompatibility.json b/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/compat/getSchemaBackCompatibility.json deleted file mode 100644 index 4a5fd0161d10..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/compat/getSchemaBackCompatibility.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "networkCallRecords" : [ { - "Method" : "GET", - "Uri" : "https://REDACTED.servicebus.windows.net/$schemaGroups/$schemas/e5691f79e3964309ac712ec52abcccca?api-version=2021-10", - "Headers" : { - "User-Agent" : "azsdk-java-azure-data-schemaregistry/1.0.0-beta.7 (11.0.5; Windows 10; 10.0)", - "x-ms-client-request-id" : "f68333f6-8f87-4b80-9cda-ac2ec096fa25" - }, - "Response" : { - "Transfer-Encoding" : "chunked", - "Schema-Version" : "1", - "Server" : "Microsoft-HTTPAPI/2.0", - "Schema-Name" : "sch17568204e", - "retry-after" : "0", - "Schema-Id-Location" : "https://conniey.servicebus.windows.net:443/$schemagroups/$schemas/e5691f79e3964309ac712ec52abcccca?api-version=2021-10", - "StatusCode" : "200", - "Date" : "Thu, 11 Nov 2021 02:50:18 GMT", - "Strict-Transport-Security" : "max-age=31536000", - "Schema-Id" : "e5691f79e3964309ac712ec52abcccca", - "Schema-Group-Name" : "mygroup", - "Body" : "\"{\\\"type\\\" : \\\"record\\\",\\\"namespace\\\" : \\\"TestSchema\\\",\\\"name\\\" : \\\"Employee\\\",\\\"fields\\\" : [{ \\\"name\\\" : \\\"Name\\\" , \\\"type\\\" : \\\"string\\\" },{ \\\"name\\\" : \\\"Age\\\", \\\"type\\\" : \\\"int\\\" }]}\"", - "Content-Type" : "application/json;serialization=Avro", - "Location" : "https://conniey.servicebus.windows.net:443/$schemagroups/mygroup/schemas/sch17568204e/versions/1?api-version=2021-10", - "Schema-Versions-Location" : "https://conniey.servicebus.windows.net:443/$schemagroups/mygroup/schemas/sch17568204e/versions?api-version=2021-10" - } - } ] -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/compat/getSchemaByIdFromPortal.json b/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/compat/getSchemaByIdFromPortal.json deleted file mode 100644 index 92771f14aa72..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/resources/compat/getSchemaByIdFromPortal.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "networkCallRecords" : [ { - "Method" : "GET", - "Uri" : "https://REDACTED.servicebus.windows.net/$schemaGroups/$schemas/f45b841fcb88401e961ca45477906be9?api-version=2021-10", - "Headers" : { - "User-Agent" : "azsdk-java-azure-data-schemaregistry/1.1.0-beta.1 (11.0.5; Windows 10; 10.0)", - "x-ms-client-request-id" : "b35c0b68-941c-4ab2-8d83-e8a7597a8290" - }, - "Response" : { - "Transfer-Encoding" : "chunked", - "Schema-Version" : "1", - "Server" : "Microsoft-HTTPAPI/2.0", - "Schema-Name" : "test", - "retry-after" : "0", - "Schema-Id-Location" : "https://conniey.servicebus.windows.net:443/$schemagroups/$schemas/f45b841fcb88401e961ca45477906be9?api-version=2021-10", - "StatusCode" : "200", - "Date" : "Tue, 04 Jan 2022 20:48:23 GMT", - "Strict-Transport-Security" : "max-age=31536000", - "Schema-Id" : "f45b841fcb88401e961ca45477906be9", - "Schema-Group-Name" : "mygroup", - "Body" : "{\"namespace\":\"SampleSchemaNameSpace\",\"type\":\"record\",\"name\":\"Person\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favourite_number\",\"type\":[\"int\",\"null\"]},{\"name\":\"favourite_colour\",\"type\":[\"string\",\"null\"]}]}", - "Content-Type" : "application/json;serialization=Avro", - "Location" : "https://conniey.servicebus.windows.net:443/$schemagroups/mygroup/schemas/test/versions/1?api-version=2021-10", - "Schema-Versions-Location" : "https://conniey.servicebus.windows.net:443/$schemagroups/mygroup/schemas/test/versions?api-version=2021-10" - } - } ] -} diff --git a/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md b/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md deleted file mode 100644 index cfc5a426b17e..000000000000 --- a/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md +++ /dev/null @@ -1,107 +0,0 @@ -# Azure Schema Registry for Java - -> see https://aka.ms/autorest - -### Setup - -> see https://github.com/Azure/autorest.java - -### Generation -> see https://github.com/Azure/autorest.java/releases for the latest version of autorest -```ps -cd -mvn install -autorest --java --use:@autorest/java@4.0.x -``` - -### Code generation settings -```yaml -use: '@autorest/java@4.1.24' -input-file: https://github.com/Azure/azure-rest-api-specs/blob/84d7b8f05a60d12922341578434b512540563850/specification/schemaregistry/data-plane/Microsoft.EventHub/stable/2023-07-01/schemaregistry.json -java: true -output-folder: ../ -namespace: com.azure.data.schemaregistry -generate-client-as-impl: true -service-interface-as-public: true -enable-sync-stack: true -generic-response-type: true -disable-client-builder: true -stream-style-serialization: true -license-header: MICROSOFT_MIT_SMALL -context-client-method-parameter: true -models-subpackage: implementation.models -``` - -### Add Content-Type header to GetById operation - -```yaml -directive: - from: swagger-document - where: $.paths["/$schemaGroups/{groupName}/schemas/{schemaName}:get-id"].post - transform: > - $.parameters.push({ - "name": "Content-Type", - "in": "header", - "description": "Content type of the schema.", - "required": true, - "type": "string", - "enum": [ - "application/json; serialization=Avro", - "application/json; serialization=Json", - "text/plain; charset=utf-8" - ], - "x-ms-enum": { - "name": "SchemaFormat", - "modelAsString": true - }}); -``` - -### Add Content-Type header to Register operation - -```yaml -directive: - from: swagger-document - where: $.paths["/$schemaGroups/{groupName}/schemas/{schemaName}"].put - transform: > - $.parameters.push({ - "name": "Content-Type", - "in": "header", - "description": "Content type of the schema.", - "required": true, - "type": "string"}); -``` - -### Enrich Content-Type header in response headers for operations returning the schema - -```yaml -directive: - from: swagger-document - where: $.paths["/$schemaGroups/$schemas/{id}"].get.responses["200"].headers - transform: > - $["Content-Type"]["enum"] = [ - "application/json; serialization=Avro", - "application/json; serialization=Json", - "text/plain; charset=utf-8" - ]; - $["Content-Type"]["x-ms-enum"] = { - "name": "SchemaFormat", - "modelAsString": true - }; -``` - -```yaml -directive: - from: swagger-document - where: $.paths["/$schemaGroups/{groupName}/schemas/{schemaName}/versions/{schemaVersion}"].get.responses["200"].headers - transform: > - $["Content-Type"]["enum"] = [ - "application/json; serialization=Avro", - "application/json; serialization=Json", - "text/plain; charset=utf-8" - ]; - $["Content-Type"]["x-ms-enum"] = { - "name": "SchemaFormat", - "modelAsString": true - }; -``` - diff --git a/sdk/schemaregistry/azure-data-schemaregistry/tsp-location.yaml b/sdk/schemaregistry/azure-data-schemaregistry/tsp-location.yaml new file mode 100644 index 000000000000..04eb3337b517 --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/schemaregistry/SchemaRegistry +commit: 8e89c3d0d28ca231e16c33c546978d28613bc4d4 +repo: test-repo-billy/azure-rest-api-specs +additionalDirectories: