From b7928db96f8fb379ddd7cdc40a814f85a3969d7a Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Mon, 12 Dec 2022 15:07:36 -0800 Subject: [PATCH 1/9] integrate sync stack in schema registry --- .../SchemaRegistryAsyncClient.java | 17 +- .../schemaregistry/SchemaRegistryClient.java | 128 +- .../SchemaRegistryClientBuilder.java | 12 +- .../AzureSchemaRegistryImplBuilder.java | 22 +- .../SchemaGroupsOperationsImpl.java | 88 ++ .../implementation/SchemaRegistryHelper.java | 19 +- .../implementation/SchemasImpl.java | 1067 +++++++++++++++-- .../implementation/models/Error.java | 3 + .../implementation/models/ErrorDetail.java | 3 + .../implementation/models/SchemaGroups.java | 3 + .../implementation/models/SchemaId.java | 3 + .../implementation/models/SchemaVersions.java | 3 + .../models/SchemasGetByIdHeaders.java | 28 +- .../SchemasGetSchemaVersionHeaders.java | 28 +- .../SchemasQueryIdByContentHeaders.java | 26 +- .../models/SchemasRegisterHeaders.java | 26 +- .../SchemaRegistryAsyncClientTests.java | 11 +- .../SchemaRegistryClientTests.java | 28 +- .../swagger/README.md | 3 +- 19 files changed, 1320 insertions(+), 198 deletions(-) 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 61dd48fb48fad..d6463bb7b1ae2 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 @@ -170,7 +170,7 @@ Mono> registerSchemaWithResponse(String groupName, St return restService.getSchemas().registerWithResponseAsync(groupName, name, binaryData, binaryData.getLength(), context) .map(response -> { - final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties(response); + final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), @@ -262,11 +262,11 @@ Mono> getSchemaWithResponse(String schemaId, Cont return this.restService.getSchemas().getByIdWithResponseAsync(schemaId, context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .handle((response, sink) -> { - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetByIdHeaders(response); final String schema; try { - schema = convertToString(response.getValue()); + schema = convertToString(response.getValue().toStream()); } catch (UncheckedIOException e) { sink.error(e); return; @@ -290,8 +290,8 @@ Mono> getSchemaWithResponse(String groupName, Str context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .handle((response, sink) -> { - final InputStream schemaInputStream = response.getValue(); - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response); + final InputStream schemaInputStream = response.getValue().toStream(); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(response); final String schema; if (schemaInputStream == null) { @@ -402,7 +402,7 @@ Mono> getSchemaPropertiesWithResponse(String groupNam .queryIdByContentWithResponseAsync(groupName, name, binaryData, binaryData.getLength(), context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .map(response -> { - final SchemaProperties properties = SchemaRegistryHelper.getSchemaProperties(response); + final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromSchemasQueryIdByContentHeaders(response); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), @@ -417,7 +417,7 @@ Mono> getSchemaPropertiesWithResponse(String groupNam * * @return The remapped error. */ - private static Throwable remapError(ErrorException error) { + static HttpResponseException remapError(ErrorException error) { if (error.getResponse().getStatusCode() == 404) { final String message; if (error.getValue() != null && error.getValue().getError() != null) { @@ -425,7 +425,6 @@ private static Throwable remapError(ErrorException error) { } else { message = error.getMessage(); } - return new ResourceNotFoundException(message, error.getResponse(), error); } @@ -441,7 +440,7 @@ private static Throwable remapError(ErrorException error) { * * @throws UncheckedIOException if an {@link IOException} is thrown when creating the readers. */ - private static String convertToString(InputStream inputStream) { + static String convertToString(InputStream inputStream) { final StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { 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 8fb045ebfdfd5..4ae1d19c571e9 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 @@ -9,12 +9,27 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.exception.ResourceNotFoundException; 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.SchemasRegisterHeaders; +import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentHeaders; import com.azure.data.schemaregistry.models.SchemaFormat; import com.azure.data.schemaregistry.models.SchemaProperties; import com.azure.data.schemaregistry.models.SchemaRegistrySchema; +import java.io.InputStream; import java.io.UncheckedIOException; +import java.util.Objects; + +import static com.azure.data.schemaregistry.SchemaRegistryAsyncClient.convertToString; /** * HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand. @@ -57,10 +72,16 @@ */ @ServiceClient(builder = SchemaRegistryClientBuilder.class) public final class SchemaRegistryClient { - private final SchemaRegistryAsyncClient asyncClient; + 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(SchemaRegistryAsyncClient asyncClient) { - this.asyncClient = asyncClient; + SchemaRegistryClient(AzureSchemaRegistryImpl restService) { + this.restService = restService; + + // So the accessor is initialised because there were NullPointerExceptions before. + new SchemaProperties("", SchemaFormat.AVRO); } /** @@ -69,7 +90,7 @@ public final class SchemaRegistryClient { * @return The fully qualified namespace of the Schema Registry instance. */ public String getFullyQualifiedNamespace() { - return asyncClient.getFullyQualifiedNamespace(); + return this.restService.getEndpoint(); } /** @@ -95,7 +116,7 @@ public String getFullyQualifiedNamespace() { @ServiceMethod(returns = ReturnType.SINGLE) public SchemaProperties registerSchema(String groupName, String name, String schemaDefinition, SchemaFormat format) { - return this.asyncClient.registerSchema(groupName, name, schemaDefinition, format).block(); + return registerSchemaWithResponse(groupName, name, schemaDefinition, format, Context.NONE).getValue(); } /** @@ -122,8 +143,27 @@ public SchemaProperties registerSchema(String groupName, String name, String sch @ServiceMethod(returns = ReturnType.SINGLE) public Response registerSchemaWithResponse(String groupName, String name, String schemaDefinition, SchemaFormat format, Context context) { - return this.asyncClient.registerSchemaWithResponse(groupName, name, schemaDefinition, format, - context).block(); + 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); + + context = enableSyncRestProxy(context); + final BinaryData binaryData = BinaryData.fromString(schemaDefinition); + + ResponseBase response = restService.getSchemas().registerWithResponse(groupName, name, binaryData, binaryData.getLength(), context); + final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response); + return new SimpleResponse<>( + response.getRequest(), response.getStatusCode(), + response.getHeaders(), registered); } /** @@ -140,7 +180,7 @@ public Response registerSchemaWithResponse(String groupName, S */ @ServiceMethod(returns = ReturnType.SINGLE) public SchemaRegistrySchema getSchema(String schemaId) { - return this.asyncClient.getSchema(schemaId).block(); + return getSchemaWithResponse(schemaId, Context.NONE).getValue(); } /** @@ -160,7 +200,7 @@ public SchemaRegistrySchema getSchema(String schemaId) { */ @ServiceMethod(returns = ReturnType.SINGLE) public SchemaRegistrySchema getSchema(String groupName, String schemaName, int schemaVersion) { - return this.asyncClient.getSchema(groupName, schemaName, schemaVersion).block(); + return getSchemaWithResponse(groupName, schemaName, schemaVersion, Context.NONE).getValue(); } /** @@ -178,7 +218,19 @@ public SchemaRegistrySchema getSchema(String groupName, String schemaName, int s */ @ServiceMethod(returns = ReturnType.SINGLE) public Response getSchemaWithResponse(String schemaId, Context context) { - return this.asyncClient.getSchemaWithResponse(schemaId, context).block(); + if (Objects.isNull(schemaId)) { + throw logger.logExceptionAsError(new NullPointerException("'schemaId' should not be null.")); + } + context = enableSyncRestProxy(context); + try { + ResponseBase response = this.restService.getSchemas().getByIdWithResponse(schemaId, context); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetByIdHeaders(response); + final String schema = convertToString(response.getValue().toStream()); + return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), + response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema)); + } catch (ErrorException ex) { + throw logger.logExceptionAsError(SchemaRegistryAsyncClient.remapError(ex)); + } } /** @@ -200,7 +252,26 @@ public Response getSchemaWithResponse(String schemaId, Con @ServiceMethod(returns = ReturnType.SINGLE) public Response getSchemaWithResponse(String groupName, String schemaName, int schemaVersion, Context context) { - return this.asyncClient.getSchemaWithResponse(groupName, schemaName, schemaVersion, context).block(); + if (Objects.isNull(groupName)) { + throw logger.logExceptionAsError(new NullPointerException("'groupName' should not be null.")); + } + context = enableSyncRestProxy(context); + + ResponseBase response = this.restService.getSchemas().getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, + context); + final InputStream schemaInputStream = response.getValue().toStream(); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(response); + final String schema; + + 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))); + } + schema = convertToString(schemaInputStream); + return new SimpleResponse<>( + response.getRequest(), response.getStatusCode(), + response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema)); } /** @@ -222,7 +293,7 @@ public Response getSchemaWithResponse(String groupName, St @ServiceMethod(returns = ReturnType.SINGLE) public SchemaProperties getSchemaProperties(String groupName, String name, String schemaDefinition, SchemaFormat format) { - return this.asyncClient.getSchemaProperties(groupName, name, schemaDefinition, format).block(); + return getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format, Context.NONE).getValue(); } /** @@ -245,7 +316,36 @@ public SchemaProperties getSchemaProperties(String groupName, String name, Strin @ServiceMethod(returns = ReturnType.SINGLE) public Response getSchemaPropertiesWithResponse(String groupName, String name, String schemaDefinition, SchemaFormat format, Context context) { - return this.asyncClient.getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format, context) - .block(); + 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; + } + context = enableSyncRestProxy(context); + + final BinaryData binaryData = BinaryData.fromString(schemaDefinition); + + try { + ResponseBase response = restService.getSchemas() + .queryIdByContentWithResponse(groupName, name, binaryData, binaryData.getLength(), context); + final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromSchemasQueryIdByContentHeaders(response); + return new SimpleResponse<>( + response.getRequest(), response.getStatusCode(), + response.getHeaders(), properties); + } catch (ErrorException ex) { + throw logger.logExceptionAsError(SchemaRegistryAsyncClient.remapError(ex)); + } + } + + private Context enableSyncRestProxy(Context context) { + return context.addData(HTTP_REST_PROXY_SYNC_PROXY_ENABLE, true); } } 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 e17b157dca1f3..2c6f22503743d 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 @@ -370,6 +370,12 @@ public SchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public SchemaRegistryAsyncClient buildAsyncClient() { + AzureSchemaRegistryImpl restService = getAzureSchemaREgistryImplService(); + + return new SchemaRegistryAsyncClient(restService); + } + + private AzureSchemaRegistryImpl getAzureSchemaREgistryImplService() { Objects.requireNonNull(credential, "'credential' cannot be null and must be set via builder.credential(TokenCredential)"); Objects.requireNonNull(fullyQualifiedNamespace, @@ -435,8 +441,7 @@ public SchemaRegistryAsyncClient buildAsyncClient() { .apiVersion(version.getVersion()) .pipeline(buildPipeline) .buildClient(); - - return new SchemaRegistryAsyncClient(restService); + return restService; } /** @@ -449,6 +454,7 @@ public SchemaRegistryAsyncClient buildAsyncClient() { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public SchemaRegistryClient buildClient() { - return new SchemaRegistryClient(this.buildAsyncClient()); + AzureSchemaRegistryImpl restService = getAzureSchemaREgistryImplService(); + return new SchemaRegistryClient(restService); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java index 6985850a6c4a8..51b35d894dc68 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** A builder for creating a new instance of the AzureSchemaRegistry type. */ @@ -48,7 +49,7 @@ public final class AzureSchemaRegistryImplBuilder @Generated private static final String SDK_VERSION = "version"; - @Generated private final Map properties = new HashMap<>(); + @Generated private static final Map PROPERTIES = new HashMap<>(); @Generated private final List pipelinePolicies; @@ -127,6 +128,7 @@ public AzureSchemaRegistryImplBuilder retryOptions(RetryOptions retryOptions) { @Generated @Override public AzureSchemaRegistryImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); pipelinePolicies.add(customPolicy); return this; } @@ -228,21 +230,17 @@ public AzureSchemaRegistryImpl buildClient() { private HttpPipeline createHttpPipeline() { Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; - if (httpLogOptions == null) { - httpLogOptions = new HttpLogOptions(); - } - if (clientOptions == null) { - clientOptions = new ClientOptions(); - } + 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(clientOptions, httpLogOptions); + 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 = new HttpHeaders(); - clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); + localClientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); if (headers.getSize() > 0) { policies.add(new AddHeadersPolicy(headers)); } @@ -264,7 +262,7 @@ private HttpPipeline createHttpPipeline() { new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) - .clientOptions(clientOptions) + .clientOptions(localClientOptions) .build(); return httpPipeline; } 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 index fafbf4c937430..64cb7ec399f94 100644 --- 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 @@ -17,6 +17,7 @@ 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; @@ -55,6 +56,32 @@ Mono> list( @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 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 Response} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listWithResponseAsync() { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context)); } /** @@ -74,4 +101,65 @@ public Mono> listWithResponseAsync(Context context) { final String accept = "application/json"; return service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, 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 on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono listAsync() { + return listWithResponseAsync().flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * 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 on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono listAsync(Context context) { + return listWithResponseAsync(context).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * 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 Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response listWithResponse(Context context) { + final String accept = "application/json"; + return service.listSync(this.client.getEndpoint(), this.client.getApiVersion(), accept, 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. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SchemaGroups list() { + return listWithResponse(Context.NONE).getValue(); + } } 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 index 289333f6e9c98..54e26945fa6b7 100644 --- 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 @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.azure.data.schemaregistry.implementation; +import com.azure.core.http.rest.ResponseBase; +import com.azure.core.util.BinaryData; import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdHeaders; import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdResponse; import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionHeaders; @@ -13,6 +15,7 @@ import com.azure.data.schemaregistry.models.SchemaFormat; import com.azure.data.schemaregistry.models.SchemaProperties; +import java.io.InputStream; import java.util.Objects; /** @@ -38,29 +41,29 @@ public static void setAccessor(SchemaRegistryModelsAccessor modelsAccessor) { accessor = Objects.requireNonNull(modelsAccessor, "'modelsAccessor' cannot be null."); } - public static SchemaProperties getSchemaProperties(SchemasRegisterResponse response) { - final SchemasRegisterHeaders headers = response.getDeserializedHeaders(); + public static SchemaProperties getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(ResponseBase response) { + final SchemasGetSchemaVersionHeaders headers = response.getDeserializedHeaders(); return accessor.getSchemaProperties(headers.getSchemaId(), SchemaFormat.AVRO, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); } - public static SchemaProperties getSchemaProperties(SchemasGetByIdResponse response) { - final SchemasGetByIdHeaders headers = response.getDeserializedHeaders(); + public static SchemaProperties getSchemaPropertiesFromSchemasQueryIdByContentHeaders(ResponseBase response) { + final SchemasQueryIdByContentHeaders headers = response.getDeserializedHeaders(); return accessor.getSchemaProperties(headers.getSchemaId(), SchemaFormat.AVRO, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); } - public static SchemaProperties getSchemaProperties(SchemasQueryIdByContentResponse response) { - final SchemasQueryIdByContentHeaders headers = response.getDeserializedHeaders(); + public static SchemaProperties getSchemaPropertiesFromSchemasGetByIdHeaders(ResponseBase response) { + final SchemasGetByIdHeaders headers = response.getDeserializedHeaders(); return accessor.getSchemaProperties(headers.getSchemaId(), SchemaFormat.AVRO, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); } - public static SchemaProperties getSchemaProperties(SchemasGetSchemaVersionResponse response) { - final SchemasGetSchemaVersionHeaders headers = response.getDeserializedHeaders(); + public static SchemaProperties getSchemaPropertiesFromSchemaRegisterHeaders(ResponseBase response) { + final SchemasRegisterHeaders headers = response.getDeserializedHeaders(); return accessor.getSchemaProperties(headers.getSchemaId(), SchemaFormat.AVRO, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); 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 index 309267d3348ce..c6d4eb30717d2 100644 --- 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 @@ -19,15 +19,17 @@ import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; 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.SchemaVersions; -import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdResponse; -import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionResponse; -import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentResponse; -import com.azure.data.schemaregistry.implementation.models.SchemasRegisterResponse; +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; @@ -60,7 +62,17 @@ public interface SchemasService { @Get("/$schemaGroups/$schemas/{id}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono getById( + 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}) + @UnexpectedResponseExceptionType(ErrorException.class) + ResponseBase getByIdSync( @HostParam("endpoint") String endpoint, @PathParam("id") String id, @QueryParam("api-version") String apiVersion, @@ -78,10 +90,33 @@ Mono> getVersions( @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}) + @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}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono getSchemaVersion( + ResponseBase getSchemaVersionSync( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @@ -96,7 +131,7 @@ Mono getSchemaVersion( value = ErrorException.class, code = {415}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono queryIdByContent( + Mono> queryIdByContent( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @@ -112,7 +147,23 @@ Mono queryIdByContent( value = ErrorException.class, code = {415}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono queryIdByContent( + Mono> queryIdByContent( + @HostParam("endpoint") String endpoint, + @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json; serialization=Avro") BinaryData schemaContent, + @HeaderParam("Content-Length") long contentLength, + @HeaderParam("Accept") String accept, + Context context); + + @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") + @ExpectedResponses({204}) + @UnexpectedResponseExceptionType( + value = ErrorException.class, + code = {415}) + @UnexpectedResponseExceptionType(ErrorException.class) + ResponseBase queryIdByContentSync( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @@ -128,7 +179,7 @@ Mono queryIdByContent( value = ErrorException.class, code = {415}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono register( + Mono> register( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @@ -144,7 +195,23 @@ Mono register( value = ErrorException.class, code = {415}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono register( + Mono> register( + @HostParam("endpoint") String endpoint, + @PathParam("groupName") String groupName, + @PathParam("schemaName") String schemaName, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json; serialization=Avro") BinaryData schemaContent, + @HeaderParam("Content-Length") long contentLength, + @HeaderParam("Accept") String accept, + Context context); + + @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") + @ExpectedResponses({204}) + @UnexpectedResponseExceptionType( + value = ErrorException.class, + code = {415}) + @UnexpectedResponseExceptionType(ErrorException.class) + ResponseBase registerSync( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @@ -155,6 +222,27 @@ Mono register( 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"; + return FluxUtil.withContext( + context -> + service.getById(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context)); + } + /** * Get a registered schema by its unique ID reference. * @@ -166,14 +254,86 @@ Mono register( * @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}. + * @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) { + public Mono> getByIdWithResponseAsync(String id, Context context) { final String accept = "application/json; serialization=Avro"; 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 Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ResponseBase getByIdWithResponse(String id, Context context) { + final String accept = "application/json; serialization=Avro"; + 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. * @@ -182,7 +342,6 @@ public Mono getByIdWithResponseAsync(String id, Context * @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. @@ -190,175 +349,857 @@ public Mono getByIdWithResponseAsync(String id, Context * Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getVersionsWithResponseAsync( - String groupName, String schemaName, Context context) { + public Mono> getVersionsWithResponseAsync(String groupName, String schemaName) { final String accept = "application/json"; - return service.getVersions( - this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), accept, context); + return FluxUtil.withContext( + context -> + service.getVersions( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + accept, + context)); } /** - * Get specific schema versions. + * Get list schema versions. * - *

Gets one specific version of one schema. + *

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 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}. + * @return the list of all versions of one schema along with {@link Response} on successful completion of {@link + * Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchemaVersionWithResponseAsync( - String groupName, String schemaName, int schemaVersion, Context context) { + public Mono> getVersionsWithResponseAsync( + String groupName, String schemaName, Context context) { final String accept = "application/json"; - return service.getSchemaVersion( - this.client.getEndpoint(), - groupName, - schemaName, - schemaVersion, - this.client.getApiVersion(), - accept, - context); + return service.getVersions( + this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), accept, context); } /** - * Get ID for existing schema. + * Get list schema versions. * - *

Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. + *

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 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 ErrorException thrown if the request is rejected by server on status code 415. * @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}. + * @return the list of all versions of one schema on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentWithResponseAsync( - String groupName, String schemaName, Flux schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.queryIdByContent( - this.client.getEndpoint(), - groupName, - schemaName, - this.client.getApiVersion(), - schemaContent, - contentLength, - accept, - context); + public Mono getVersionsAsync(String groupName, String schemaName) { + return getVersionsWithResponseAsync(groupName, schemaName).flatMap(res -> Mono.justOrEmpty(res.getValue())); } /** - * Get ID for existing schema. + * Get list schema versions. * - *

Gets the ID referencing an existing schema within the specified schema group, as matched by schema content - * comparison. + *

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 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 ErrorException thrown if the request is rejected by server on status code 415. * @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}. + * @return the list of all versions of one schema on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentWithResponseAsync( - String groupName, String schemaName, BinaryData schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.queryIdByContent( - this.client.getEndpoint(), - groupName, - schemaName, - this.client.getApiVersion(), - schemaContent, - contentLength, - accept, - context); + public Mono getVersionsAsync(String groupName, String schemaName, Context context) { + return getVersionsWithResponseAsync(groupName, schemaName, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); } /** - * Register new schema + * Get list schema versions. * - *

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. + *

Gets the list of all versions of one schema. * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. + * @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 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 ErrorException thrown if the request is rejected by server on status code 415. * @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. + * @return the list of all versions of one schema along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerWithResponseAsync( - String groupName, String schemaName, Flux schemaContent, long contentLength, Context context) { + public Response getVersionsWithResponse(String groupName, String schemaName, Context context) { final String accept = "application/json"; - return service.register( - this.client.getEndpoint(), - groupName, - schemaName, - this.client.getApiVersion(), - schemaContent, - contentLength, - accept, - context); + return service.getVersionsSync( + this.client.getEndpoint(), groupName, schemaName, this.client.getApiVersion(), accept, context); } /** - * Register new schema + * Get list schema versions. * - *

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. + *

Gets the list of all versions of one schema. * - * @param groupName Schema group under which schema should be registered. Group's serialization type should match - * the serialization type specified in the request. + * @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 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 ErrorException thrown if the request is rejected by server on status code 415. * @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. + * @return the list of all versions of one schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerWithResponseAsync( - String groupName, String schemaName, BinaryData schemaContent, long contentLength, Context context) { - final String accept = "application/json"; - return service.register( - this.client.getEndpoint(), - groupName, - schemaName, - this.client.getApiVersion(), - schemaContent, + public SchemaVersions getVersions(String groupName, String schemaName) { + return getVersionsWithResponse(groupName, schemaName, Context.NONE).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. + * @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"; + 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"; + 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 Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ResponseBase getSchemaVersionWithResponse( + String groupName, String schemaName, int schemaVersion, Context context) { + final String accept = "application/json"; + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.queryIdByContent( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength, Context context) { + final String accept = "application/json"; + return service.queryIdByContent( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength) { + return queryIdByContentWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength, Context context) { + return queryIdByContentWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.queryIdByContent( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength, Context context) { + final String accept = "application/json"; + return service.queryIdByContent( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength) { + return queryIdByContentWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength, Context context) { + return queryIdByContentWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength, Context context) { + final String accept = "application/json"; + return service.queryIdByContentSync( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength) { + queryIdByContentWithResponse(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.register( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength, Context context) { + final String accept = "application/json"; + return service.register( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength) { + return registerWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, Flux schemaContent, long contentLength, Context context) { + return registerWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.register( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength, Context context) { + final String accept = "application/json"; + return service.register( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength) { + return registerWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength, Context context) { + return registerWithResponseAsync(groupName, schemaName, 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength, Context context) { + final String accept = "application/json"; + return service.registerSync( + this.client.getEndpoint(), + groupName, + schemaName, + this.client.getApiVersion(), + 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 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 ErrorException thrown if the request is rejected by server on status code 415. + * @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, BinaryData schemaContent, long contentLength) { + registerWithResponse(groupName, schemaName, schemaContent, contentLength, Context.NONE); + } } 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 index 7f4d28fcfef60..5c543c61f2270 100644 --- 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 @@ -16,6 +16,9 @@ public final class Error { @JsonProperty(value = "error", required = true) private ErrorDetail error; + /** Creates an instance of Error class. */ + public Error() {} + /** * Get the error property: Error response returned from Azure Schema Registry service. * 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 index c1cec549d4170..112d79d762638 100644 --- 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 @@ -29,6 +29,9 @@ public final class ErrorDetail { @JsonProperty(value = "details") private List details; + /** Creates an instance of ErrorDetail class. */ + public ErrorDetail() {} + /** * Get the code property: Type of error. * 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 index e7de5f685e384..2a587cd173656 100644 --- 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 @@ -17,6 +17,9 @@ public final class SchemaGroups { @JsonProperty(value = "schemaGroups") private List schemaGroups; + /** Creates an instance of SchemaGroups class. */ + public SchemaGroups() {} + /** * Get the schemaGroups property: Array of schema groups. * 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 index 95c6a509358f3..e937dc6675f94 100644 --- 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 @@ -16,6 +16,9 @@ public final class SchemaId { @JsonProperty(value = "id") 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. * 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 index d981a6636e3b4..2c24119c40f4a 100644 --- 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 @@ -17,6 +17,9 @@ public final class SchemaVersions { @JsonProperty(value = "schemaVersions") private List schemaVersions; + /** Creates an instance of SchemaVersions class. */ + public SchemaVersions() {} + /** * Get the schemaVersions property: Array of schema groups. * 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 index 2db54c3b8d083..cce55e0060cc0 100644 --- 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 @@ -5,6 +5,7 @@ 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; import com.fasterxml.jackson.annotation.JsonProperty; @@ -53,6 +54,16 @@ public final class SchemasGetByIdHeaders { @JsonProperty(value = "Content-Type") private String 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. @@ -60,13 +71,16 @@ public final class SchemasGetByIdHeaders { * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public SchemasGetByIdHeaders(HttpHeaders rawHeaders) { - this.schemaVersion = Integer.parseInt(rawHeaders.getValue("Schema-Version")); - 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("Location"); - this.contentType = rawHeaders.getValue("Content-Type"); + 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); + this.contentType = rawHeaders.getValue(HttpHeaderName.CONTENT_TYPE); } /** 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 index 6958014397c5d..8f81460f75085 100644 --- 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 @@ -5,6 +5,7 @@ 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; import com.fasterxml.jackson.annotation.JsonProperty; @@ -53,6 +54,16 @@ public final class SchemasGetSchemaVersionHeaders { @JsonProperty(value = "Content-Type") private String 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. @@ -60,13 +71,16 @@ public final class SchemasGetSchemaVersionHeaders { * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public SchemasGetSchemaVersionHeaders(HttpHeaders rawHeaders) { - this.schemaVersion = Integer.parseInt(rawHeaders.getValue("Schema-Version")); - 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("Location"); - this.contentType = rawHeaders.getValue("Content-Type"); + 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); + this.contentType = rawHeaders.getValue(HttpHeaderName.CONTENT_TYPE); } /** 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 index 09f21395c1736..d95f4fceb8ed9 100644 --- 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 @@ -5,6 +5,7 @@ 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; import com.fasterxml.jackson.annotation.JsonProperty; @@ -47,6 +48,16 @@ public final class SchemasQueryIdByContentHeaders { @JsonProperty(value = "Location") 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. @@ -54,12 +65,15 @@ public final class SchemasQueryIdByContentHeaders { * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public SchemasQueryIdByContentHeaders(HttpHeaders rawHeaders) { - this.schemaVersion = Integer.parseInt(rawHeaders.getValue("Schema-Version")); - 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("Location"); + 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); } /** 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 index 5bec46ebb9837..c8483963825da 100644 --- 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 @@ -5,6 +5,7 @@ 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; import com.fasterxml.jackson.annotation.JsonProperty; @@ -47,6 +48,16 @@ public final class SchemasRegisterHeaders { @JsonProperty(value = "Location") 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. @@ -54,12 +65,15 @@ public final class SchemasRegisterHeaders { * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public SchemasRegisterHeaders(HttpHeaders rawHeaders) { - this.schemaVersion = Integer.parseInt(rawHeaders.getValue("Schema-Version")); - 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("Location"); + 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); } /** 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 index 15c0a0ea3aa8b..e6524afcf91cc 100644 --- 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 @@ -8,10 +8,12 @@ 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.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.test.TestBase; +import com.azure.core.test.http.AssertingHttpClientBuilder; import com.azure.data.schemaregistry.models.SchemaFormat; import com.azure.data.schemaregistry.models.SchemaProperties; import com.azure.data.schemaregistry.models.SchemaRegistrySchema; @@ -82,7 +84,7 @@ protected void beforeTest() { .fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { - builder.httpClient(interceptorManager.getPlaybackClient()); + builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); } else { builder.addPolicy(new RetryPolicy()) .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) @@ -90,6 +92,13 @@ protected void beforeTest() { } } + private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .assertAsync() + .skipRequest((httpRequest, context) -> false) + .build(); + } + @Override protected void afterTest() { Mockito.framework().clearInlineMock(this); 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 index 2d32584359520..ef6bd1bedb77d 100644 --- 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 @@ -8,8 +8,11 @@ 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.http.policy.RetryPolicy; import com.azure.core.test.TestBase; +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; @@ -17,7 +20,6 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; import java.time.OffsetDateTime; @@ -75,13 +77,20 @@ protected void beforeTest() { .fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { - builder.httpClient(interceptorManager.getPlaybackClient()); + builder.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient())); } else { builder.addPolicy(new RetryPolicy()) .addPolicy(interceptorManager.getRecordPolicy()); } } + private HttpClient buildSyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .assertSync() + .skipRequest((httpRequest, context) -> false) + .build(); + } + @Override protected void afterTest() { Mockito.framework().clearInlineMock(this); @@ -202,18 +211,15 @@ public void registerBadRequest() { public void registerSchemaInvalidFormat() { // Arrange final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client = builder.buildAsyncClient(); + final SchemaRegistryClient client = builder.buildClient(); 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(); + final HttpResponseException error = assertThrows(HttpResponseException.class, + () -> client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat, Context.NONE)); + + assertTrue(error instanceof HttpResponseException); + assertEquals(415, error.getResponse().getStatusCode()); } /** diff --git a/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md b/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md index 2b4dd6ab4ef6c..9f04e25f749eb 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md +++ b/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md @@ -22,10 +22,11 @@ output-folder: ../ namespace: com.azure.data.schemaregistry generate-client-as-impl: true service-interface-as-public: true -sync-methods: none +enable-sync-stack: true license-header: MICROSOFT_MIT_SMALL context-client-method-parameter: true models-subpackage: implementation.models +generic-response-type: true ``` From 39b248f53e7de093972114f677c783a91efb614b Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Sat, 17 Dec 2022 18:02:20 -0800 Subject: [PATCH 2/9] update --- .../azure/data/schemaregistry/implementation/SchemasImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index c6d4eb30717d2..31c4d518f37d9 100644 --- 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 @@ -309,7 +309,7 @@ public Mono getByIdAsync(String id, Context context) { * @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 Response}. + * @return a registered schema by its unique ID along with {@link ResponseBase}. */ @ServiceMethod(returns = ReturnType.SINGLE) public ResponseBase getByIdWithResponse(String id, Context context) { @@ -578,7 +578,7 @@ public Mono getSchemaVersionAsync( * @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 Response}. + * @return one specific version of one schema along with {@link ResponseBase}. */ @ServiceMethod(returns = ReturnType.SINGLE) public ResponseBase getSchemaVersionWithResponse( From 6bafa20e4820d9c8c8595dfce91fdf30b85034ce Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Thu, 5 Jan 2023 16:34:58 -0800 Subject: [PATCH 3/9] address feedback --- .../SchemaRegistryAsyncClient.java | 46 +++++++++++-------- .../models/SchemasGetByIdHeaders.java | 5 +- 2 files changed, 29 insertions(+), 22 deletions(-) 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 d6463bb7b1ae2..6d9363e17533b 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 @@ -20,6 +20,7 @@ import com.azure.data.schemaregistry.models.SchemaFormat; import com.azure.data.schemaregistry.models.SchemaProperties; import com.azure.data.schemaregistry.models.SchemaRegistrySchema; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.io.BufferedReader; @@ -27,6 +28,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UncheckedIOException; +import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Objects; @@ -289,30 +291,19 @@ Mono> getSchemaWithResponse(String groupName, Str return this.restService.getSchemas().getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion, context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) - .handle((response, sink) -> { - final InputStream schemaInputStream = response.getValue().toStream(); + .flatMap(response -> { + final Flux schemaFlux = response.getValue().toFluxByteBuffer(); final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(response); - final String schema; - if (schemaInputStream == null) { - sink.error(new IllegalArgumentException(String.format( + 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; - } - - try { - schema = convertToString(schemaInputStream); - } catch (UncheckedIOException e) { - sink.error(e); - return; } - - sink.next(new SimpleResponse<>( - response.getRequest(), response.getStatusCode(), - response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema))); - sink.complete(); + return convertToString(schemaFlux) + .map(schema -> new SimpleResponse<>( + response.getRequest(), response.getStatusCode(), + response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema))); }); } @@ -457,4 +448,21 @@ static String convertToString(InputStream inputStream) { return builder.toString(); } + + /** + * Converts a Flux of Byte Buffer into its string representation. + * + * @param byteBufferFlux the Byte Buffer Flux input. + * + * @return A string representation. + * + */ + static Mono convertToString(Flux byteBufferFlux) { + final StringBuilder builder = new StringBuilder(); + return byteBufferFlux + .map(byteBuffer -> { + builder.append(new String(byteBuffer.array(), StandardCharsets.UTF_8)); + return Mono.empty(); + }).then(Mono.defer(() -> Mono.just(builder.toString()))); + } } 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 index cce55e0060cc0..927e61057f5e6 100644 --- 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 @@ -72,9 +72,8 @@ public final class SchemasGetByIdHeaders { */ public SchemasGetByIdHeaders(HttpHeaders rawHeaders) { String schemaVersion = rawHeaders.getValue(SCHEMA_VERSION); - if (schemaVersion != null) { - this.schemaVersion = Integer.parseInt(schemaVersion); - } + //Note: AutoRest adds an if null check for schema version, which is hand-reverted here as it is a behavioural breaking change. + this.schemaVersion = Integer.parseInt(schemaVersion); this.schemaId = rawHeaders.getValue(SCHEMA_ID); this.schemaGroupName = rawHeaders.getValue(SCHEMA_GROUP_NAME); this.schemaName = rawHeaders.getValue(SCHEMA_NAME); From 47e3d0d4bafb7437a8c100b469f811ff9f2df988 Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Fri, 27 Jan 2023 18:40:24 -0800 Subject: [PATCH 4/9] regenerate and sync stack update --- .../SchemaRegistryAsyncClient.java | 37 +- .../schemaregistry/SchemaRegistryClient.java | 17 +- .../SchemaGroupsOperationsImpl.java | 202 +++++- .../implementation/SchemaRegistryHelper.java | 51 +- .../implementation/SchemasImpl.java | 638 ++++++++++++++++-- .../implementation/models/ErrorDetail.java | 1 - .../implementation/models/SchemaFormat.java | 43 ++ .../implementation/models/SchemaGroups.java | 4 - .../implementation/models/SchemaVersions.java | 4 - .../models/SchemasGetByIdHeaders.java | 36 +- .../models/SchemasGetByIdResponse.java | 18 +- .../SchemasGetSchemaVersionHeaders.java | 36 +- .../SchemasGetSchemaVersionResponse.java | 20 +- .../swagger/README.md | 104 +-- 14 files changed, 976 insertions(+), 235 deletions(-) create mode 100644 sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaFormat.java 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 cf64e22dee466..cb93ad0a760b9 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 @@ -154,7 +154,6 @@ public Mono> registerSchemaWithResponse(String groupN 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)) { @@ -171,14 +170,10 @@ Mono> registerSchemaWithResponse(String groupName, St final BinaryData binaryData = BinaryData.fromString(schemaDefinition); final SchemaFormatImpl contentType = SchemaRegistryHelper.getContentType(format); - return restService.getSchemas().registerWithResponseAsync(groupName, name, contentType, binaryData, + return restService.getSchemas().registerWithResponseAsync(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), context) .map(response -> { -//<<<<<<< HEAD -// final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response); -//======= - final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties(response, format); - + final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response, format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), registered); @@ -268,21 +263,12 @@ Mono> getSchemaWithResponse(String schemaId, Cont return this.restService.getSchemas().getByIdWithResponseAsync(schemaId, context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) - .handle((response, sink) -> { + .flatMap(response -> { final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetByIdHeaders(response); - final String schema; - - try { - schema = convertToString(response.getValue().toStream()); - } catch (UncheckedIOException e) { - sink.error(e); - return; - } - - sink.next(new SimpleResponse<>( + return convertToString(response.getValue()) + .map(schema -> new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema))); - sink.complete(); }); } @@ -297,8 +283,8 @@ Mono> getSchemaWithResponse(String groupName, Str context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .flatMap(response -> { - final Flux schemaFlux = response.getValue().toFluxByteBuffer(); - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(response); + final Flux schemaFlux = response.getValue(); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromGetSchemaVersionHeaders(response); if (schemaFlux == null) { return Mono.error(new IllegalArgumentException(String.format( @@ -396,15 +382,12 @@ Mono> getSchemaPropertiesWithResponse(String groupNam final SchemaFormatImpl contentType = SchemaRegistryHelper.getContentType(format); return restService.getSchemas() - .queryIdByContentWithResponseAsync(groupName, name, contentType, binaryData, binaryData.getLength(), + .queryIdByContentWithResponseAsync(groupName, name, com.azure.data.schemaregistry.implementation.models.SchemaFormat.fromString(contentType.toString()), + binaryData, binaryData.getLength(), context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .map(response -> { -<<<<<<< HEAD - final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromSchemasQueryIdByContentHeaders(response); -======= - final SchemaProperties properties = SchemaRegistryHelper.getSchemaProperties(response, format); ->>>>>>> upstream/main + final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromQueryByIdContentHeaders(response, format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), 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 4ae1d19c571e9..d4ad81f0f94de 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 @@ -17,10 +17,11 @@ 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.SchemasRegisterHeaders; import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentHeaders; +import com.azure.data.schemaregistry.implementation.models.SchemaFormatImpl; +import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdHeaders; +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; @@ -158,9 +159,10 @@ public Response registerSchemaWithResponse(String groupName, S context = enableSyncRestProxy(context); final BinaryData binaryData = BinaryData.fromString(schemaDefinition); + final SchemaFormatImpl contentType = SchemaRegistryHelper.getContentType(format); - ResponseBase response = restService.getSchemas().registerWithResponse(groupName, name, binaryData, binaryData.getLength(), context); - final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response); + ResponseBase response = restService.getSchemas().registerWithResponse(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), context); + final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response, format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), registered); @@ -260,7 +262,7 @@ public Response getSchemaWithResponse(String groupName, St ResponseBase response = this.restService.getSchemas().getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, context); final InputStream schemaInputStream = response.getValue().toStream(); - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(response); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromGetSchemaVersionHeaders(response); final String schema; if (schemaInputStream == null) { @@ -332,11 +334,12 @@ public Response getSchemaPropertiesWithResponse(String groupNa context = enableSyncRestProxy(context); final BinaryData binaryData = BinaryData.fromString(schemaDefinition); + final SchemaFormatImpl contentType = SchemaRegistryHelper.getContentType(format); try { ResponseBase response = restService.getSchemas() - .queryIdByContentWithResponse(groupName, name, binaryData, binaryData.getLength(), context); - final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromSchemasQueryIdByContentHeaders(response); + .queryIdByContentWithResponse(groupName, name, com.azure.data.schemaregistry.implementation.models.SchemaFormat.fromString(contentType.toString()), binaryData, binaryData.getLength(), context); + final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromQueryByIdContentHeaders(response, format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), properties); 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 index f51b115cbd602..411616d38b7ee 100644 --- 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 @@ -16,11 +16,13 @@ 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; @@ -60,6 +62,15 @@ Mono> list( @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) @@ -68,6 +79,42 @@ Mono> listNext( @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)); } /** @@ -108,7 +155,7 @@ public Mono> listSinglePageAsync(Context context) { */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listAsync() { - return listAsync(Context.NONE); + return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink)); } /** @@ -128,6 +175,110 @@ public PagedFlux listAsync(Context context) { () -> 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. * @@ -154,4 +305,53 @@ public Mono> listNextSinglePageAsync(String nextLink, Cont 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/SchemaRegistryHelper.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java index 094bb649f159d..74efc6be4e7e7 100644 --- 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 @@ -2,21 +2,13 @@ // Licensed under the MIT License. package com.azure.data.schemaregistry.implementation; -//<<<<<<< HEAD -//import com.azure.core.http.rest.ResponseBase; -//import com.azure.core.util.BinaryData; -//======= import com.azure.core.http.HttpHeaders; +import com.azure.core.http.rest.ResponseBase; import com.azure.data.schemaregistry.implementation.models.SchemaFormatImpl; -//>>>>>>> upstream/main import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdResponse; import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionResponse; import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentResponse; import com.azure.data.schemaregistry.implementation.models.SchemasRegisterHeaders; -import com.azure.data.schemaregistry.implementation.models.SchemasRegisterResponse; import com.azure.data.schemaregistry.models.SchemaFormat; import com.azure.data.schemaregistry.models.SchemaProperties; @@ -60,57 +52,34 @@ public static void setAccessor(SchemaRegistryModelsAccessor modelsAccessor) { accessor = Objects.requireNonNull(modelsAccessor, "'modelsAccessor' cannot be null."); } -//<<<<<<< HEAD -// public static SchemaProperties getSchemaPropertiesFromSchemasGetSchemaVersionHeaders(ResponseBase response) { -// final SchemasGetSchemaVersionHeaders headers = response.getDeserializedHeaders(); -//======= - public static SchemaProperties getSchemaProperties(SchemasRegisterResponse response, SchemaFormat fallbackFormat) { + public static SchemaProperties getSchemaPropertiesFromSchemaRegisterHeaders(ResponseBase response, SchemaFormat fallbackFormat) { final SchemasRegisterHeaders headers = response.getDeserializedHeaders(); final SchemaFormat responseFormat = getSchemaFormat(response.getHeaders()); final SchemaFormat schemaFormat = responseFormat != null ? responseFormat : fallbackFormat; -//>>>>>>> upstream/main return accessor.getSchemaProperties(headers.getSchemaId(), schemaFormat, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); } -//<<<<<<< HEAD -// public static SchemaProperties getSchemaPropertiesFromSchemasQueryIdByContentHeaders(ResponseBase response) { -// final SchemasQueryIdByContentHeaders headers = response.getDeserializedHeaders(); -//======= - public static SchemaProperties getSchemaProperties(SchemasGetByIdResponse response) { - final SchemasGetByIdHeaders headers = response.getDeserializedHeaders(); - final SchemaFormat schemaFormat = getSchemaFormat(response.getHeaders()); -//>>>>>>> upstream/main + public static SchemaProperties getSchemaPropertiesFromQueryByIdContentHeaders(ResponseBase response, SchemaFormat format) { + final SchemasQueryIdByContentHeaders headers = response.getDeserializedHeaders(); + final SchemaFormat responseFormat = getSchemaFormat(response.getHeaders()); + final SchemaFormat schemaFormat = responseFormat != null ? responseFormat : format; return accessor.getSchemaProperties(headers.getSchemaId(), schemaFormat, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); } -//<<<<<<< HEAD -// public static SchemaProperties getSchemaPropertiesFromSchemasGetByIdHeaders(ResponseBase response) { -// final SchemasGetByIdHeaders headers = response.getDeserializedHeaders(); -//======= - public static SchemaProperties getSchemaProperties(SchemasQueryIdByContentResponse response, - SchemaFormat fallbackFormat) { - - final SchemasQueryIdByContentHeaders headers = response.getDeserializedHeaders(); - final SchemaFormat responseFormat = getSchemaFormat(response.getHeaders()); - final SchemaFormat schemaFormat = responseFormat != null ? responseFormat : fallbackFormat; -//>>>>>>> upstream/main - + public static SchemaProperties getSchemaPropertiesFromSchemasGetByIdHeaders(ResponseBase response) { + final SchemasGetByIdHeaders headers = response.getDeserializedHeaders(); + final SchemaFormat schemaFormat = getSchemaFormat(response.getHeaders()); return accessor.getSchemaProperties(headers.getSchemaId(), schemaFormat, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); } -//<<<<<<< HEAD -// public static SchemaProperties getSchemaPropertiesFromSchemaRegisterHeaders(ResponseBase response) { -// final SchemasRegisterHeaders headers = response.getDeserializedHeaders(); -//======= - public static SchemaProperties getSchemaProperties(SchemasGetSchemaVersionResponse response) { + public static SchemaProperties getSchemaPropertiesFromGetSchemaVersionHeaders(ResponseBase response) { final SchemasGetSchemaVersionHeaders headers = response.getDeserializedHeaders(); final SchemaFormat schemaFormat = getSchemaFormat(response.getHeaders()); -//>>>>>>> upstream/main return accessor.getSchemaProperties(headers.getSchemaId(), schemaFormat, headers.getSchemaGroupName(), headers.getSchemaName(), headers.getSchemaVersion()); 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 index 1254d278433c1..57de8d8df7f24 100644 --- 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 @@ -19,26 +19,26 @@ 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.SchemaFormatImpl; +import com.azure.data.schemaregistry.implementation.models.SchemaFormat; import com.azure.data.schemaregistry.implementation.models.SchemaVersions; -import com.azure.data.schemaregistry.implementation.models.SchemasGetByIdResponse; -import com.azure.data.schemaregistry.implementation.models.SchemasGetSchemaVersionResponse; -import com.azure.data.schemaregistry.implementation.models.SchemasQueryIdByContentResponse; -import com.azure.data.schemaregistry.implementation.models.SchemasRegisterResponse; +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; -import java.io.InputStream; -import java.nio.ByteBuffer; - /** 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. */ @@ -67,7 +67,17 @@ public interface SchemasService { @Get("/$schemaGroups/$schemas/{id}") @ExpectedResponses({200, 200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono getById( + 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, @@ -85,10 +95,33 @@ Mono> getVersions( @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) - Mono getSchemaVersion( + ResponseBase getSchemaVersionSync( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @@ -100,12 +133,12 @@ Mono getSchemaVersion( @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono queryIdByContent( + Mono> queryIdByContent( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @QueryParam("api-version") String apiVersion, - @HeaderParam("Content-Type") SchemaFormatImpl contentType, + @HeaderParam("Content-Type") SchemaFormat contentType, @BodyParam("application/octet-stream") Flux schemaContent, @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, @@ -114,12 +147,26 @@ Mono queryIdByContent( @Post("/$schemaGroups/{groupName}/schemas/{schemaName}:get-id") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono queryIdByContent( + 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") SchemaFormatImpl contentType, + @HeaderParam("Content-Type") SchemaFormat contentType, @BodyParam("application/octet-stream") BinaryData schemaContent, @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, @@ -128,12 +175,12 @@ Mono queryIdByContent( @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono register( + Mono> register( @HostParam("endpoint") String endpoint, @PathParam("groupName") String groupName, @PathParam("schemaName") String schemaName, @QueryParam("api-version") String apiVersion, - @HeaderParam("Content-Type") SchemaFormatImpl contentType, + @HeaderParam("Content-Type") String contentType, @BodyParam("application/octet-stream") Flux schemaContent, @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, @@ -142,12 +189,26 @@ Mono register( @Put("/$schemaGroups/{groupName}/schemas/{schemaName}") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono register( + 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") SchemaFormatImpl contentType, + @HeaderParam("Content-Type") String contentType, @BodyParam("application/octet-stream") BinaryData schemaContent, @HeaderParam("Content-Length") long contentLength, @HeaderParam("Accept") String accept, @@ -161,6 +222,15 @@ Mono> getVersionsNext( @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); } /** @@ -173,10 +243,11 @@ Mono> getVersionsNext( * @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}. + * @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) { + public Mono>> getByIdWithResponseAsync(String id) { final String accept = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8"; return FluxUtil.withContext( @@ -195,10 +266,12 @@ public Mono getByIdWithResponseAsync(String id) { * @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}. + * @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) { + public Mono>> getByIdWithResponseAsync( + String id, Context context) { final String accept = "application/json; serialization=Avro, application/json; serialization=json, text/plain; charset=utf-8"; return service.getById(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context); @@ -217,7 +290,7 @@ public Mono getByIdWithResponseAsync(String id, Context * @return a registered schema by its unique ID on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getByIdAsync(String id) { + public Mono> getByIdAsync(String id) { return getByIdWithResponseAsync(id).flatMap(res -> Mono.justOrEmpty(res.getValue())); } @@ -235,10 +308,84 @@ public Mono getByIdAsync(String id) { * @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) { + 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"; + 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. * @@ -286,7 +433,9 @@ public Mono> getVersionsSinglePageAsync( */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux getVersionsAsync(String groupName, String schemaName) { - return getVersionsAsync(groupName, schemaName, Context.NONE); + return new PagedFlux<>( + () -> getVersionsSinglePageAsync(groupName, schemaName), + nextLink -> getVersionsNextSinglePageAsync(nextLink)); } /** @@ -310,6 +459,109 @@ public PagedFlux getVersionsAsync(String groupName, String schemaName, 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. * @@ -322,10 +574,11 @@ public PagedFlux getVersionsAsync(String groupName, String schemaName, * @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}. + * @return one specific version of one schema along with {@link ResponseBase} on successful completion of {@link + * Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchemaVersionWithResponseAsync( + 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"; @@ -354,10 +607,11 @@ public Mono getSchemaVersionWithResponseAsync( * @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}. + * @return one specific version of one schema along with {@link ResponseBase} on successful completion of {@link + * Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchemaVersionWithResponseAsync( + 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"; @@ -386,7 +640,7 @@ public Mono getSchemaVersionWithResponseAsync( * @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) { + public Mono> getSchemaVersionAsync(String groupName, String schemaName, int schemaVersion) { return getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion) .flatMap(res -> Mono.justOrEmpty(res.getValue())); } @@ -407,12 +661,61 @@ public Mono getSchemaVersionAsync(String groupName, String schemaNa * @return one specific version of one schema on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchemaVersionAsync( + 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"; + 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. * @@ -429,13 +732,13 @@ public Mono getSchemaVersionAsync( * @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}. + * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentWithResponseAsync( + public Mono> queryIdByContentWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, Flux schemaContent, long contentLength) { final String accept = "application/json"; @@ -470,13 +773,13 @@ public Mono queryIdByContentWithResponseAsync( * @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}. + * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentWithResponseAsync( + public Mono> queryIdByContentWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, Flux schemaContent, long contentLength, Context context) { @@ -515,7 +818,7 @@ public Mono queryIdByContentWithResponseAsync( public Mono queryIdByContentAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, Flux schemaContent, long contentLength) { return queryIdByContentWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) @@ -545,7 +848,7 @@ public Mono queryIdByContentAsync( public Mono queryIdByContentAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, Flux schemaContent, long contentLength, Context context) { @@ -570,13 +873,13 @@ public Mono queryIdByContentAsync( * @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}. + * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentWithResponseAsync( + public Mono> queryIdByContentWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, BinaryData schemaContent, long contentLength) { final String accept = "application/json"; @@ -611,13 +914,13 @@ public Mono queryIdByContentWithResponseAsync( * @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}. + * comparison along with {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono queryIdByContentWithResponseAsync( + public Mono> queryIdByContentWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, BinaryData schemaContent, long contentLength, Context context) { @@ -656,7 +959,7 @@ public Mono queryIdByContentWithResponseAsync( public Mono queryIdByContentAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, BinaryData schemaContent, long contentLength) { return queryIdByContentWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) @@ -686,7 +989,7 @@ public Mono queryIdByContentAsync( public Mono queryIdByContentAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + SchemaFormat contentType, BinaryData schemaContent, long contentLength, Context context) { @@ -695,6 +998,72 @@ public Mono queryIdByContentAsync( .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 * @@ -711,13 +1080,13 @@ public Mono queryIdByContentAsync( * @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. + * @return the {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerWithResponseAsync( + public Mono> registerWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + String contentType, Flux schemaContent, long contentLength) { final String accept = "application/json"; @@ -752,13 +1121,13 @@ public Mono registerWithResponseAsync( * @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. + * @return the {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerWithResponseAsync( + public Mono> registerWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + String contentType, Flux schemaContent, long contentLength, Context context) { @@ -797,7 +1166,7 @@ public Mono registerWithResponseAsync( public Mono registerAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + String contentType, Flux schemaContent, long contentLength) { return registerWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) @@ -827,7 +1196,7 @@ public Mono registerAsync( public Mono registerAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + String contentType, Flux schemaContent, long contentLength, Context context) { @@ -851,12 +1220,11 @@ public Mono registerAsync( * @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. + * @return the {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerWithResponseAsync( - String groupName, String schemaName, SchemaFormatImpl contentType, BinaryData schemaContent, - long contentLength) { + public Mono> registerWithResponseAsync( + String groupName, String schemaName, String contentType, BinaryData schemaContent, long contentLength) { final String accept = "application/json"; return FluxUtil.withContext( context -> @@ -889,13 +1257,13 @@ public Mono registerWithResponseAsync( * @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. + * @return the {@link ResponseBase} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerWithResponseAsync( + public Mono> registerWithResponseAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + String contentType, BinaryData schemaContent, long contentLength, Context context) { @@ -932,8 +1300,7 @@ public Mono registerWithResponseAsync( */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono registerAsync( - String groupName, String schemaName, SchemaFormatImpl contentType, BinaryData schemaContent, - long contentLength) { + String groupName, String schemaName, String contentType, BinaryData schemaContent, long contentLength) { return registerWithResponseAsync(groupName, schemaName, contentType, schemaContent, contentLength) .flatMap(ignored -> Mono.empty()); } @@ -961,7 +1328,7 @@ public Mono registerAsync( public Mono registerAsync( String groupName, String schemaName, - SchemaFormatImpl contentType, + String contentType, BinaryData schemaContent, long contentLength, Context context) { @@ -969,6 +1336,96 @@ public Mono registerAsync( .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. * @@ -995,4 +1452,55 @@ public Mono> getVersionsNextSinglePageAsync(String nextLi 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/ErrorDetail.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/ErrorDetail.java index 3bdfee6af6760..2360ffc74ac4a 100644 --- 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 @@ -6,7 +6,6 @@ import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; /** Error response returned from Azure Schema Registry service. */ 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 new file mode 100644 index 0000000000000..f881c3f65f7f6 --- /dev/null +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemaFormat.java @@ -0,0 +1,43 @@ +// 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 com.fasterxml.jackson.annotation.JsonCreator; +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 or finds a SchemaFormat from its string representation. + * + * @param name a name to look for. + * @return the corresponding SchemaFormat. + */ + @JsonCreator + 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 index 3fccde49f3a5a..3100847a735f9 100644 --- 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 @@ -6,7 +6,6 @@ import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; /** Object received from the registry containing the list of schema groups and link to next batch page. */ @@ -47,9 +46,6 @@ public SchemaGroups setGroups(List groups) { return this; } - /** Creates an instance of SchemaGroups class. */ - public SchemaGroups() {} - /** * Get the nextLink property: URl to next batch of schema groups. * 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 index c1405da84fed0..f627d97b97684 100644 --- 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 @@ -6,7 +6,6 @@ import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; /** Object received from the registry containing the list of schema versions and link to next batch page. */ @@ -47,9 +46,6 @@ public SchemaVersions setVersions(List versions) { return this; } - /** Creates an instance of SchemaVersions class. */ - public SchemaVersions() {} - /** * Get the nextLink property: URl to next batch of schema versions. * 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 index 0b5f91d3d4b79..c5ea8fcf4be1d 100644 --- 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 @@ -5,6 +5,7 @@ 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; import com.fasterxml.jackson.annotation.JsonProperty; @@ -51,7 +52,17 @@ public final class SchemasGetByIdHeaders { * The Content-Type property. */ @JsonProperty(value = "Content-Type") - private SchemaFormatImpl contentType; + 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. /** @@ -60,15 +71,18 @@ public final class SchemasGetByIdHeaders { * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public SchemasGetByIdHeaders(HttpHeaders rawHeaders) { - this.schemaVersion = Integer.parseInt(rawHeaders.getValue("Schema-Version")); - 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("Location"); - String contentType = rawHeaders.getValue("Content-Type"); + 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 = SchemaFormatImpl.fromString(contentType); + this.contentType = SchemaFormat.fromString(contentType); } } @@ -197,7 +211,7 @@ public SchemasGetByIdHeaders setLocation(String location) { * * @return the contentType value. */ - public SchemaFormatImpl getContentType() { + public SchemaFormat getContentType() { return this.contentType; } @@ -207,7 +221,7 @@ public SchemaFormatImpl getContentType() { * @param contentType the contentType value to set. * @return the SchemasGetByIdHeaders object itself. */ - public SchemasGetByIdHeaders setContentType(SchemaFormatImpl contentType) { + 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/SchemasGetByIdResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java index c245726cd8927..76541072fa8fb 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java @@ -7,11 +7,13 @@ import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; import com.azure.core.http.rest.ResponseBase; - -import java.io.InputStream; +import java.io.Closeable; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; /** Contains all response data for the getById operation. */ -public final class SchemasGetByIdResponse extends ResponseBase { +public final class SchemasGetByIdResponse extends ResponseBase> + implements Closeable { /** * Creates an instance of SchemasGetByIdResponse. * @@ -25,7 +27,7 @@ public SchemasGetByIdResponse( HttpRequest request, int statusCode, HttpHeaders rawHeaders, - InputStream value, + Flux value, SchemasGetByIdHeaders headers) { super(request, statusCode, rawHeaders, value, headers); } @@ -36,7 +38,13 @@ public SchemasGetByIdResponse( * @return the response content stream. */ @Override - public InputStream getValue() { + public Flux getValue() { return super.getValue(); } + + /** Disposes of the connection associated with this stream response. */ + @Override + public void close() { + getValue().subscribe(bb -> {}, t -> {}).dispose(); + } } 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 index c78c688268c76..a0fd52cab5a82 100644 --- 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 @@ -5,6 +5,7 @@ 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; import com.fasterxml.jackson.annotation.JsonProperty; @@ -51,7 +52,17 @@ public final class SchemasGetSchemaVersionHeaders { * The Content-Type property. */ @JsonProperty(value = "Content-Type") - private SchemaFormatImpl contentType; + 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. /** @@ -60,15 +71,18 @@ public final class SchemasGetSchemaVersionHeaders { * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public SchemasGetSchemaVersionHeaders(HttpHeaders rawHeaders) { - this.schemaVersion = Integer.parseInt(rawHeaders.getValue("Schema-Version")); - 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("Location"); - String contentType = rawHeaders.getValue("Content-Type"); + 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 = SchemaFormatImpl.fromString(contentType); + this.contentType = SchemaFormat.fromString(contentType); } } @@ -197,7 +211,7 @@ public SchemasGetSchemaVersionHeaders setLocation(String location) { * * @return the contentType value. */ - public SchemaFormatImpl getContentType() { + public SchemaFormat getContentType() { return this.contentType; } @@ -207,7 +221,7 @@ public SchemaFormatImpl getContentType() { * @param contentType the contentType value to set. * @return the SchemasGetSchemaVersionHeaders object itself. */ - public SchemasGetSchemaVersionHeaders setContentType(SchemaFormatImpl contentType) { + 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/SchemasGetSchemaVersionResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java index d248c4c46ab54..8bd5cb7764d13 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java @@ -7,25 +7,27 @@ import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; import com.azure.core.http.rest.ResponseBase; - -import java.io.InputStream; +import java.io.Closeable; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; /** Contains all response data for the getSchemaVersion operation. */ -public final class SchemasGetSchemaVersionResponse extends ResponseBase { +public final class SchemasGetSchemaVersionResponse + extends ResponseBase> implements Closeable { /** * Creates an instance of SchemasGetSchemaVersionResponse. * * @param request the request which resulted in this SchemasGetSchemaVersionResponse. * @param statusCode the status code of the HTTP response. * @param rawHeaders the raw headers of the HTTP response. - * @param value the deserialized value of the HTTP response. + * @param value the content stream. * @param headers the deserialized headers of the HTTP response. */ public SchemasGetSchemaVersionResponse( HttpRequest request, int statusCode, HttpHeaders rawHeaders, - InputStream value, + Flux value, SchemasGetSchemaVersionHeaders headers) { super(request, statusCode, rawHeaders, value, headers); } @@ -36,7 +38,13 @@ public SchemasGetSchemaVersionResponse( * @return the response content stream. */ @Override - public InputStream getValue() { + public Flux getValue() { return super.getValue(); } + + /** Disposes of the connection associated with this stream response. */ + @Override + public void close() { + getValue().subscribe(bb -> {}, t -> {}).dispose(); + } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md b/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md index 9443ba827e4cd..b5fff13c43643 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md +++ b/sdk/schemaregistry/azure-data-schemaregistry/swagger/README.md @@ -23,82 +23,82 @@ namespace: com.azure.data.schemaregistry generate-client-as-impl: true service-interface-as-public: true enable-sync-stack: true +generic-response-type: true license-header: MICROSOFT_MIT_SMALL context-client-method-parameter: true models-subpackage: implementation.models -generic-response-type: true ``` ### 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 - }}); + 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"}); + 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 - }; + 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 - }; + 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 + }; ``` From 25bbe5c02a1c5c4805f43f36f603802f17814aad Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Tue, 21 Feb 2023 01:48:01 -0800 Subject: [PATCH 5/9] regenerate sync stack post autorest bug fix --- .../AzureSchemaRegistryImplBuilder.java | 15 ++++++-------- .../implementation/models/SchemaFormat.java | 8 ++++++++ .../models/SchemasGetByIdResponse.java | 18 +++++------------ .../SchemasGetSchemaVersionResponse.java | 20 ++++++------------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java index 54ab600661d19..ef37706cf6218 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/AzureSchemaRegistryImplBuilder.java @@ -37,7 +37,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; /** A builder for creating a new instance of the AzureSchemaRegistry type. */ @ServiceClientBuilder(serviceClients = {AzureSchemaRegistryImpl.class}) @@ -244,18 +243,16 @@ private HttpPipeline createHttpPipeline() { if (headers.getSize() > 0) { policies.add(new AddHeadersPolicy(headers)); } - policies.addAll( - this.pipelinePolicies.stream() - .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) - .collect(Collectors.toList())); + 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()); policies.add(new CookiePolicy()); - policies.addAll( - this.pipelinePolicies.stream() - .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) - .collect(Collectors.toList())); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); HttpPolicyProviders.addAfterRetryPolicies(policies); policies.add(new HttpLoggingPolicy(httpLogOptions)); HttpPipeline httpPipeline = 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 index f881c3f65f7f6..ecb8336e1a1f8 100644 --- 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 @@ -21,6 +21,14 @@ public final class SchemaFormat extends ExpandableStringEnum { /** 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. * diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java index 76541072fa8fb..c245726cd8927 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetByIdResponse.java @@ -7,13 +7,11 @@ import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; import com.azure.core.http.rest.ResponseBase; -import java.io.Closeable; -import java.nio.ByteBuffer; -import reactor.core.publisher.Flux; + +import java.io.InputStream; /** Contains all response data for the getById operation. */ -public final class SchemasGetByIdResponse extends ResponseBase> - implements Closeable { +public final class SchemasGetByIdResponse extends ResponseBase { /** * Creates an instance of SchemasGetByIdResponse. * @@ -27,7 +25,7 @@ public SchemasGetByIdResponse( HttpRequest request, int statusCode, HttpHeaders rawHeaders, - Flux value, + InputStream value, SchemasGetByIdHeaders headers) { super(request, statusCode, rawHeaders, value, headers); } @@ -38,13 +36,7 @@ public SchemasGetByIdResponse( * @return the response content stream. */ @Override - public Flux getValue() { + public InputStream getValue() { return super.getValue(); } - - /** Disposes of the connection associated with this stream response. */ - @Override - public void close() { - getValue().subscribe(bb -> {}, t -> {}).dispose(); - } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java index 8bd5cb7764d13..d248c4c46ab54 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/models/SchemasGetSchemaVersionResponse.java @@ -7,27 +7,25 @@ import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpRequest; import com.azure.core.http.rest.ResponseBase; -import java.io.Closeable; -import java.nio.ByteBuffer; -import reactor.core.publisher.Flux; + +import java.io.InputStream; /** Contains all response data for the getSchemaVersion operation. */ -public final class SchemasGetSchemaVersionResponse - extends ResponseBase> implements Closeable { +public final class SchemasGetSchemaVersionResponse extends ResponseBase { /** * Creates an instance of SchemasGetSchemaVersionResponse. * * @param request the request which resulted in this SchemasGetSchemaVersionResponse. * @param statusCode the status code of the HTTP response. * @param rawHeaders the raw headers of the HTTP response. - * @param value the content stream. + * @param value the deserialized value of the HTTP response. * @param headers the deserialized headers of the HTTP response. */ public SchemasGetSchemaVersionResponse( HttpRequest request, int statusCode, HttpHeaders rawHeaders, - Flux value, + InputStream value, SchemasGetSchemaVersionHeaders headers) { super(request, statusCode, rawHeaders, value, headers); } @@ -38,13 +36,7 @@ public SchemasGetSchemaVersionResponse( * @return the response content stream. */ @Override - public Flux getValue() { + public InputStream getValue() { return super.getValue(); } - - /** Disposes of the connection associated with this stream response. */ - @Override - public void close() { - getValue().subscribe(bb -> {}, t -> {}).dispose(); - } } From b5790b1bca72ee6e9f4b1fa075fa95650b2a9918 Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Tue, 21 Feb 2023 10:20:54 -0800 Subject: [PATCH 6/9] address feedback. --- .../SchemaRegistryAsyncClient.java | 39 ++----------------- .../schemaregistry/SchemaRegistryClient.java | 37 +++++++++++++++--- .../implementation/SchemaRegistryHelper.java | 34 ++++++++++++++++ 3 files changed, 70 insertions(+), 40 deletions(-) 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 cb93ad0a760b9..a329ca929325c 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 @@ -24,10 +24,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.UncheckedIOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -173,7 +169,7 @@ Mono> registerSchemaWithResponse(String groupName, St return restService.getSchemas().registerWithResponseAsync(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), context) .map(response -> { - final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response, format); + final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), registered); @@ -264,7 +260,7 @@ Mono> getSchemaWithResponse(String schemaId, Cont return this.restService.getSchemas().getByIdWithResponseAsync(schemaId, context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .flatMap(response -> { - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetByIdHeaders(response); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); return convertToString(response.getValue()) .map(schema -> new SimpleResponse<>( response.getRequest(), response.getStatusCode(), @@ -284,7 +280,7 @@ Mono> getSchemaWithResponse(String groupName, Str .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .flatMap(response -> { final Flux schemaFlux = response.getValue(); - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromGetSchemaVersionHeaders(response); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); if (schemaFlux == null) { return Mono.error(new IllegalArgumentException(String.format( @@ -387,7 +383,7 @@ Mono> getSchemaPropertiesWithResponse(String groupNam context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .map(response -> { - final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromQueryByIdContentHeaders(response, format); + final SchemaProperties properties = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), @@ -416,33 +412,6 @@ static HttpResponseException remapError(ErrorException error) { return error; } - /** - * 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. - */ - static String convertToString(InputStream inputStream) { - final StringBuilder builder = new StringBuilder(); - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { - - String str; - - while ((str = reader.readLine()) != null) { - builder.append(str); - } - - } catch (IOException exception) { - throw new UncheckedIOException("Error occurred while deserializing schemaContent.", exception); - } - - return builder.toString(); - } - /** * Converts a Flux of Byte Buffer into its string representation. * 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 d4ad81f0f94de..870acef572f5d 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 @@ -26,11 +26,14 @@ import com.azure.data.schemaregistry.models.SchemaProperties; import com.azure.data.schemaregistry.models.SchemaRegistrySchema; +import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; import java.util.Objects; -import static com.azure.data.schemaregistry.SchemaRegistryAsyncClient.convertToString; /** * HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand. @@ -162,7 +165,7 @@ public Response registerSchemaWithResponse(String groupName, S final SchemaFormatImpl contentType = SchemaRegistryHelper.getContentType(format); ResponseBase response = restService.getSchemas().registerWithResponse(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), context); - final SchemaProperties registered = SchemaRegistryHelper.getSchemaPropertiesFromSchemaRegisterHeaders(response, format); + final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), registered); @@ -226,7 +229,7 @@ public Response getSchemaWithResponse(String schemaId, Con context = enableSyncRestProxy(context); try { ResponseBase response = this.restService.getSchemas().getByIdWithResponse(schemaId, context); - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromSchemasGetByIdHeaders(response); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); final String schema = convertToString(response.getValue().toStream()); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema)); @@ -262,7 +265,7 @@ public Response getSchemaWithResponse(String groupName, St ResponseBase response = this.restService.getSchemas().getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, context); final InputStream schemaInputStream = response.getValue().toStream(); - final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaPropertiesFromGetSchemaVersionHeaders(response); + final SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); final String schema; if (schemaInputStream == null) { @@ -339,7 +342,7 @@ public Response getSchemaPropertiesWithResponse(String groupNa try { ResponseBase response = restService.getSchemas() .queryIdByContentWithResponse(groupName, name, com.azure.data.schemaregistry.implementation.models.SchemaFormat.fromString(contentType.toString()), binaryData, binaryData.getLength(), context); - final SchemaProperties properties = SchemaRegistryHelper.getSchemaPropertiesFromQueryByIdContentHeaders(response, format); + final SchemaProperties properties = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), properties); @@ -351,4 +354,28 @@ public Response getSchemaPropertiesWithResponse(String groupNa private Context enableSyncRestProxy(Context context) { return context.addData(HTTP_REST_PROXY_SYNC_PROXY_ENABLE, true); } + + /** + * 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. + */ + static String convertToString(InputStream inputStream) { + final StringBuilder builder = new StringBuilder(); + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + String str; + while ((str = reader.readLine()) != null) { + builder.append(str); + } + } catch (IOException exception) { + throw new UncheckedIOException("Error occurred while deserializing schemaContent.", exception); + } + + return builder.toString(); + } } 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 index 74efc6be4e7e7..1a259c3957918 100644 --- 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 @@ -52,6 +52,40 @@ 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 SchemaProperties getSchemaPropertiesFromSchemaRegisterHeaders(ResponseBase response, SchemaFormat fallbackFormat) { final SchemasRegisterHeaders headers = response.getDeserializedHeaders(); final SchemaFormat responseFormat = getSchemaFormat(response.getHeaders()); From e56bf29bc7da5ab55fa4d2397b4a0a6b1e8b4b3d Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Tue, 21 Feb 2023 10:21:48 -0800 Subject: [PATCH 7/9] fix casing. --- .../data/schemaregistry/SchemaRegistryClientBuilder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 2c6f22503743d..d61e683b2aed5 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 @@ -370,12 +370,12 @@ public SchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public SchemaRegistryAsyncClient buildAsyncClient() { - AzureSchemaRegistryImpl restService = getAzureSchemaREgistryImplService(); + AzureSchemaRegistryImpl restService = getAzureSchemaRegistryImplService(); return new SchemaRegistryAsyncClient(restService); } - private AzureSchemaRegistryImpl getAzureSchemaREgistryImplService() { + private AzureSchemaRegistryImpl getAzureSchemaRegistryImplService() { Objects.requireNonNull(credential, "'credential' cannot be null and must be set via builder.credential(TokenCredential)"); Objects.requireNonNull(fullyQualifiedNamespace, @@ -454,7 +454,7 @@ private AzureSchemaRegistryImpl getAzureSchemaREgistryImplService() { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public SchemaRegistryClient buildClient() { - AzureSchemaRegistryImpl restService = getAzureSchemaREgistryImplService(); + AzureSchemaRegistryImpl restService = getAzureSchemaRegistryImplService(); return new SchemaRegistryClient(restService); } } From 806e398afba35f2ae1306837ff42510e43f2f0b5 Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Wed, 22 Feb 2023 11:36:00 -0800 Subject: [PATCH 8/9] add asserting client wrapper to unit tests. --- .../SchemaRegistryAsyncClientCustomTests.java | 11 ++++++- .../SchemaRegistryAsyncClientJsonTests.java | 11 ++++++- ...chemaRegistryAsyncClientPlaybackTests.java | 11 ++++++- .../SchemaRegistryClientTests.java | 29 ++++++++++++------- 4 files changed, 49 insertions(+), 13 deletions(-) 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 index 489ce0c612210..c9cc4dfbeabcf 100644 --- 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 @@ -6,10 +6,12 @@ import com.azure.core.credential.AccessToken; import com.azure.core.credential.TokenCredential; import com.azure.core.credential.TokenRequestContext; +import com.azure.core.http.HttpClient; 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.test.TestBase; +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; @@ -65,7 +67,7 @@ protected void beforeTest() { .fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { - builder.httpClient(interceptorManager.getPlaybackClient()); + builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); } else { builder.addPolicy(new RetryPolicy()) .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) @@ -80,6 +82,13 @@ protected void afterTest() { Mockito.framework().clearInlineMock(this); } + 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. */ 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 index cc50c8a04766c..fa223cd82f28c 100644 --- 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 @@ -6,10 +6,12 @@ import com.azure.core.credential.AccessToken; import com.azure.core.credential.TokenCredential; import com.azure.core.credential.TokenRequestContext; +import com.azure.core.http.HttpClient; 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.test.TestBase; +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; @@ -68,7 +70,7 @@ protected void beforeTest() { .fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { - builder.httpClient(interceptorManager.getPlaybackClient()); + builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); } else { builder.addPolicy(new RetryPolicy()) .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) @@ -83,6 +85,13 @@ protected void afterTest() { Mockito.framework().clearInlineMock(this); } + 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. */ 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 index 3cf559575d629..c0f3f9d07838a 100644 --- 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 @@ -6,9 +6,11 @@ import com.azure.core.credential.AccessToken; import com.azure.core.credential.TokenCredential; import com.azure.core.credential.TokenRequestContext; +import com.azure.core.http.HttpClient; import com.azure.core.test.InterceptorManager; import com.azure.core.test.TestContextManager; import com.azure.core.test.TestMode; +import com.azure.core.test.http.AssertingHttpClientBuilder; import com.azure.core.test.implementation.TestingHelpers; import com.azure.data.schemaregistry.models.SchemaFormat; import org.junit.jupiter.api.AfterEach; @@ -86,6 +88,13 @@ public void teardownTest() { Mockito.framework().clearInlineMock(this); } + private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .assertAsync() + .skipRequest((httpRequest, context) -> false) + .build(); + } + /** * 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. @@ -98,7 +107,7 @@ public void getSchemaByIdFromPortal() { final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() .fullyQualifiedNamespace(endpoint) .credential(tokenCredential) - .httpClient(interceptorManager.getPlaybackClient()) + .httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())) .serviceVersion(SchemaRegistryVersion.V2021_10) .buildAsyncClient(); final String schemaId = "f45b841fcb88401e961ca45477906be9"; 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 index f791f3ec98a2e..ac8b491b589af 100644 --- 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 @@ -8,8 +8,11 @@ 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.http.policy.RetryPolicy; import com.azure.core.test.TestBase; +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; @@ -73,7 +76,7 @@ protected void beforeTest() { .fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { - builder.httpClient(interceptorManager.getPlaybackClient()); + builder.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient())); } else { builder.addPolicy(new RetryPolicy()) .addPolicy(interceptorManager.getRecordPolicy()); @@ -85,6 +88,14 @@ protected void afterTest() { Mockito.framework().clearInlineMock(this); } + + 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. */ @@ -200,18 +211,16 @@ public void registerBadRequest() { public void registerSchemaInvalidFormat() { // Arrange final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); - final SchemaRegistryAsyncClient client = builder.buildAsyncClient(); + final SchemaRegistryClient client = builder.buildClient(); 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(403, responseException.getResponse().getStatusCode()); - }) - .verify(); + try { + client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat, Context.NONE); + + } catch (HttpResponseException e) { + assertEquals(403, e.getResponse().getStatusCode()); + } } /** From 88a5bf9f35d4d1309f594844435a3592adb19b74 Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Wed, 22 Feb 2023 11:38:21 -0800 Subject: [PATCH 9/9] fix checkstyle --- .../azure/data/schemaregistry/SchemaRegistryClientTests.java | 2 -- 1 file changed, 2 deletions(-) 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 index ac8b491b589af..c48b19da7f05a 100644 --- 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 @@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; import java.time.OffsetDateTime; @@ -33,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when;