diff --git a/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/CodeModelCustomConstructor.java b/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/CodeModelCustomConstructor.java index 8884457502..3fd3506a86 100644 --- a/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/CodeModelCustomConstructor.java +++ b/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/CodeModelCustomConstructor.java @@ -8,6 +8,9 @@ import org.yaml.snakeyaml.nodes.ScalarNode; import org.yaml.snakeyaml.nodes.SequenceNode; +import java.util.ArrayList; +import java.util.List; + public class CodeModelCustomConstructor extends Constructor { public CodeModelCustomConstructor() { super(); @@ -124,6 +127,33 @@ public Object construct(Node node) { case "schema": { MappingNode value = (MappingNode) tuple.getValueNode(); value.setType(getSchemaTypeFromMappingNode(value)); + break; + } + case "extensions": { + MappingNode value = (MappingNode) tuple.getValueNode(); + List actualValues = new ArrayList<>(); + for (NodeTuple extension : value.getValue()) { + ScalarNode keyNode = (ScalarNode) extension.getKeyNode(); + if ("x-ms-pageable".equals(keyNode.getValue())) { + actualValues.add(new NodeTuple(new ScalarNode( + keyNode.getTag(), + "xmsPageable", + keyNode.getStartMark(), + keyNode.getEndMark(), + keyNode.getScalarStyle()), + extension.getValueNode())); + } else if ("x-ms-skip-url-encoding".equals(keyNode.getValue())) { + actualValues.add(new NodeTuple(new ScalarNode( + keyNode.getTag(), + "xmsSkipUrlEncoding", + keyNode.getStartMark(), + keyNode.getEndMark(), + keyNode.getScalarStyle()), + extension.getValueNode())); + } + } + value.setValue(actualValues); + break; } } } diff --git a/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/Language.java b/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/Language.java index 5457a099d8..acc98366b6 100644 --- a/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/Language.java +++ b/extension-base/src/main/java/com/azure/autorest/extension/base/model/codemodel/Language.java @@ -12,9 +12,17 @@ public class Language { /** * name used in actual implementation * (Required) - * + * */ private String name; + + /** + * name used in serialization + * (Optional) + * + */ + private String serializedName; + /** * description text - describes this node. * (Required) @@ -40,6 +48,14 @@ public void setName(String name) { this.name = name; } + public String getSerializedName() { + return serializedName; + } + + public void setSerializedName(String serializedName) { + this.serializedName = serializedName; + } + /** * description text - describes this node. * (Required) diff --git a/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsExtensions.java b/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsExtensions.java index 7364c0a029..85f65319e5 100644 --- a/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsExtensions.java +++ b/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsExtensions.java @@ -5,6 +5,10 @@ public class XmsExtensions { private String xmsClientName; + private XmsPageable xmsPageable; + + private boolean xmsSkipUrlEncoding; + public XmsEnum getXmsEnum() { return xmsEnum; } @@ -20,4 +24,20 @@ public String getXmsClientName() { public void setXmsClientName(String xmsClientName) { this.xmsClientName = xmsClientName; } + + public XmsPageable getXmsPageable() { + return xmsPageable; + } + + public void setXmsPageable(XmsPageable xmsPageable) { + this.xmsPageable = xmsPageable; + } + + public boolean isXmsSkipUrlEncoding() { + return xmsSkipUrlEncoding; + } + + public void setXmsSkipUrlEncoding(boolean xmsSkipUrlEncoding) { + this.xmsSkipUrlEncoding = xmsSkipUrlEncoding; + } } diff --git a/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsPageable.java b/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsPageable.java new file mode 100644 index 0000000000..eba866727e --- /dev/null +++ b/extension-base/src/main/java/com/azure/autorest/extension/base/model/extensionmodel/XmsPageable.java @@ -0,0 +1,42 @@ +package com.azure.autorest.extension.base.model.extensionmodel; + +import com.azure.autorest.extension.base.model.codemodel.Operation; + +public class XmsPageable { + private String itemName = "value"; + private String nextLinkName; + private String operationName; + private Operation nextOperation; + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getNextLinkName() { + return nextLinkName; + } + + public void setNextLinkName(String nextLinkName) { + this.nextLinkName = nextLinkName; + } + + public String getOperationName() { + return operationName; + } + + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + public Operation getNextOperation() { + return nextOperation; + } + + public void setNextOperation(Operation nextOperation) { + this.nextOperation = nextOperation; + } +} diff --git a/generate b/generate index 7cf8997dc9..543f43b1b7 100755 --- a/generate +++ b/generate @@ -13,7 +13,8 @@ autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azu autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-integer.json --namespace=fixtures.bodyinteger --output-folder=tests --sync-methods=all autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-number.json --namespace=fixtures.bodynumber --output-folder=tests --sync-methods=all autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/httpInfrastructure.json --namespace=fixtures.httpinfrastructure --output-folder=tests --sync-methods=all +autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/paging.json --namespace=fixtures.paging --output-folder=tests --sync-methods=all autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-byte.json --namespace=fixtures.bodybyte --output-folder=tests --sync-methods=all autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-date.json --namespace=fixtures.bodydate --output-folder=tests --sync-methods=all autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-datetime.json --namespace=fixtures.bodydatetime --output-folder=tests --sync-methods=all -autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-datetime-rfc1123.json --namespace=fixtures.bodydatetimerfc1123 --output-folder=tests --sync-methods=all +autorest-beta --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-datetime-rfc1123.json --namespace=fixtures.bodydatetimerfc1123 --output-folder=tests --sync-methods=all \ No newline at end of file diff --git a/generate.bat b/generate.bat index 81c8823611..0afb32aa5f 100755 --- a/generate.bat +++ b/generate.bat @@ -12,7 +12,8 @@ call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.co call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-integer.json --namespace=fixtures.bodyinteger --output-folder=tests --sync-methods=all call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-number.json --namespace=fixtures.bodynumber --output-folder=tests --sync-methods=all call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/httpInfrastructure.json --namespace=fixtures.httpinfrastructure --output-folder=tests --sync-methods=all +call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/paging.json --namespace=fixtures.paging --output-folder=tests --sync-methods=all call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-byte.json --namespace=fixtures.bodybyte --output-folder=tests --sync-methods=all call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-date.json --namespace=fixtures.bodydate --output-folder=tests --sync-methods=all call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-datetime.json --namespace=fixtures.bodydatetime --output-folder=tests --sync-methods=all -call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-datetime-rfc1123.json --namespace=fixtures.bodydatetimerfc1123 --output-folder=tests --sync-methods=all +call autorest-beta --java --use:.\ --input-file=https://raw.githubusercontent.com/Azure/autorest.testserver/master/swagger/body-datetime-rfc1123.json --namespace=fixtures.bodydatetimerfc1123 --output-folder=tests --sync-methods=all \ No newline at end of file diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ClientMethodMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ClientMethodMapper.java index 49e1c165a4..d57c40356c 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ClientMethodMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ClientMethodMapper.java @@ -1,28 +1,37 @@ package com.azure.autorest.mapper; import com.azure.autorest.extension.base.model.codemodel.ConstantSchema; +import com.azure.autorest.extension.base.model.codemodel.ObjectSchema; import com.azure.autorest.extension.base.model.codemodel.Operation; import com.azure.autorest.extension.base.model.codemodel.Parameter; import com.azure.autorest.extension.base.model.codemodel.Response; +import com.azure.autorest.extension.base.model.codemodel.Schema; import com.azure.autorest.extension.base.plugin.JavaSettings; import com.azure.autorest.model.clientmodel.ClassType; import com.azure.autorest.model.clientmodel.ClientMethod; import com.azure.autorest.model.clientmodel.ClientMethodParameter; import com.azure.autorest.model.clientmodel.ClientMethodType; +import com.azure.autorest.model.clientmodel.ClientModel; import com.azure.autorest.model.clientmodel.GenericType; import com.azure.autorest.model.clientmodel.IType; +import com.azure.autorest.model.clientmodel.ListType; +import com.azure.autorest.model.clientmodel.MethodPageDetails; import com.azure.autorest.model.clientmodel.PrimitiveType; import com.azure.autorest.model.clientmodel.ProxyMethod; import com.azure.autorest.model.clientmodel.ReturnValue; - +import com.azure.autorest.util.CodeNamer; import com.azure.autorest.util.SchemaUtil; + import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; public class ClientMethodMapper implements IMapper> { private static ClientMethodMapper instance = new ClientMethodMapper(); + private Map> parsed = new HashMap<>(); private ClientMethodMapper() { } @@ -34,6 +43,9 @@ public static ClientMethodMapper getInstance() { @Override public List map(Operation operation) { JavaSettings settings = JavaSettings.getInstance(); + if (parsed.containsKey(operation)) { + return parsed.get(operation); + } ProxyMethod proxyMethod = Mappers.getProxyMethodMapper().map(operation); @@ -46,68 +58,83 @@ public List map(Operation operation) { } } - // WithResponseAsync, with required and optional parameters - methods.add(new ClientMethod( - operation.getDescription(), - new ReturnValue(null, proxyMethod.getReturnType().getClientType()), - proxyMethod.getSimpleAsyncRestResponseMethodName(), - parameters, - false, - ClientMethodType.SimpleAsyncRestResponse, - proxyMethod, - new ArrayList<>(), - new ArrayList<>(), - false, - null, - null, - new ArrayList<>())); - - IType responseBodyType = Mappers.getSchemaMapper().map(SchemaUtil.getLowestCommonParent( - operation.getResponses().stream().map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList()))); - - if (responseBodyType == null) { - responseBodyType = PrimitiveType.Void; - } - // Simple Async - if (settings.getSyncMethods() != JavaSettings.SyncMethodsGeneration.NONE) { - - - IType restAPIMethodReturnBodyClientType = responseBodyType.getClientType(); - IType asyncMethodReturnType; - if (restAPIMethodReturnBodyClientType != PrimitiveType.Void) - { - asyncMethodReturnType = GenericType.Mono(restAPIMethodReturnBodyClientType); - } - else - { - asyncMethodReturnType = GenericType.Mono(ClassType.Void); - } + if (operation.getExtensions() != null && operation.getExtensions().getXmsPageable() != null) { + boolean isNextMethod = operation.getExtensions().getXmsPageable().getNextOperation() == operation; + + MethodPageDetails details = new MethodPageDetails( + CodeNamer.getPropertyName(operation.getExtensions().getXmsPageable().getNextLinkName()), + CodeNamer.getPropertyName(operation.getExtensions().getXmsPageable().getItemName()), + isNextMethod ? null : Mappers.getClientMethodMapper().map(operation.getExtensions().getXmsPageable().getNextOperation()) + .stream().findFirst().get()); + + // Mono> + Schema responseBodySchema = SchemaUtil.getLowestCommonParent( + operation.getResponses().stream().map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList())); + ClientModel responseBodyModel = Mappers.getModelMapper().map((ObjectSchema) responseBodySchema); + IType listType = responseBodyModel.getProperties().stream() + .filter(p -> p.getSerializedName().equals(operation.getExtensions().getXmsPageable().getItemName())) + .findFirst().get().getWireType(); + IType elementType = ((ListType) listType).getElementType(); + IType asyncSinglePageReturnType = GenericType.Mono(GenericType.PagedResponse(elementType)); + IType asyncReturnType = GenericType.PagedFlux(elementType); + IType syncReturnType = GenericType.PagedIterable(elementType); methods.add(new ClientMethod( operation.getDescription(), - new ReturnValue(null, asyncMethodReturnType), - proxyMethod.getSimpleAsyncMethodName(), + new ReturnValue(null, asyncSinglePageReturnType), + proxyMethod.getPagingAsyncSinglePageMethodName(), parameters, false, - ClientMethodType.SimpleAsync, + ClientMethodType.PagingAsyncSinglePage, proxyMethod, new ArrayList<>(), new ArrayList<>(), false, null, - null, + details, new ArrayList<>())); - } - // Sync - if (settings.getSyncMethods() == JavaSettings.SyncMethodsGeneration.ALL) { + if (!isNextMethod) { + methods.add(new ClientMethod( + operation.getDescription(), + new ReturnValue(null, asyncReturnType), + proxyMethod.getSimpleAsyncMethodName(), + parameters, + false, + ClientMethodType.PagingAsync, + proxyMethod, + new ArrayList<>(), + new ArrayList<>(), + false, + null, + details, + new ArrayList<>())); + + methods.add(new ClientMethod( + operation.getDescription(), + new ReturnValue(null, syncReturnType), + proxyMethod.getName(), + parameters, + false, + ClientMethodType.PagingSync, + proxyMethod, + new ArrayList<>(), + new ArrayList<>(), + false, + null, + details, + new ArrayList<>())); + } + } else { + + // WithResponseAsync, with required and optional parameters methods.add(new ClientMethod( operation.getDescription(), - new ReturnValue(null, responseBodyType.getClientType()), - proxyMethod.getName(), + new ReturnValue(null, proxyMethod.getReturnType().getClientType()), + proxyMethod.getSimpleAsyncRestResponseMethodName(), parameters, false, - ClientMethodType.SimpleSync, + ClientMethodType.SimpleAsyncRestResponse, proxyMethod, new ArrayList<>(), new ArrayList<>(), @@ -115,8 +142,62 @@ public List map(Operation operation) { null, null, new ArrayList<>())); + + IType responseBodyType = Mappers.getSchemaMapper().map(SchemaUtil.getLowestCommonParent( + operation.getResponses().stream().map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList()))); + + if (responseBodyType == null) { + responseBodyType = PrimitiveType.Void; + } + + // Simple Async + if (settings.getSyncMethods() != JavaSettings.SyncMethodsGeneration.NONE) { + + + IType restAPIMethodReturnBodyClientType = responseBodyType.getClientType(); + IType asyncMethodReturnType; + if (restAPIMethodReturnBodyClientType != PrimitiveType.Void) { + asyncMethodReturnType = GenericType.Mono(restAPIMethodReturnBodyClientType); + } else { + asyncMethodReturnType = GenericType.Mono(ClassType.Void); + } + + methods.add(new ClientMethod( + operation.getDescription(), + new ReturnValue(null, asyncMethodReturnType), + proxyMethod.getSimpleAsyncMethodName(), + parameters, + false, + ClientMethodType.SimpleAsync, + proxyMethod, + new ArrayList<>(), + new ArrayList<>(), + false, + null, + null, + new ArrayList<>())); + } + + // Sync + if (settings.getSyncMethods() == JavaSettings.SyncMethodsGeneration.ALL) { + methods.add(new ClientMethod( + operation.getDescription(), + new ReturnValue(null, responseBodyType.getClientType()), + proxyMethod.getName(), + parameters, + false, + ClientMethodType.SimpleSync, + proxyMethod, + new ArrayList<>(), + new ArrayList<>(), + false, + null, + null, + new ArrayList<>())); + } } + parsed.put(operation, methods); return methods; } } diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ClientParameterMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ClientParameterMapper.java index 148636341e..4a951c7088 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ClientParameterMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ClientParameterMapper.java @@ -26,7 +26,7 @@ public ClientMethodParameter map(Parameter parameter) { JavaSettings settings = JavaSettings.getInstance(); IType wireType = Mappers.getSchemaMapper().map(parameter.getSchema()); - if (parameter.isNullable()) { + if (parameter.isNullable() || !parameter.isRequired()) { wireType = wireType.asNullable(); } diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java index bac3529104..17e6dd5416 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java @@ -1,10 +1,10 @@ package com.azure.autorest.mapper; -import com.azure.autorest.extension.base.model.codemodel.ConstantSchema; import com.azure.autorest.extension.base.model.codemodel.Header; import com.azure.autorest.extension.base.model.codemodel.Operation; import com.azure.autorest.extension.base.model.codemodel.Parameter; import com.azure.autorest.extension.base.model.codemodel.Response; +import com.azure.autorest.extension.base.model.codemodel.Schema; import com.azure.autorest.extension.base.plugin.JavaSettings; import com.azure.autorest.model.clientmodel.ClassType; import com.azure.autorest.model.clientmodel.GenericType; @@ -65,8 +65,9 @@ public ProxyMethod map(Operation operation) { .map(s -> HttpResponseStatus.valueOf(Integer.parseInt(s))) .sorted().collect(Collectors.toList()); - IType responseBodyType = Mappers.getSchemaMapper().map(SchemaUtil.getLowestCommonParent( - operation.getResponses().stream().map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList()))); + Schema responseBodySchema = SchemaUtil.getLowestCommonParent( + operation.getResponses().stream().map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList())); + IType responseBodyType = Mappers.getSchemaMapper().map(responseBodySchema); if (responseBodyType == null) { responseBodyType = PrimitiveType.Void; @@ -86,7 +87,6 @@ public ProxyMethod map(Operation operation) { ClassType clientResponseClassType = ClientMapper.getClientResponseClassType(operation, settings); returnType = GenericType.Mono(clientResponseClassType); } else { - // SchemaResponse IType singleValueType; if (responseBodyType.equals(GenericType.FluxByteBuffer)) { singleValueType = ClassType.StreamResponse; diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ProxyParameterMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ProxyParameterMapper.java index eebc3ec64d..931682da21 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ProxyParameterMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ProxyParameterMapper.java @@ -35,7 +35,7 @@ public ProxyMethodParameter map(Parameter parameter) { Schema ParameterJvWireType = parameter.getSchema(); IType wireType = Mappers.getSchemaMapper().map(ParameterJvWireType); - if (parameter.isNullable()) { + if (parameter.isNullable() || !parameter.isRequired()) { wireType = wireType.asNullable(); } IType clientType = wireType.getClientType(); @@ -54,17 +54,15 @@ public ProxyMethodParameter map(Parameter parameter) { wireType = ClassType.String; } - boolean parameterIsNullable = parameter.isNullable(); - if (parameterIsNullable) { - clientType = clientType.asNullable(); - } - String parameterDescription = parameter.getDescription(); if (parameterDescription == null || parameterDescription.isEmpty()) { parameterDescription = String.format("the %s value", clientType); } - boolean parameterSkipUrlEncodingExtension = false; // TODO: SkipUrlEncoding parameter.Extensions?.Get(SwaggerExtensions.SkipUrlEncodingExtension) == true; + boolean parameterSkipUrlEncodingExtension = false; + if (parameter.getExtensions() != null) { + parameterSkipUrlEncodingExtension = parameter.getExtensions().isXmsSkipUrlEncoding(); + } boolean parameterIsConstant = false; String defaultValue = null; diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ServiceClientMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ServiceClientMapper.java index f57ef67d56..4cec94fa29 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ServiceClientMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ServiceClientMapper.java @@ -54,14 +54,14 @@ public ServiceClient map(CodeModel codeModel) { Proxy serviceClientRestAPI = null; List serviceClientMethods = new ArrayList<>(); List codeModelRestAPIMethods = codeModel.getOperationGroups().stream() - .filter(og -> og.getLanguage().getDefault().getName() == null || og.getLanguage().getDefault().getName().isEmpty()) + .filter(og -> og.getLanguage().getJava().getName() == null || og.getLanguage().getJava().getName().isEmpty()) .flatMap(og -> og.getOperations().stream()) .collect(Collectors.toList()); if (!codeModelRestAPIMethods.isEmpty()) { String restAPIName = serviceClientInterfaceName + "Service"; // TODO: Assume all operations share the same base url String proxyBaseUrl = codeModel.getOperationGroups().stream() - .filter(og -> og.getLanguage().getDefault().getName() == null || og.getLanguage().getDefault().getName().isEmpty()) + .filter(og -> og.getLanguage().getJava().getName() == null || og.getLanguage().getJava().getName().isEmpty()) .map(og -> og.getOperations().get(0)) .findFirst().get().getRequest() .getProtocol().getHttp().getUri(); @@ -78,7 +78,7 @@ public ServiceClient map(CodeModel codeModel) { List serviceClientMethodGroupClients = new ArrayList<>(); List codeModelMethodGroups = codeModel.getOperationGroups().stream() - .filter(og -> og.getLanguage().getDefault().getName() != null && !og.getLanguage().getDefault().getName().isEmpty()) + .filter(og -> og.getLanguage().getJava().getName() != null && !og.getLanguage().getJava().getName().isEmpty()) .collect(Collectors.toList()); for (OperationGroup codeModelMethodGroup : codeModelMethodGroups) { serviceClientMethodGroupClients.add(Mappers.getMethodGroupMapper().map(codeModelMethodGroup)); diff --git a/javagen/src/main/java/com/azure/autorest/model/clientmodel/ClientMethod.java b/javagen/src/main/java/com/azure/autorest/model/clientmodel/ClientMethod.java index 2ea36539e9..bdd7101e51 100644 --- a/javagen/src/main/java/com/azure/autorest/model/clientmodel/ClientMethod.java +++ b/javagen/src/main/java/com/azure/autorest/model/clientmodel/ClientMethod.java @@ -243,6 +243,10 @@ public void addImportsTo(Set imports, boolean includeImplementationImpor parameter.addImportsTo(imports, includeImplementationImports); } + if (getMethodPageDetails() != null) { + imports.add("com.azure.core.http.rest.PagedResponseBase"); + } + if (includeImplementationImports) { if (!expressionsToValidate.isEmpty() && settings.shouldClientSideValidations()) { imports.add(ClassType.Validator.getFullName()); diff --git a/javagen/src/main/java/com/azure/autorest/model/clientmodel/GenericType.java b/javagen/src/main/java/com/azure/autorest/model/clientmodel/GenericType.java index 0f0f15c7b9..302d2cbffc 100644 --- a/javagen/src/main/java/com/azure/autorest/model/clientmodel/GenericType.java +++ b/javagen/src/main/java/com/azure/autorest/model/clientmodel/GenericType.java @@ -69,6 +69,18 @@ public static GenericType BodyResponse(IType bodyType) { return new GenericType("com.azure.core.http.rest", "SimpleResponse", bodyType); } + public static GenericType PagedResponse(IType bodyType) { + return new GenericType("com.azure.core.http.rest", "PagedResponse", bodyType); + } + + public static GenericType PagedFlux(IType bodyType) { + return new GenericType("com.azure.core.http.rest", "PagedFlux", bodyType); + } + + public static GenericType PagedIterable(IType bodyType) { + return new GenericType("com.azure.core.http.rest", "PagedIterable", bodyType); + } + public static GenericType Function(IType inputType, IType outputType) { return new GenericType("java.util", "Function", inputType, outputType); } diff --git a/javagen/src/main/java/com/azure/autorest/model/clientmodel/MethodPageDetails.java b/javagen/src/main/java/com/azure/autorest/model/clientmodel/MethodPageDetails.java index 2966356cab..65741a63b0 100644 --- a/javagen/src/main/java/com/azure/autorest/model/clientmodel/MethodPageDetails.java +++ b/javagen/src/main/java/com/azure/autorest/model/clientmodel/MethodPageDetails.java @@ -11,73 +11,25 @@ public class MethodPageDetails { /** * Get whether or not this method is a request to get the next page of a sequence of pages. */ - private boolean isNextMethod; - private IType pageType; - private GenericType pageImplType; - private String nextLinkVariableName; - private String nextLinkParameterName; + private String nextLinkName; + private String itemName; private ClientMethod nextMethod; - private String nextMethodGroupName; - private ClientMethodParameter nextGroupParameter; - private String nextGroupParameterTypeName; - private String nextMethodInvocation; - private String nextMethodParameterInvocation; - public MethodPageDetails(boolean isNextMethod, IType pageType, GenericType pageImplType, String nextLinkVariableName, String nextLinkParameterName, ClientMethod nextMethod, String nextMethodGroupName, ClientMethodParameter nextGroupParameter, String nextGroupParameterTypeName, String nextMethodInvocation, java.util.function.Function nextMethodParameterInvocation) { - this.isNextMethod = isNextMethod; - this.pageType = pageType; - this.pageImplType = pageImplType; - this.nextLinkVariableName = nextLinkVariableName; - this.nextLinkParameterName = nextLinkParameterName; + public MethodPageDetails(String nextLinkName, String itemName, ClientMethod nextMethod) { + this.nextLinkName = nextLinkName; + this.itemName = itemName; this.nextMethod = nextMethod; - this.nextMethodGroupName = nextMethodGroupName; - this.nextGroupParameter = nextGroupParameter; - this.nextGroupParameterTypeName = nextGroupParameterTypeName; - this.nextMethodInvocation = nextMethodInvocation; - this.nextMethodParameterInvocation = nextMethodParameterInvocation.apply(this); } - public final boolean getIsNextMethod() { - return isNextMethod; + public String getNextLinkName() { + return nextLinkName; } - public final IType getPageType() { - return pageType; - } - - public final GenericType getPageImplType() { - return pageImplType; - } - - public final String getNextLinkVariableName() { - return nextLinkVariableName; - } - - public final String getNextLinkParameterName() { - return nextLinkParameterName; + public String getItemName() { + return itemName; } public final ClientMethod getNextMethod() { return nextMethod; } - - public final String nextMethodGroupName() { - return nextMethodGroupName; - } - - public final ClientMethodParameter getNextGroupParameter() { - return nextGroupParameter; - } - - public final String getNextGroupParameterTypeName() { - return nextGroupParameterTypeName; - } - - public final String getNextMethodInvocation() { - return nextMethodInvocation; - } - - public final String getNextMethodParameterInvocation() { - return nextMethodParameterInvocation; - } } \ No newline at end of file diff --git a/javagen/src/main/java/com/azure/autorest/model/clientmodel/PagingClientMethod.java b/javagen/src/main/java/com/azure/autorest/model/clientmodel/PagingClientMethod.java deleted file mode 100644 index 0db4d3c99c..0000000000 --- a/javagen/src/main/java/com/azure/autorest/model/clientmodel/PagingClientMethod.java +++ /dev/null @@ -1,279 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package com.azure.autorest.model.clientmodel; - -import com.azure.autorest.extension.base.model.codemodel.RequestParameterLocation; -import com.azure.autorest.extension.base.plugin.JavaSettings; -import com.azure.autorest.util.CodeNamer; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - - -/** - * A ClientMethod that exists on a ServiceClient or MethodGroupClient that eventually will call a ProxyMethod. - */ -public class PagingClientMethod { - /** - * The description of this ClientMethod. - */ - private String description; - /** - * The return value of this ClientMethod. - */ - private ReturnValue returnValue; - /** - * The name of this ClientMethod. - */ - private String name; - /** - * The parameters of this ClientMethod. - */ - private List parameters; - /** - * Whether or not this ClientMethod has omitted optional parameters. - */ - private boolean onlyRequiredParameters; - /** - * The type of this ClientMethod. - */ - private ClientMethodType type = ClientMethodType.values()[0]; - /** - * The RestAPIMethod that this ClientMethod eventually calls. - */ - private ProxyMethod proxyMethod; - /** - * The expressions (parameters and service client properties) that need to be validated in this ClientMethod. - */ - private List expressionsToValidate; - private ArrayList requiredNullableParameterExpressions; - private ClientMethodParameter groupedParameter; - private String groupedParameterTypeName; - private MethodPageDetails methodPageDetails; - private ArrayList methodTransformationDetails; - - /** - * Create a new ClientMethod with the provided properties. - * @param description The description of this ClientMethod. - * @param returnValue The return value of this ClientMethod. - * @param name The name of this ClientMethod. - * @param parameters The parameters of this ClientMethod. - * @param onlyRequiredParameters Whether or not this ClientMethod has omitted optional parameters. - * @param type The type of this ClientMethod. - * @param proxyMethod The ProxyMethod that this ClientMethod eventually calls. - * @param expressionsToValidate The expressions (parameters and service client properties) that need to be validated in this ClientMethod. - * @param requiredNullableParameterExpressions The parameter expressions which are required. - * @param groupedParameter The parameter that needs to transformed before pagination. - * @param groupedParameterTypeName The type name of groupedParameter. - * @param methodPageDetails The pagination information if this is a paged method. - * @param methodTransformationDetails The parameter transformations before calling ProxyMethod. - */ - public PagingClientMethod(String description, com.azure.autorest.model.clientmodel.ReturnValue returnValue, String name, List parameters, boolean onlyRequiredParameters, ClientMethodType type, ProxyMethod proxyMethod, List expressionsToValidate, ArrayList requiredNullableParameterExpressions, ClientMethodParameter groupedParameter, String groupedParameterTypeName, MethodPageDetails methodPageDetails, ArrayList methodTransformationDetails) { - this.description = description; - this.returnValue = returnValue; - this.name = name; - this.parameters = parameters; - this.onlyRequiredParameters = onlyRequiredParameters; - this.type = type; - this.proxyMethod = proxyMethod; - this.expressionsToValidate = expressionsToValidate; - this.requiredNullableParameterExpressions = requiredNullableParameterExpressions; - this.groupedParameter = groupedParameter; - this.groupedParameterTypeName = groupedParameterTypeName; - this.methodPageDetails = methodPageDetails; - this.methodTransformationDetails = methodTransformationDetails; - } - - public final String getDescription() { - return description; - } - - public final com.azure.autorest.model.clientmodel.ReturnValue getReturnValue() { - return returnValue; - } - - public final String getName() { - return name; - } - -// public final String getClientReference() -// { -// return getProxyMethod().getAutoRestMethod().Group.IsNullOrEmpty() ? "this" : "this.client"; -// } - - public final List getParameters() { - return parameters; - } - - public final boolean getOnlyRequiredParameters() { - return onlyRequiredParameters; - } - - public final ClientMethodType getType() { - return type; - } - - public final ProxyMethod getProxyMethod() { - return proxyMethod; - } - - public final List getExpressionsToValidate() { - return expressionsToValidate; - } - - /** - * Get the comma-separated list of parameter declarations for this ClientMethod. - */ - public final String getParametersDeclaration() { - return getParameters().stream() - .map(ClientMethodParameter::getDeclaration) - .collect(Collectors.joining(", ")); - } - - /** - * Get the comma-separated list of parameter names for this ClientMethod. - */ - public final String getArgumentList() { - return getParameters().stream() - .map(ClientMethodParameter::getName) - .collect(Collectors.joining(", ")); - } - - /** - * The full declaration of this ClientMethod. - */ - public final String getDeclaration() { - return String.format("%1$s %2$s(%3$s)", getReturnValue().getType(), getName(), getParametersDeclaration()); - } - - public final String getPagingAsyncSinglePageMethodName() { - return getProxyMethod().getName() + "SinglePageAsync"; - } - - public final String getSimpleAsyncMethodName() { - return getProxyMethod().getName() + "Async"; - } - - public final List getMethodParameters() { - return getParameters().stream() - .filter(parameter -> parameter != null && !parameter.getFromClient() && parameter.getName() != null && !parameter.getName().isEmpty()) - .sorted((p1, p2) -> Boolean.compare(p2.getIsRequired(), p1.getIsRequired())) - .collect(Collectors.toList()); - } - - public final List getMethodNonConstantParameters() { - return getMethodParameters().stream() - .filter(parameter -> !parameter.getIsConstant()) - .sorted((p1, p2) -> Boolean.compare(p2.getIsRequired(), p1.getIsRequired())) - .collect(Collectors.toList()); - } - - public final List getMethodRequiredParameters() { - return getMethodNonConstantParameters().stream() - .filter(parameter -> parameter.getIsRequired()) - .collect(Collectors.toList()); - } - - public final ArrayList getRequiredNullableParameterExpressions() { - return requiredNullableParameterExpressions; - } - - public final ClientMethodParameter getGroupedParameter() { - return groupedParameter; - } - - public final String getGroupedParameterTypeName() { - return groupedParameterTypeName; - } - - public final MethodPageDetails getMethodPageDetails() { - return methodPageDetails; - } - - public final ArrayList getMethodTransformationDetails() { - return methodTransformationDetails; - } - - public final List getProxyMethodArguments(JavaSettings settings) { - List restAPIMethodArguments = getProxyMethod().getParameters().stream() - .map(parameter -> - { - String parameterName = parameter.getParameterReference(); - IType parameterWireType = parameter.getWireType(); - if (parameter.getIsNullable()) { - parameterWireType = parameterWireType.asNullable(); - } - IType parameterClientType = parameter.getClientType(); - - if (parameterClientType != ClassType.Base64Url && parameter.getRequestParameterLocation() != RequestParameterLocation.Body /*&& parameter.getRequestParameterLocation() != RequestParameterLocation.FormData*/ && (parameterClientType instanceof ArrayType || parameterClientType instanceof ListType)) { - parameterWireType = ClassType.String; - } - - String parameterWireName = parameterClientType != parameterWireType ? String.format("%1$sConverted", CodeNamer.toCamelCase(parameterName)) : parameterName; - - String result; - /*if (settings.ShouldGenerateXmlSerialization && parameterWireType is ListType) - { - // used to be $"new {parameterWireType.XmlName.ToPascalCase()}Wrapper({parameterWireName})" - result = $"new {parameterWireType.ToString().ToPascalCase()}Wrapper({parameterWireName})"; - } - else */ - if (getMethodTransformationDetails().stream().anyMatch(d -> (parameterName + "1").equals(d.getOutParameter().getName()))) { - result = getMethodTransformationDetails().stream().filter(d -> (parameterName + "1").equals(d.getOutParameter().getName())).findFirst().get().getOutParameter().getName(); - } else { - result = parameterWireName; - } - return result; - }).collect(Collectors.toList()); - if (settings.getAddContextParameter()) { - restAPIMethodArguments.add(0, "context"); - } - return restAPIMethodArguments; - } - - /** - * Add this ClientMethod's imports to the provided ISet of imports. - * @param imports The set of imports to add to. - * @param includeImplementationImports Whether or not to include imports that are only necessary for method implementations. - */ - public void addImportsTo(Set imports, boolean includeImplementationImports, JavaSettings settings) { - getReturnValue().addImportsTo(imports, includeImplementationImports); - - for (com.azure.autorest.model.clientmodel.ClientMethodParameter parameter : getParameters()) { - parameter.addImportsTo(imports, includeImplementationImports); - } - - if (includeImplementationImports) { - if (expressionsToValidate.size() > 0) { - imports.add(ClassType.Validator.getFullName()); - } - - // TODO: Yuck! -// List methodRetrofitParameters = ProxyMethod.AutoRestMethod.LogicalParameters.Where(p => p.Location != AutoRestParameterLocation.None).ToList(); -// if (settings.IsAzureOrFluent && ProxyMethod.AutoRestMethod.Extensions.Get("nextLinkMethod") == true) -// { -// methodRetrofitParameters.RemoveAll(p => p.Location == AutoRestParameterLocation.Path); -// } -// foreach (AutoRestParameter parameter in methodRetrofitParameters) -// { -// AutoRestParameterLocation location = parameter.Location; -// AutoRestIModelType parameterModelType = parameter.ModelType; -// -// if (location != AutoRestParameterLocation.Body) -// { -// if (parameterModelType.IsPrimaryType(AutoRestKnownPrimaryType.ByteArray)) -// { -// imports.Add("com.azure.core.util.Base64Util"); -// } -// else if (parameterModelType is AutoRestSequenceType) -// { -// imports.Add("com.azure.core.util.serializer.CollectionFormat"); -// } -// } -// } - } - } -} \ No newline at end of file diff --git a/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java index b1454f440c..f446431b85 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java @@ -24,8 +24,6 @@ import com.azure.autorest.util.CodeNamer; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -262,211 +260,83 @@ public final void write(ClientMethod clientMethod, JavaType typeBlock) { comment.methodReturns(clientMethod.getReturnValue().getDescription()); }); typeBlock.annotation("ServiceMethod(returns = ReturnType.COLLECTION)"); - typeBlock.publicMethod(clientMethod.getDeclaration(), function -> - { - function.line(String.format("%1$s response = %2$s(%3$s).block();", pageDetails.getPageType(), clientMethod.getPagingAsyncSinglePageMethodName(), clientMethod.getArgumentList())); - function.returnAnonymousClass(String.format("new %1$s(response)", clientMethod.getReturnValue().getType()), anonymousClass -> - { - anonymousClass.annotation("Override"); - anonymousClass.publicMethod(String.format("%1$s nextPage(String %2$s)", pageDetails.getPageType(), pageDetails.getNextLinkParameterName()), subFunction -> - { - if (clientMethod.getMethodTransformationDetails() != null && !clientMethod.getMethodTransformationDetails().isEmpty() && pageDetails.getNextMethod().getMethodTransformationDetails() != null) { - if (!pageDetails.getNextGroupParameterTypeName().equals(clientMethod.getGroupedParameterTypeName()) && (!clientMethod.getOnlyRequiredParameters() || clientMethod.getIsGroupedParameterRequired())) { - String nextGroupTypeCamelCaseName = CodeNamer.toCamelCase(pageDetails.getNextGroupParameterTypeName()); - String groupedTypeCamelCaseName = CodeNamer.toCamelCase(clientMethod.getGroupedParameterTypeName()); - - String nextGroupTypeCodeName = CodeNamer.getTypeName(pageDetails.getNextGroupParameterTypeName()) + (settings.isFluent() ? "Inner" : ""); - - if (!clientMethod.getIsGroupedParameterRequired()) { - subFunction.line(String.format("%1$s %2$s = null;", nextGroupTypeCodeName, nextGroupTypeCamelCaseName)); - subFunction.line(String.format("if (%s != null) {", groupedTypeCamelCaseName)); - subFunction.increaseIndent(); - subFunction.line(String.format("%1$s = new %2$s();", nextGroupTypeCamelCaseName, nextGroupTypeCodeName)); - } else { - subFunction.line(String.format("%1$s %2$s = new %3$s();", nextGroupTypeCodeName, nextGroupTypeCamelCaseName, nextGroupTypeCodeName)); - } - ClientMethod nextMethod = pageDetails.getNextMethod(); - for (ClientMethodParameter outputParameter : nextMethod.getMethodTransformationDetails().stream().map(MethodTransformationDetail::getOutParameter).collect(Collectors.toList())) { - String outputParameterName; - if (!outputParameter.getFromClient()) { - outputParameterName = outputParameter.getName(); - } else { - String caller = (pageDetails.nextMethodGroupName() == null || pageDetails.nextMethodGroupName().isEmpty()) ? "this" : "this.client"; - String clientPropertyName = outputParameter.getFromClient() ? outputParameter.getName() : null; - if (clientPropertyName != null && !clientPropertyName.isEmpty()) { - clientPropertyName = CodeNamer.toPascalCase(CodeNamer.removeInvalidCharacters(clientPropertyName)); - } - outputParameterName = String.format("%1$s.get%2$s()", caller, clientPropertyName); - } - subFunction.line(String.format("%1$s.%2$s(%3$s.%4$s());", nextGroupTypeCamelCaseName, CodeNamer.toCamelCase(outputParameterName), groupedTypeCamelCaseName, CodeNamer.toCamelCase(outputParameterName))); - } - if (!clientMethod.getIsGroupedParameterRequired()) { - subFunction.decreaseIndent(); - subFunction.line("}"); - } - } - } - subFunction.methodReturn(String.format("%1$s(%2$s).block()", pageDetails.getNextMethodInvocation() + "SinglePageAsync", pageDetails.getNextMethodParameterInvocation())); - }); - }); + typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { + function.methodReturn(String.format("new PagedIterable<>(%s(%s))", clientMethod.getSimpleAsyncMethodName(), clientMethod.getArgumentList())); }); break; case PagingAsync: // typeBlock.javadocComment(comment -> typeBlock.annotation("ServiceMethod(returns = ReturnType.COLLECTION)"); - typeBlock.publicMethod(clientMethod.getDeclaration(), function -> - { - function.line(String.format("return %1$s(%2$s)", clientMethod.getPagingAsyncSinglePageMethodName(), clientMethod.getArgumentList())); - function.indent(() -> - { - function.line(".repeat(1)"); - function.text(".concatMap("); - function.lambda(pageDetails.getPageType().toString(), "page", lambda -> { - lambda.line(String.format("String %s = page.nextPageLink();", pageDetails.getNextLinkVariableName())); - lambda.ifBlock(String.format("%s == null", pageDetails.getNextLinkVariableName()), ifBlock -> { - ifBlock.methodReturn("Flux.just(page)"); - }); - - if (clientMethod.getMethodTransformationDetails() != null && pageDetails.getNextMethod().getMethodTransformationDetails() != null) { - if (pageDetails.getNextGroupParameterTypeName() != clientMethod.getGroupedParameterTypeName() && (!clientMethod.getOnlyRequiredParameters() || clientMethod.getIsGroupedParameterRequired())) { - String nextGroupTypeCamelCaseName = CodeNamer.toCamelCase(pageDetails.getNextGroupParameterTypeName()); - String groupedTypeCamelCaseName = CodeNamer.toCamelCase(clientMethod.getGroupedParameterTypeName()); - - String nextGroupTypeCodeName = CodeNamer.getTypeName(pageDetails.getNextGroupParameterTypeName()) + (settings.isFluent() ? "Inner" : ""); - - if (!clientMethod.getIsGroupedParameterRequired()) { - lambda.line("%s %s = null", nextGroupTypeCodeName, nextGroupTypeCamelCaseName); - lambda.line("if (%s != null) {", groupedTypeCamelCaseName); - lambda.increaseIndent(); - lambda.line("%s = new %s();", nextGroupTypeCamelCaseName, nextGroupTypeCodeName); - } else { - lambda.line("%s %s = new %s()", nextGroupTypeCodeName, nextGroupTypeCamelCaseName, nextGroupTypeCodeName); - } - - for (ClientMethodParameter outputParameter : pageDetails.getNextMethod().getMethodTransformationDetails().stream().map(td -> td.getOutParameter()).collect(Collectors.toList())) { - String outputParameterName; - if (!outputParameter.getFromClient()) { - outputParameterName = CodeNamer.toCamelCase(outputParameter.getName()); - } else { - String caller = (pageDetails.nextMethodGroupName() == null || pageDetails.nextMethodGroupName().isEmpty()) ? "this" : "this.client"; - String clientPropertyName = outputParameter.getFromClient() ? outputParameter.getName() : null; - if (clientPropertyName != null && !clientPropertyName.isEmpty()) { - clientPropertyName = CodeNamer.toPascalCase(CodeNamer.removeInvalidCharacters(clientPropertyName)); - } - outputParameterName = String.format("%1$s.get%2$s()", caller, clientPropertyName); - } - lambda.line("%s.%s(%s.%s());", nextGroupTypeCamelCaseName, outputParameterName, groupedTypeCamelCaseName, outputParameterName); - } - - if (!clientMethod.getIsGroupedParameterRequired()) { - lambda.decreaseIndent(); - lambda.line("}"); - } - } - } - - lambda.lambdaReturn(String.format("Flux.just(page).concatWith(%sAsync(%s))", pageDetails.getNextMethodInvocation(), pageDetails.getNextMethodParameterInvocation())); - }); - function.line(");"); + typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { + function.line("return new PagedFlux<>("); + function.indent(() -> { + function.line("() -> %s(%s),", + clientMethod.getProxyMethod().getPagingAsyncSinglePageMethodName(), + clientMethod.getArgumentList()); + function.line("nextLink -> %s(%s));", + clientMethod.getMethodPageDetails().getNextMethod().getProxyMethod().getPagingAsyncSinglePageMethodName(), + clientMethod.getMethodPageDetails().getNextMethod().getArgumentList()); }); }); break; - case PagingAsyncSinglePage: typeBlock.annotation("ServiceMethod(returns = ReturnType.SINGLE)"); typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { - AddNullChecks(function, clientMethod.getRequiredNullableParameterExpressions(), settings); - AddValidations(function, clientMethod.getExpressionsToValidate(), settings); - AddOptionalAndConstantVariables(function, clientMethod, restAPIMethod.getParameters(), settings); - ApplyParameterTransformations(function, clientMethod, settings); - ConvertClientTypesToWireTypes(function, clientMethod, restAPIMethod.getParameters(), clientMethod.getClientReference(), settings); - - if (pageDetails.getIsNextMethod()) { - String methodUrl = restAPIMethod.getUrlPath(); - String substitutedMethodUrl = methodUrl.replaceAll("\\{\\w+}", "%s"); - - List retrofitParameters = restAPIMethod.getParameters().stream().filter(p -> p.getRequestParameterLocation() != RequestParameterLocation.None).collect(Collectors.toList()); - StringBuilder builder = new StringBuilder(String.format("String.format(\"%s\"", substitutedMethodUrl)); - Pattern pattern = Pattern.compile("\\{\\w+}"); - Matcher matcher = pattern.matcher(methodUrl); - while (matcher.find()) { - String serializedNameWithBrackets = matcher.group(); - String serializedName = serializedNameWithBrackets.substring(1, serializedNameWithBrackets.length() - 2); - ProxyMethodParameter parameter = retrofitParameters.stream().filter((p -> p.getRequestParameterName().equals(serializedName))).findFirst().get(); - - String parameterName; - if (!parameter.getFromClient()) { - parameterName = parameter.getName(); - } else { - parameterName = parameter.getParameterReference(); - } - - IType parameterModelType = parameter.getWireType(); - if (parameterModelType != null && !parameter.getIsNullable()) { - if (parameterModelType instanceof ClassType && ((ClassType) parameterModelType).isBoxedType()) { - parameterModelType = PrimitiveType.fromNullableType((ClassType) parameterModelType); - } - } - - IType parameterClientType = parameterModelType.getClientType(); - - IType parameterWireType; - if (parameterModelType.equals(GenericType.FluxByteBuffer)) { - parameterWireType = parameterClientType; - } else if (!parameterModelType.equals(ClassType.Base64Url) && - parameter.getRequestParameterLocation() != RequestParameterLocation.Body && - //parameter.getRequestParameterLocation() != RequestParameterLocation.FormData && - (parameterClientType instanceof ArrayType || parameterClientType instanceof ListType)) { - parameterWireType = ClassType.String; - } else { - parameterWireType = parameterModelType; - } - - String parameterWireName = !parameterClientType.toString().equals(parameterWireType.toString()) ? CodeNamer.toCamelCase(parameterName) + "Converted" : parameterName; - builder.append(", ").append(parameterWireName); - } - builder.append(")"); - - function.line("String nextUrl = %s;", builder.toString()); - } - }); - break; - case SimulatedPagingSync: - typeBlock.annotation("ServiceMethod(returns = ReturnType.COLLECTION)"); - typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { - function.line("%s page = new %s<>();", pageDetails.getPageImplType(), pageDetails.getPageImplType()); - function.line("page.setItems(%s(%s).single().items());", clientMethod.getSimpleAsyncMethodName(), clientMethod.getArgumentList()); - function.line("page.setNextPageLink(null);"); - function.returnAnonymousClass(String.format("new %s(page)", clientMethod.getReturnValue().getType()), anonymousClass -> { - anonymousClass.annotation("Override"); - anonymousClass.publicMethod("{pageDetails.PageType} nextPage(String nextPageLink)", subFunction -> { - subFunction.methodReturn("null"); - }); - }); - }); - break; - - case SimulatedPagingAsync: - typeBlock.annotation("ServiceMethod(returns = ReturnType.COLLECTION)"); - typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { - AddNullChecks(function, clientMethod.getRequiredNullableParameterExpressions(), settings); - AddValidations(function, clientMethod.getExpressionsToValidate(), settings); - AddOptionalAndConstantVariables(function, clientMethod, restAPIMethod.getParameters(), settings); - ApplyParameterTransformations(function, clientMethod, settings); - ConvertClientTypesToWireTypes(function, clientMethod, restAPIMethod.getParameters(), clientMethod.getClientReference(), settings); - - IType returnValueTypeArgumentType = ((GenericType) restAPIMethod.getReturnType()).getTypeArguments()[0]; - String restAPIMethodArgumentList = String.join(", ", clientMethod.getProxyMethodArguments(settings)); - function.line("return service.%s(%s)", clientMethod.getProxyMethod().getName(), restAPIMethodArgumentList); + function.line("return service.%s(%s).map(res -> new PagedResponseBase<>(", + clientMethod.getProxyMethod().getName(), + String.join(", ", clientMethod.getProxyMethodArguments(settings))); function.indent(() -> { - function.text(".map("); - function.lambda(returnValueTypeArgumentType.toString(), "res", "res.value()"); - function.line(")"); - function.line(".repeat(1);"); + function.line("res.getRequest(),"); + function.line("res.getStatusCode(),"); + function.line("res.getHeaders(),"); + function.line("res.getValue().get%s(),", CodeNamer.toPascalCase(clientMethod.getMethodPageDetails().getItemName())); + function.line("res.getValue().get%s(),", CodeNamer.toPascalCase(clientMethod.getMethodPageDetails().getNextLinkName())); + IType responseType = ((GenericType) clientMethod.getProxyMethod().getReturnType()).getTypeArguments()[0]; + if (responseType instanceof ClassType) { + function.line("res.getDeserializedHeaders()));"); + } else { + function.line("null));"); + } }); }); break; + // TODO: Simulated paging +// case SimulatedPagingSync: +// typeBlock.annotation("ServiceMethod(returns = ReturnType.COLLECTION)"); +// typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { +// function.line("%s page = new %s<>();", pageDetails.getPageImplType(), pageDetails.getPageImplType()); +// function.line("page.setItems(%s(%s).single().items());", clientMethod.getSimpleAsyncMethodName(), clientMethod.getArgumentList()); +// function.line("page.setNextPageLink(null);"); +// function.returnAnonymousClass(String.format("new %s(page)", clientMethod.getReturnValue().getType()), anonymousClass -> { +// anonymousClass.annotation("Override"); +// anonymousClass.publicMethod("{pageDetails.PageType} nextPage(String nextPageLink)", subFunction -> { +// subFunction.methodReturn("null"); +// }); +// }); +// }); +// break; +// +// case SimulatedPagingAsync: +// typeBlock.annotation("ServiceMethod(returns = ReturnType.COLLECTION)"); +// typeBlock.publicMethod(clientMethod.getDeclaration(), function -> { +// AddNullChecks(function, clientMethod.getRequiredNullableParameterExpressions(), settings); +// AddValidations(function, clientMethod.getExpressionsToValidate(), settings); +// AddOptionalAndConstantVariables(function, clientMethod, restAPIMethod.getParameters(), settings); +// ApplyParameterTransformations(function, clientMethod, settings); +// ConvertClientTypesToWireTypes(function, clientMethod, restAPIMethod.getParameters(), clientMethod.getClientReference(), settings); +// +// IType returnValueTypeArgumentType = ((GenericType) restAPIMethod.getReturnType()).getTypeArguments()[0]; +// String restAPIMethodArgumentList = String.join(", ", clientMethod.getProxyMethodArguments(settings)); +// function.line("return service.%s(%s)", clientMethod.getProxyMethod().getName(), restAPIMethodArgumentList); +// function.indent(() -> { +// function.text(".map("); +// function.lambda(returnValueTypeArgumentType.toString(), "res", "res.value()"); +// function.line(")"); +// function.line(".repeat(1);"); +// }); +// }); +// break; case LongRunningSync: typeBlock.annotation("ServiceMethod(returns = ReturnType.SINGLE)"); diff --git a/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java index 410773e556..af1f9233da 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java @@ -80,7 +80,7 @@ public final void write(Proxy restAPI, JavaClass classBlock) { case Query: case Header: parameterDeclarationBuilder.append(String.format("@%1$sParam(", CodeNamer.toPascalCase(parameter.getRequestParameterLocation().toString()))); - if ((parameter.getRequestParameterLocation() == RequestParameterLocation.Path || parameter.getRequestParameterLocation() == RequestParameterLocation.Query) && settings.isAzureOrFluent() && parameter.getAlreadyEncoded()) { + if ((parameter.getRequestParameterLocation() == RequestParameterLocation.Path || parameter.getRequestParameterLocation() == RequestParameterLocation.Query) && parameter.getAlreadyEncoded()) { parameterDeclarationBuilder.append(String.format("value = \"%1$s\", encoded = true", parameter.getRequestParameterName())); } else if (parameter.getRequestParameterLocation() == RequestParameterLocation.Header && parameter.getHeaderCollectionPrefix() != null && !parameter.getHeaderCollectionPrefix().isEmpty()) { parameterDeclarationBuilder.append(String.format("\"%1$s\"", parameter.getHeaderCollectionPrefix())); diff --git a/javagen/src/main/java/com/azure/autorest/transformer/Transformer.java b/javagen/src/main/java/com/azure/autorest/transformer/Transformer.java index ea518108f5..5f8e0a9e3c 100644 --- a/javagen/src/main/java/com/azure/autorest/transformer/Transformer.java +++ b/javagen/src/main/java/com/azure/autorest/transformer/Transformer.java @@ -4,16 +4,25 @@ import com.azure.autorest.extension.base.model.codemodel.ChoiceSchema; import com.azure.autorest.extension.base.model.codemodel.CodeModel; import com.azure.autorest.extension.base.model.codemodel.Language; +import com.azure.autorest.extension.base.model.codemodel.Languages; import com.azure.autorest.extension.base.model.codemodel.Metadata; import com.azure.autorest.extension.base.model.codemodel.ObjectSchema; import com.azure.autorest.extension.base.model.codemodel.Operation; import com.azure.autorest.extension.base.model.codemodel.OperationGroup; import com.azure.autorest.extension.base.model.codemodel.Parameter; import com.azure.autorest.extension.base.model.codemodel.Property; +import com.azure.autorest.extension.base.model.codemodel.Protocol; +import com.azure.autorest.extension.base.model.codemodel.Protocols; +import com.azure.autorest.extension.base.model.codemodel.Request; +import com.azure.autorest.extension.base.model.codemodel.RequestParameterLocation; import com.azure.autorest.extension.base.model.codemodel.Schemas; import com.azure.autorest.extension.base.model.codemodel.SealedChoiceSchema; +import com.azure.autorest.extension.base.model.codemodel.StringSchema; +import com.azure.autorest.extension.base.model.extensionmodel.XmsExtensions; import com.azure.autorest.util.CodeNamer; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class Transformer { @@ -43,6 +52,7 @@ private void transformSchemas(Schemas schemas) { } private void transformOperationGroups(List operationGroups, CodeModel codeModel) { + List pagingOperations = new ArrayList<>(); for (OperationGroup operationGroup : operationGroups) { operationGroup.setCodeModel(codeModel); renameMethodGroup(operationGroup); @@ -53,14 +63,118 @@ private void transformOperationGroups(List operationGroups, Code parameter.setOperation(operation); renameVariable(parameter); } + + if (operation.getExtensions() != null && operation.getExtensions().getXmsPageable() != null) { + pagingOperations.add(operation); + } } } + + // paging + for (Operation operation : pagingOperations) { + addPagingNextOperation(codeModel, operation.getOperationGroup(), operation); + } + } + + private void addPagingNextOperation(CodeModel codeModel, OperationGroup operationGroup, Operation operation) { + String operationGroupName; + String operationName; + if (operation.getExtensions().getXmsPageable().getOperationName() != null) { + String operationGroupAndName = operation.getExtensions().getXmsPageable().getOperationName(); + if (operationGroupAndName.contains("_")) { + String[] parts = operationGroupAndName.split("_", 2); + operationGroupName = CodeNamer.getMethodGroupName(parts[0]); + operationName = CodeNamer.getMethodName(parts[1]); + } else { + operationGroupName = operationGroup.getLanguage().getJava().getName(); + operationName = CodeNamer.getMethodName(operationGroupAndName); + } + } else { + operationGroupName = operationGroup.getLanguage().getJava().getName(); + operationName = operation.getLanguage().getJava().getName() + "Next"; + } + if (!codeModel.getOperationGroups().stream() + .anyMatch(og -> og.getLanguage().getJava().getName().equals(operationGroupName))) { + OperationGroup newOg = new OperationGroup(); + newOg.setCodeModel(codeModel); + newOg.set$key(operationGroupName); + newOg.setOperations(new ArrayList<>()); + newOg.setExtensions(operationGroup.getExtensions()); + newOg.setLanguage(new Languages()); + newOg.getLanguage().setJava(new Language()); + newOg.getLanguage().getJava().setName(operationGroupName); + newOg.getLanguage().getJava().setDescription(operationGroup.getLanguage().getJava().getDescription()); + newOg.setProtocol(operationGroup.getProtocol()); + + codeModel.getOperationGroups().add(newOg); + operationGroup = newOg; + } + + if (!operationGroup.getOperations().stream() + .anyMatch(o -> o.getLanguage().getJava().getName().equals(operationName))) { + Operation nextOperation = new Operation(); + nextOperation.setOperationGroup(operationGroup); + nextOperation.set$key(operationName); + nextOperation.setLanguage(new Languages()); + nextOperation.getLanguage().setJava(new Language()); + nextOperation.getLanguage().getJava().setName(operationName); + nextOperation.getLanguage().getJava().setDescription("Get the next page of items"); + nextOperation.setRequest(new Request()); + nextOperation.getRequest().setProtocol(new Protocols()); + nextOperation.getRequest().getProtocol().setHttp(new Protocol()); + nextOperation.getRequest().getProtocol().getHttp().setPath("{nextLink}"); + nextOperation.getRequest().getProtocol().getHttp().setUri(operation.getRequest().getProtocol().getHttp().getUri()); + nextOperation.getRequest().getProtocol().getHttp().setMethod("get"); + nextOperation.getRequest().setExtensions(operation.getRequest().getExtensions()); + nextOperation.getRequest().setLanguage(operation.getLanguage()); + Parameter nextLink = new Parameter(); + nextLink.setOperation(nextOperation); + nextLink.setImplementation(Parameter.ImplementationLocation.METHOD); + nextLink.set$key("nextLink"); + nextLink.setNullable(false); + nextLink.setSummary("The URL to get the next list of items"); + nextLink.setSchema(new StringSchema()); + nextLink.setRequired(true); + nextLink.setLanguage(new Languages()); + nextLink.getLanguage().setJava(new Language()); + nextLink.getLanguage().getJava().setName("nextLink"); + nextLink.getLanguage().getJava().setSerializedName("nextLink"); + nextLink.getLanguage().setDefault(nextLink.getLanguage().getJava()); + nextLink.setProtocol(new Protocols()); + nextLink.getProtocol().setHttp(new Protocol()); + nextLink.getProtocol().getHttp().setIn(RequestParameterLocation.Path); + nextLink.setExtensions(new XmsExtensions()); + nextLink.getExtensions().setXmsSkipUrlEncoding(true); + nextOperation.getRequest().setParameters(Collections.singletonList(nextLink)); + nextOperation.setApiVersions(operation.getApiVersions()); + nextOperation.setDeprecated(operation.getDeprecated()); + nextOperation.setDescription(operation.getDescription()); + nextOperation.setExceptions(operation.getExceptions()); + nextOperation.setExtensions(operation.getExtensions()); + nextOperation.setExternalDocs(operation.getExternalDocs()); + nextOperation.setProfile(operation.getProfile()); + nextOperation.setResponses(operation.getResponses()); + nextOperation.setSummary(operation.getSummary()); + nextOperation.setUid(operation.getUid()); + + operation.getExtensions().getXmsPageable().setNextOperation(nextOperation); + nextOperation.getExtensions().getXmsPageable().setNextOperation(nextOperation); + operationGroup.getOperations().add(nextOperation); + } else { + Operation nextOperation = operationGroup.getOperations().stream() + .filter(o -> o.getLanguage().getJava().getName().equals(operationName)) + .findFirst().get(); + operation.getExtensions().getXmsPageable().setNextOperation(nextOperation); + nextOperation.getExtensions().getXmsPageable().setNextOperation(nextOperation); + } } private void renameType(Metadata schema) { Language language = schema.getLanguage().getDefault(); Language java = new Language(); java.setName(CodeNamer.getTypeName(language.getName())); + java.setSerializedName(language.getSerializedName()); + java.setDescription(language.getDescription()); schema.getLanguage().setJava(java); } @@ -68,6 +182,8 @@ private void renameProperty(Property property) { Language language = property.getLanguage().getDefault(); Language java = new Language(); java.setName(CodeNamer.getPropertyName(language.getName())); + java.setSerializedName(language.getSerializedName()); + java.setDescription(language.getDescription()); property.getLanguage().setJava(java); } @@ -83,6 +199,8 @@ private void renameVariable(Metadata schema) { Language language = schema.getLanguage().getDefault(); Language java = new Language(); java.setName(CodeNamer.getParameterName(language.getName())); + java.setSerializedName(language.getSerializedName()); + java.setDescription(language.getDescription()); schema.getLanguage().setJava(java); } @@ -90,6 +208,8 @@ private void renameMethodGroup(Metadata schema) { Language language = schema.getLanguage().getDefault(); Language java = new Language(); java.setName(CodeNamer.getMethodGroupName(language.getName())); + java.setSerializedName(language.getSerializedName()); + java.setDescription(language.getDescription()); schema.getLanguage().setJava(java); } @@ -97,6 +217,8 @@ private void renameMethod(Metadata schema) { Language language = schema.getLanguage().getDefault(); Language java = new Language(); java.setName(CodeNamer.getMethodName(language.getName())); + java.setSerializedName(language.getSerializedName()); + java.setDescription(language.getDescription()); schema.getLanguage().setJava(java); } } diff --git a/tests/pom.xml b/tests/pom.xml index 19ae8e78b4..b16d170035 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -18,7 +18,7 @@ com.azure azure-core - 1.1.0 + 1.2.0-beta.1 com.azure diff --git a/tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java b/tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java index 0109ede0f2..431f6ec794 100644 --- a/tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java +++ b/tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java @@ -62,19 +62,19 @@ private interface HttpClientFailuresService { @Put("/http/failure/client/400") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put400(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put400(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/failure/client/400") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch400(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch400(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/failure/client/400") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post400(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post400(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/failure/client/400") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete400(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete400(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/failure/client/401") @UnexpectedResponseExceptionType(ErrorException.class) @@ -90,23 +90,23 @@ private interface HttpClientFailuresService { @Put("/http/failure/client/404") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put404(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put404(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/failure/client/405") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch405(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch405(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/failure/client/406") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post406(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post406(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/failure/client/407") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete407(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete407(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Put("/http/failure/client/409") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put409(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put409(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/failure/client/410") @UnexpectedResponseExceptionType(ErrorException.class) @@ -122,15 +122,15 @@ private interface HttpClientFailuresService { @Put("/http/failure/client/413") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put413(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put413(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/failure/client/414") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch414(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch414(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/failure/client/415") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post415(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post415(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Get("/http/failure/client/416") @UnexpectedResponseExceptionType(ErrorException.class) @@ -138,7 +138,7 @@ private interface HttpClientFailuresService { @Delete("/http/failure/client/417") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete417(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete417(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/failure/client/429") @UnexpectedResponseExceptionType(ErrorException.class) @@ -179,7 +179,7 @@ public void get400() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put400WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put400(this.client.getHost(), booleanValue); } @@ -196,7 +196,7 @@ public void put400() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch400WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch400(this.client.getHost(), booleanValue); } @@ -213,7 +213,7 @@ public void patch400() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post400WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post400(this.client.getHost(), booleanValue); } @@ -230,7 +230,7 @@ public void post400() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete400WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete400(this.client.getHost(), booleanValue); } @@ -295,7 +295,7 @@ public void get403() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put404WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put404(this.client.getHost(), booleanValue); } @@ -312,7 +312,7 @@ public void put404() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch405WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch405(this.client.getHost(), booleanValue); } @@ -329,7 +329,7 @@ public void patch405() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post406WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post406(this.client.getHost(), booleanValue); } @@ -346,7 +346,7 @@ public void post406() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete407WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete407(this.client.getHost(), booleanValue); } @@ -363,7 +363,7 @@ public void delete407() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put409WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put409(this.client.getHost(), booleanValue); } @@ -428,7 +428,7 @@ public void get412() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put413WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put413(this.client.getHost(), booleanValue); } @@ -445,7 +445,7 @@ public void put413() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch414WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch414(this.client.getHost(), booleanValue); } @@ -462,7 +462,7 @@ public void patch414() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post415WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post415(this.client.getHost(), booleanValue); } @@ -495,7 +495,7 @@ public void get416() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete417WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete417(this.client.getHost(), booleanValue); } diff --git a/tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java b/tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java index 1150e80aa6..19affd5abf 100644 --- a/tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java +++ b/tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java @@ -90,7 +90,7 @@ private interface HttpRedirectsService { @Put("/http/redirect/301") @ExpectedResponses({301}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono put301(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono put301(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/redirect/302") @ExpectedResponses({200, 302}) @@ -105,12 +105,12 @@ private interface HttpRedirectsService { @Patch("/http/redirect/302") @ExpectedResponses({302}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono patch302(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono patch302(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/redirect/303") @ExpectedResponses({200, 303}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono post303(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono post303(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/redirect/307") @ExpectedResponses({200, 307}) @@ -125,22 +125,22 @@ private interface HttpRedirectsService { @Put("/http/redirect/307") @ExpectedResponses({200, 307}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono put307(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono put307(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/redirect/307") @ExpectedResponses({200, 307}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono patch307(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono patch307(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/redirect/307") @ExpectedResponses({200, 307}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono post307(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono post307(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/redirect/307") @ExpectedResponses({200, 307}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono delete307(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono delete307(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); } @ServiceMethod(returns = ReturnType.SINGLE) @@ -215,7 +215,7 @@ public void get301() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono put301WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put301(this.client.getHost(), booleanValue); } @@ -264,7 +264,7 @@ public void get302() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono patch302WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch302(this.client.getHost(), booleanValue); } @@ -281,7 +281,7 @@ public void patch302() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono post303WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post303(this.client.getHost(), booleanValue); } @@ -330,7 +330,7 @@ public void get307() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono put307WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put307(this.client.getHost(), booleanValue); } @@ -347,7 +347,7 @@ public void put307() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono patch307WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch307(this.client.getHost(), booleanValue); } @@ -364,7 +364,7 @@ public void patch307() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono post307WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post307(this.client.getHost(), booleanValue); } @@ -381,7 +381,7 @@ public void post307() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono delete307WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete307(this.client.getHost(), booleanValue); } diff --git a/tests/src/main/java/fixtures/httpinfrastructure/HttpRetrys.java b/tests/src/main/java/fixtures/httpinfrastructure/HttpRetrys.java index 34573bb17d..ec71b21736 100644 --- a/tests/src/main/java/fixtures/httpinfrastructure/HttpRetrys.java +++ b/tests/src/main/java/fixtures/httpinfrastructure/HttpRetrys.java @@ -60,12 +60,12 @@ private interface HttpRetrysService { @Put("/http/retry/500") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put500(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put500(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/retry/500") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch500(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch500(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Get("/http/retry/502") @ExpectedResponses({200}) @@ -75,22 +75,22 @@ private interface HttpRetrysService { @Post("/http/retry/503") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post503(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post503(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/retry/503") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete503(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete503(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Put("/http/retry/504") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put504(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put504(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/retry/504") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch504(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch504(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); } @ServiceMethod(returns = ReturnType.SINGLE) @@ -111,7 +111,7 @@ public void head408() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put500WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put500(this.client.getHost(), booleanValue); } @@ -128,7 +128,7 @@ public void put500() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch500WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch500(this.client.getHost(), booleanValue); } @@ -161,7 +161,7 @@ public void get502() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post503WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post503(this.client.getHost(), booleanValue); } @@ -178,7 +178,7 @@ public void post503() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete503WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete503(this.client.getHost(), booleanValue); } @@ -195,7 +195,7 @@ public void delete503() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put504WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put504(this.client.getHost(), booleanValue); } @@ -212,7 +212,7 @@ public void put504() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch504WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch504(this.client.getHost(), booleanValue); } diff --git a/tests/src/main/java/fixtures/httpinfrastructure/HttpServerFailures.java b/tests/src/main/java/fixtures/httpinfrastructure/HttpServerFailures.java index 1fdd6d7627..9783bac2c7 100644 --- a/tests/src/main/java/fixtures/httpinfrastructure/HttpServerFailures.java +++ b/tests/src/main/java/fixtures/httpinfrastructure/HttpServerFailures.java @@ -60,11 +60,11 @@ private interface HttpServerFailuresService { @Post("/http/failure/server/505") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post505(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post505(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/failure/server/505") @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete505(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete505(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); } @ServiceMethod(returns = ReturnType.SINGLE) @@ -101,7 +101,7 @@ public void get501() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post505WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post505(this.client.getHost(), booleanValue); } @@ -118,7 +118,7 @@ public void post505() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete505WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete505(this.client.getHost(), booleanValue); } diff --git a/tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java b/tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java index ec00da99ab..83304212ea 100644 --- a/tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java +++ b/tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java @@ -66,52 +66,52 @@ private interface HttpSuccessService { @Put("/http/success/200") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put200(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put200(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/success/200") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch200(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch200(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/success/200") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post200(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post200(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/success/200") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete200(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete200(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Put("/http/success/201") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put201(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put201(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/success/201") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post201(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post201(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Put("/http/success/202") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put202(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put202(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/success/202") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch202(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch202(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/success/202") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post202(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post202(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/success/202") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete202(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete202(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/success/204") @ExpectedResponses({204}) @@ -121,22 +121,22 @@ private interface HttpSuccessService { @Put("/http/success/204") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> put204(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> put204(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Patch("/http/success/204") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> patch204(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> patch204(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Post("/http/success/204") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> post204(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> post204(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Delete("/http/success/204") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(ErrorException.class) - Mono> delete204(@HostParam("$host") String host, @BodyParam("application/json") boolean booleanValue); + Mono> delete204(@HostParam("$host") String host, @BodyParam("application/json") Boolean booleanValue); @Head("/http/success/404") @ExpectedResponses({204, 404}) @@ -184,7 +184,7 @@ public boolean get200() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put200WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put200(this.client.getHost(), booleanValue); } @@ -201,7 +201,7 @@ public void put200() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch200WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch200(this.client.getHost(), booleanValue); } @@ -218,7 +218,7 @@ public void patch200() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post200WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post200(this.client.getHost(), booleanValue); } @@ -235,7 +235,7 @@ public void post200() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete200WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete200(this.client.getHost(), booleanValue); } @@ -252,7 +252,7 @@ public void delete200() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put201WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put201(this.client.getHost(), booleanValue); } @@ -269,7 +269,7 @@ public void put201() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post201WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post201(this.client.getHost(), booleanValue); } @@ -286,7 +286,7 @@ public void post201() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put202WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put202(this.client.getHost(), booleanValue); } @@ -303,7 +303,7 @@ public void put202() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch202WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch202(this.client.getHost(), booleanValue); } @@ -320,7 +320,7 @@ public void patch202() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post202WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post202(this.client.getHost(), booleanValue); } @@ -337,7 +337,7 @@ public void post202() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete202WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete202(this.client.getHost(), booleanValue); } @@ -370,7 +370,7 @@ public void head204() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> put204WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.put204(this.client.getHost(), booleanValue); } @@ -387,7 +387,7 @@ public void put204() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> patch204WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.patch204(this.client.getHost(), booleanValue); } @@ -404,7 +404,7 @@ public void patch204() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> post204WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.post204(this.client.getHost(), booleanValue); } @@ -421,7 +421,7 @@ public void post204() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> delete204WithResponseAsync() { - final boolean booleanValue = true; + final Boolean booleanValue = true; return service.delete204(this.client.getHost(), booleanValue); } diff --git a/tests/src/main/java/fixtures/paging/AutoRestPagingTestService.java b/tests/src/main/java/fixtures/paging/AutoRestPagingTestService.java new file mode 100644 index 0000000000..1f901b4865 --- /dev/null +++ b/tests/src/main/java/fixtures/paging/AutoRestPagingTestService.java @@ -0,0 +1,82 @@ +package fixtures.paging; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; + +/** + * Initializes a new instance of the AutoRestPagingTestService type. + */ +public final class AutoRestPagingTestService { + /** + * http://localhost:3000. + */ + private String host; + + /** + * Gets http://localhost:3000. + * + * @return the host value. + */ + public String getHost() { + return this.host; + } + + /** + * Sets http://localhost:3000. + * + * @param host the host value. + * @return the service client itself. + */ + AutoRestPagingTestService setHost(String host) { + this.host = host; + return this; + } + + /** + * The HTTP pipeline to send requests through. + */ + private HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The Pagings object to access its operations. + */ + private Pagings pagings; + + /** + * Gets the Pagings object to access its operations. + * + * @return the Pagings object. + */ + public Pagings pagings() { + return this.pagings; + } + + /** + * Initializes an instance of AutoRestPagingTestService client. + */ + public AutoRestPagingTestService() { + new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()).build(); + } + + /** + * Initializes an instance of AutoRestPagingTestService client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + */ + public AutoRestPagingTestService(HttpPipeline httpPipeline) { + this.httpPipeline = httpPipeline; + this.pagings = new Pagings(this); + } +} diff --git a/tests/src/main/java/fixtures/paging/AutoRestPagingTestServiceBuilder.java b/tests/src/main/java/fixtures/paging/AutoRestPagingTestServiceBuilder.java new file mode 100644 index 0000000000..ec51594d4d --- /dev/null +++ b/tests/src/main/java/fixtures/paging/AutoRestPagingTestServiceBuilder.java @@ -0,0 +1,65 @@ +package fixtures.paging; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; + +/** + * A builder for creating a new instance of the AutoRestPagingTestService type. + */ +@ServiceClientBuilder(serviceClients = AutoRestPagingTestService.class) +public final class AutoRestPagingTestServiceBuilder { + /* + * http://localhost:3000 + */ + private String host; + + /** + * Sets http://localhost:3000. + * + * @param host the host value. + * @return the AutoRestPagingTestServiceBuilder. + */ + public AutoRestPagingTestServiceBuilder host(String host) { + this.host = host; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the AutoRestPagingTestServiceBuilder. + */ + public AutoRestPagingTestServiceBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /** + * Builds an instance of AutoRestPagingTestService with the provided parameters. + * + * @return an instance of AutoRestPagingTestService. + */ + public AutoRestPagingTestService build() { + if (host == null) { + this.host = "http://localhost:3000"; + } + if (pipeline == null) { + this.pipeline = new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()).build(); + } + AutoRestPagingTestService client = new AutoRestPagingTestService(pipeline); + if (this.host != null) { + client.setHost(this.host); + } + return client; + } +} diff --git a/tests/src/main/java/fixtures/paging/Pagings.java b/tests/src/main/java/fixtures/paging/Pagings.java new file mode 100644 index 0000000000..38f8aef028 --- /dev/null +++ b/tests/src/main/java/fixtures/paging/Pagings.java @@ -0,0 +1,659 @@ +package fixtures.paging; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.HttpResponseException; +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.RestProxy; +import com.azure.core.http.rest.SimpleResponse; +import fixtures.paging.models.OdataProductResult; +import fixtures.paging.models.Product; +import fixtures.paging.models.ProductResult; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in + * Pagings. + */ +public final class Pagings { + /** + * The proxy service used to perform REST calls. + */ + private PagingsService service; + + /** + * The service client containing this operation class. + */ + private AutoRestPagingTestService client; + + /** + * Initializes an instance of Pagings. + * + * @param client the instance of the service client containing this operation class. + */ + public Pagings(AutoRestPagingTestService client) { + this.service = RestProxy.create(PagingsService.class, client.getHttpPipeline()); + this.client = client; + } + + /** + * The interface defining all the services for + * AutoRestPagingTestServicePagings to be used by the proxy service to + * perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "AutoRestPagingTestServicePagings") + private interface PagingsService { + @Get("/paging/single") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSinglePages(@HostParam("$host") String host); + + @Get("/paging/multiple") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePages(@HostParam("$host") String host, @HeaderParam("client-request-id") String clientRequestId, @HeaderParam("maxresults") Integer maxresults, @HeaderParam("timeout") Integer timeout); + + @Get("/paging/multiple/odata") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getOdataMultiplePages(@HostParam("$host") String host, @HeaderParam("client-request-id") String clientRequestId, @HeaderParam("maxresults") Integer maxresults, @HeaderParam("timeout") Integer timeout); + + @Get("/paging/multiple/withpath/{offset}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesWithOffset(@HostParam("$host") String host, @HeaderParam("client-request-id") String clientRequestId, @HeaderParam("maxresults") Integer maxresults, @PathParam("offset") int offset, @HeaderParam("timeout") Integer timeout); + + @Get("/paging/multiple/retryfirst") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesRetryFirst(@HostParam("$host") String host); + + @Get("/paging/multiple/retrysecond") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesRetrySecond(@HostParam("$host") String host); + + @Get("/paging/single/failure") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSinglePagesFailure(@HostParam("$host") String host); + + @Get("/paging/multiple/failure") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesFailure(@HostParam("$host") String host); + + @Get("/paging/multiple/failureuri") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesFailureUri(@HostParam("$host") String host); + + @Get("/paging/multiple/fragment/{tenant}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesFragmentNextLink(@HostParam("$host") String host, @QueryParam("api_version") String apiVersion, @PathParam("tenant") String tenant); + + @Get("/paging/multiple/fragmentwithgrouping/{tenant}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesFragmentWithGroupingNextLink(@HostParam("$host") String host, @QueryParam("api_version") String apiVersion, @PathParam("tenant") String tenant); + + @Post("/paging/multiple/lro") + @ExpectedResponses({202}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesLRO(@HostParam("$host") String host, @HeaderParam("client-request-id") String clientRequestId, @HeaderParam("maxresults") Integer maxresults, @HeaderParam("timeout") Integer timeout); + + @Get("/paging/multiple/fragment/{tenant}/{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> nextFragment(@HostParam("$host") String host, @QueryParam("api_version") String apiVersion, @PathParam("tenant") String tenant, @PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("/paging/multiple/fragmentwithgrouping/{tenant}/{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> nextFragmentWithGrouping(@HostParam("$host") String host, @QueryParam("api_version") String apiVersion, @PathParam("tenant") String tenant, @PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSinglePagesNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getOdataMultiplePagesNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesWithOffsetNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesRetryFirstNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesRetrySecondNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSinglePagesFailureNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesFailureNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesFailureUriNext(@PathParam(value = "nextLink", encoded = true) String nextLink); + + @Get("{nextLink}") + @ExpectedResponses({202}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getMultiplePagesLRONext(@PathParam(value = "nextLink", encoded = true) String nextLink); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSinglePagesSinglePageAsync() { + return service.getSinglePages(this.client.getHost()).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getSinglePagesAsync() { + return new PagedFlux<>( + () -> getSinglePagesSinglePageAsync(), + nextLink -> getSinglePagesNextSinglePageAsync(nextLink)); + } + + /** + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getSinglePages() { + return new PagedIterable<>(getSinglePagesAsync()); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesSinglePageAsync(String clientRequestId, Integer maxresults, Integer timeout) { + return service.getMultiplePages(this.client.getHost(), clientRequestId, maxresults, timeout).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesAsync(String clientRequestId, Integer maxresults, Integer timeout) { + return new PagedFlux<>( + () -> getMultiplePagesSinglePageAsync(clientRequestId, maxresults, timeout), + nextLink -> getMultiplePagesNextSinglePageAsync(nextLink)); + } + + /** + * @param clientRequestId null + * @param maxresults null + * @param timeout null + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePages(String clientRequestId, Integer maxresults, Integer timeout) { + return new PagedIterable<>(getMultiplePagesAsync(clientRequestId, maxresults, timeout)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getOdataMultiplePagesSinglePageAsync(String clientRequestId, Integer maxresults, Integer timeout) { + return service.getOdataMultiplePages(this.client.getHost(), clientRequestId, maxresults, timeout).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getOdatanextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getOdataMultiplePagesAsync(String clientRequestId, Integer maxresults, Integer timeout) { + return new PagedFlux<>( + () -> getOdataMultiplePagesSinglePageAsync(clientRequestId, maxresults, timeout), + nextLink -> getOdataMultiplePagesNextSinglePageAsync(nextLink)); + } + + /** + * @param clientRequestId null + * @param maxresults null + * @param timeout null + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getOdataMultiplePages(String clientRequestId, Integer maxresults, Integer timeout) { + return new PagedIterable<>(getOdataMultiplePagesAsync(clientRequestId, maxresults, timeout)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesWithOffsetSinglePageAsync(String clientRequestId, Integer maxresults, int offset, Integer timeout) { + return service.getMultiplePagesWithOffset(this.client.getHost(), clientRequestId, maxresults, offset, timeout).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesWithOffsetAsync(String clientRequestId, Integer maxresults, int offset, Integer timeout) { + return new PagedFlux<>( + () -> getMultiplePagesWithOffsetSinglePageAsync(clientRequestId, maxresults, offset, timeout), + nextLink -> getMultiplePagesWithOffsetNextSinglePageAsync(nextLink)); + } + + /** + * @param clientRequestId null + * @param maxresults null + * @param offset null + * @param timeout null + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesWithOffset(String clientRequestId, Integer maxresults, int offset, Integer timeout) { + return new PagedIterable<>(getMultiplePagesWithOffsetAsync(clientRequestId, maxresults, offset, timeout)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesRetryFirstSinglePageAsync() { + return service.getMultiplePagesRetryFirst(this.client.getHost()).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesRetryFirstAsync() { + return new PagedFlux<>( + () -> getMultiplePagesRetryFirstSinglePageAsync(), + nextLink -> getMultiplePagesRetryFirstNextSinglePageAsync(nextLink)); + } + + /** + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesRetryFirst() { + return new PagedIterable<>(getMultiplePagesRetryFirstAsync()); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesRetrySecondSinglePageAsync() { + return service.getMultiplePagesRetrySecond(this.client.getHost()).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesRetrySecondAsync() { + return new PagedFlux<>( + () -> getMultiplePagesRetrySecondSinglePageAsync(), + nextLink -> getMultiplePagesRetrySecondNextSinglePageAsync(nextLink)); + } + + /** + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesRetrySecond() { + return new PagedIterable<>(getMultiplePagesRetrySecondAsync()); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSinglePagesFailureSinglePageAsync() { + return service.getSinglePagesFailure(this.client.getHost()).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getSinglePagesFailureAsync() { + return new PagedFlux<>( + () -> getSinglePagesFailureSinglePageAsync(), + nextLink -> getSinglePagesFailureNextSinglePageAsync(nextLink)); + } + + /** + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getSinglePagesFailure() { + return new PagedIterable<>(getSinglePagesFailureAsync()); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesFailureSinglePageAsync() { + return service.getMultiplePagesFailure(this.client.getHost()).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesFailureAsync() { + return new PagedFlux<>( + () -> getMultiplePagesFailureSinglePageAsync(), + nextLink -> getMultiplePagesFailureNextSinglePageAsync(nextLink)); + } + + /** + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesFailure() { + return new PagedIterable<>(getMultiplePagesFailureAsync()); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesFailureUriSinglePageAsync() { + return service.getMultiplePagesFailureUri(this.client.getHost()).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesFailureUriAsync() { + return new PagedFlux<>( + () -> getMultiplePagesFailureUriSinglePageAsync(), + nextLink -> getMultiplePagesFailureUriNextSinglePageAsync(nextLink)); + } + + /** + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesFailureUri() { + return new PagedIterable<>(getMultiplePagesFailureUriAsync()); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesFragmentNextLinkSinglePageAsync(String apiVersion, String tenant) { + return service.getMultiplePagesFragmentNextLink(this.client.getHost(), apiVersion, tenant).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getOdatanextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesFragmentNextLinkAsync(String apiVersion, String tenant) { + return new PagedFlux<>( + () -> getMultiplePagesFragmentNextLinkSinglePageAsync(apiVersion, tenant), + nextLink -> nextFragmentSinglePageAsync(apiVersion, tenant, nextLink)); + } + + /** + * @param apiVersion null + * @param tenant null + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesFragmentNextLink(String apiVersion, String tenant) { + return new PagedIterable<>(getMultiplePagesFragmentNextLinkAsync(apiVersion, tenant)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesFragmentWithGroupingNextLinkSinglePageAsync(String apiVersion, String tenant) { + return service.getMultiplePagesFragmentWithGroupingNextLink(this.client.getHost(), apiVersion, tenant).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getOdatanextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesFragmentWithGroupingNextLinkAsync(String apiVersion, String tenant) { + return new PagedFlux<>( + () -> getMultiplePagesFragmentWithGroupingNextLinkSinglePageAsync(apiVersion, tenant), + nextLink -> nextFragmentWithGroupingSinglePageAsync(apiVersion, tenant, nextLink)); + } + + /** + * @param apiVersion null + * @param tenant null + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesFragmentWithGroupingNextLink(String apiVersion, String tenant) { + return new PagedIterable<>(getMultiplePagesFragmentWithGroupingNextLinkAsync(apiVersion, tenant)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesLROSinglePageAsync(String clientRequestId, Integer maxresults, Integer timeout) { + return service.getMultiplePagesLRO(this.client.getHost(), clientRequestId, maxresults, timeout).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux getMultiplePagesLROAsync(String clientRequestId, Integer maxresults, Integer timeout) { + return new PagedFlux<>( + () -> getMultiplePagesLROSinglePageAsync(clientRequestId, maxresults, timeout), + nextLink -> getMultiplePagesLRONextSinglePageAsync(nextLink)); + } + + /** + * @param clientRequestId null + * @param maxresults null + * @param timeout null + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException 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.COLLECTION) + public PagedIterable getMultiplePagesLRO(String clientRequestId, Integer maxresults, Integer timeout) { + return new PagedIterable<>(getMultiplePagesLROAsync(clientRequestId, maxresults, timeout)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> nextFragmentSinglePageAsync(String apiVersion, String tenant, String nextLink) { + return service.nextFragment(this.client.getHost(), apiVersion, tenant, nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getOdatanextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> nextFragmentWithGroupingSinglePageAsync(String apiVersion, String tenant, String nextLink) { + return service.nextFragmentWithGrouping(this.client.getHost(), apiVersion, tenant, nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getOdatanextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSinglePagesNextSinglePageAsync(String nextLink) { + return service.getSinglePagesNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesNextSinglePageAsync(String nextLink) { + return service.getMultiplePagesNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getOdataMultiplePagesNextSinglePageAsync(String nextLink) { + return service.getOdataMultiplePagesNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getOdatanextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesWithOffsetNextSinglePageAsync(String nextLink) { + return service.getMultiplePagesWithOffsetNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesRetryFirstNextSinglePageAsync(String nextLink) { + return service.getMultiplePagesRetryFirstNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesRetrySecondNextSinglePageAsync(String nextLink) { + return service.getMultiplePagesRetrySecondNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSinglePagesFailureNextSinglePageAsync(String nextLink) { + return service.getSinglePagesFailureNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesFailureNextSinglePageAsync(String nextLink) { + return service.getMultiplePagesFailureNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesFailureUriNextSinglePageAsync(String nextLink) { + return service.getMultiplePagesFailureUriNext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } + + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMultiplePagesLRONextSinglePageAsync(String nextLink) { + return service.getMultiplePagesLRONext(nextLink).map(res -> new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValues(), + res.getValue().getNextLink(), + null)); + } +} diff --git a/tests/src/main/java/fixtures/paging/models/OdataProductResult.java b/tests/src/main/java/fixtures/paging/models/OdataProductResult.java new file mode 100644 index 0000000000..c463fe730b --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/OdataProductResult.java @@ -0,0 +1,63 @@ +package fixtures.paging.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * The OdataProductResult model. + */ +@Fluent +public final class OdataProductResult { + /* + * The values property. + */ + @JsonProperty(value = "values") + private List values; + + /* + * The odata.nextLink property. + */ + @JsonProperty(value = "odata.nextLink") + private String odatanextLink; + + /** + * Get the values property: The values property. + * + * @return the values value. + */ + public List getValues() { + return this.values; + } + + /** + * Set the values property: The values property. + * + * @param values the values value to set. + * @return the OdataProductResult object itself. + */ + public OdataProductResult setValues(List values) { + this.values = values; + return this; + } + + /** + * Get the odatanextLink property: The odata.nextLink property. + * + * @return the odatanextLink value. + */ + public String getOdatanextLink() { + return this.odatanextLink; + } + + /** + * Set the odatanextLink property: The odata.nextLink property. + * + * @param odatanextLink the odatanextLink value to set. + * @return the OdataProductResult object itself. + */ + public OdataProductResult setOdatanextLink(String odatanextLink) { + this.odatanextLink = odatanextLink; + return this; + } +} diff --git a/tests/src/main/java/fixtures/paging/models/OperationResult.java b/tests/src/main/java/fixtures/paging/models/OperationResult.java new file mode 100644 index 0000000000..3dc2a26bf8 --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/OperationResult.java @@ -0,0 +1,36 @@ +package fixtures.paging.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The OperationResult model. + */ +@Fluent +public final class OperationResult { + /* + * The status property. + */ + @JsonProperty(value = "status") + private OperationResultStatus status; + + /** + * Get the status property: The status property. + * + * @return the status value. + */ + public OperationResultStatus getStatus() { + return this.status; + } + + /** + * Set the status property: The status property. + * + * @param status the status value to set. + * @return the OperationResult object itself. + */ + public OperationResult setStatus(OperationResultStatus status) { + this.status = status; + return this; + } +} diff --git a/tests/src/main/java/fixtures/paging/models/OperationResultStatus.java b/tests/src/main/java/fixtures/paging/models/OperationResultStatus.java new file mode 100644 index 0000000000..c7fa7cd8cf --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/OperationResultStatus.java @@ -0,0 +1,83 @@ +package fixtures.paging.models; + +import com.azure.core.util.ExpandableStringEnum; +import com.fasterxml.jackson.annotation.JsonCreator; +import java.util.Collection; + +/** + * Defines values for OperationResultStatus. + */ +public final class OperationResultStatus extends ExpandableStringEnum { + /** + * Static value Succeeded for OperationResultStatus. + */ + public static final OperationResultStatus SUCCEEDED = fromString("Succeeded"); + + /** + * Static value Failed for OperationResultStatus. + */ + public static final OperationResultStatus FAILED = fromString("Failed"); + + /** + * Static value canceled for OperationResultStatus. + */ + public static final OperationResultStatus CANCELED = fromString("canceled"); + + /** + * Static value Accepted for OperationResultStatus. + */ + public static final OperationResultStatus ACCEPTED = fromString("Accepted"); + + /** + * Static value Creating for OperationResultStatus. + */ + public static final OperationResultStatus CREATING = fromString("Creating"); + + /** + * Static value Created for OperationResultStatus. + */ + public static final OperationResultStatus CREATED = fromString("Created"); + + /** + * Static value Updating for OperationResultStatus. + */ + public static final OperationResultStatus UPDATING = fromString("Updating"); + + /** + * Static value Updated for OperationResultStatus. + */ + public static final OperationResultStatus UPDATED = fromString("Updated"); + + /** + * Static value Deleting for OperationResultStatus. + */ + public static final OperationResultStatus DELETING = fromString("Deleting"); + + /** + * Static value Deleted for OperationResultStatus. + */ + public static final OperationResultStatus DELETED = fromString("Deleted"); + + /** + * Static value OK for OperationResultStatus. + */ + public static final OperationResultStatus OK = fromString("OK"); + + /** + * Creates or finds a OperationResultStatus from its string representation. + * + * @param name a name to look for. + * @return the corresponding OperationResultStatus. + */ + @JsonCreator + public static OperationResultStatus fromString(String name) { + return fromString(name, OperationResultStatus.class); + } + + /** + * @return known OperationResultStatus values. + */ + public static Collection values() { + return values(OperationResultStatus.class); + } +} diff --git a/tests/src/main/java/fixtures/paging/models/Product.java b/tests/src/main/java/fixtures/paging/models/Product.java new file mode 100644 index 0000000000..46b29359c7 --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/Product.java @@ -0,0 +1,36 @@ +package fixtures.paging.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The Product model. + */ +@Fluent +public final class Product { + /* + * The properties property. + */ + @JsonProperty(value = "properties") + private ProductProperties properties; + + /** + * Get the properties property: The properties property. + * + * @return the properties value. + */ + public ProductProperties getProperties() { + return this.properties; + } + + /** + * Set the properties property: The properties property. + * + * @param properties the properties value to set. + * @return the Product object itself. + */ + public Product setProperties(ProductProperties properties) { + this.properties = properties; + return this; + } +} diff --git a/tests/src/main/java/fixtures/paging/models/ProductProperties.java b/tests/src/main/java/fixtures/paging/models/ProductProperties.java new file mode 100644 index 0000000000..d5a87bf03b --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/ProductProperties.java @@ -0,0 +1,62 @@ +package fixtures.paging.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The ProductProperties model. + */ +@Fluent +public final class ProductProperties { + /* + * The id property. + */ + @JsonProperty(value = "id") + private Integer id; + + /* + * The name property. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Get the id property: The id property. + * + * @return the id value. + */ + public Integer getId() { + return this.id; + } + + /** + * Set the id property: The id property. + * + * @param id the id value to set. + * @return the ProductProperties object itself. + */ + public ProductProperties setId(Integer id) { + this.id = id; + return this; + } + + /** + * Get the name property: The name property. + * + * @return the name value. + */ + public String getName() { + return this.name; + } + + /** + * Set the name property: The name property. + * + * @param name the name value to set. + * @return the ProductProperties object itself. + */ + public ProductProperties setName(String name) { + this.name = name; + return this; + } +} diff --git a/tests/src/main/java/fixtures/paging/models/ProductResult.java b/tests/src/main/java/fixtures/paging/models/ProductResult.java new file mode 100644 index 0000000000..4e53839b35 --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/ProductResult.java @@ -0,0 +1,63 @@ +package fixtures.paging.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * The ProductResult model. + */ +@Fluent +public final class ProductResult { + /* + * The values property. + */ + @JsonProperty(value = "values") + private List values; + + /* + * The nextLink property. + */ + @JsonProperty(value = "nextLink") + private String nextLink; + + /** + * Get the values property: The values property. + * + * @return the values value. + */ + public List getValues() { + return this.values; + } + + /** + * Set the values property: The values property. + * + * @param values the values value to set. + * @return the ProductResult object itself. + */ + public ProductResult setValues(List values) { + this.values = values; + return this; + } + + /** + * Get the nextLink property: The nextLink property. + * + * @return the nextLink value. + */ + public String getNextLink() { + return this.nextLink; + } + + /** + * Set the nextLink property: The nextLink property. + * + * @param nextLink the nextLink value to set. + * @return the ProductResult object itself. + */ + public ProductResult setNextLink(String nextLink) { + this.nextLink = nextLink; + return this; + } +} diff --git a/tests/src/main/java/fixtures/paging/models/package-info.java b/tests/src/main/java/fixtures/paging/models/package-info.java new file mode 100644 index 0000000000..89ebaf4913 --- /dev/null +++ b/tests/src/main/java/fixtures/paging/models/package-info.java @@ -0,0 +1,5 @@ +/** + * Package containing the data models for AutoRestPagingTestService. + * Long-running Operation for AutoRest. + */ +package fixtures.paging.models; diff --git a/tests/src/main/java/fixtures/paging/package-info.java b/tests/src/main/java/fixtures/paging/package-info.java new file mode 100644 index 0000000000..39d18580ea --- /dev/null +++ b/tests/src/main/java/fixtures/paging/package-info.java @@ -0,0 +1,5 @@ +/** + * Package containing the classes for AutoRestPagingTestService. + * Long-running Operation for AutoRest. + */ +package fixtures.paging; diff --git a/tests/src/test/java/fixtures/bodystring/StringOperationsTests.java b/tests/src/test/java/fixtures/bodystring/StringOperationsTests.java index 34b1088158..6a082ca4a6 100644 --- a/tests/src/test/java/fixtures/bodystring/StringOperationsTests.java +++ b/tests/src/test/java/fixtures/bodystring/StringOperationsTests.java @@ -96,7 +96,7 @@ public void getBase64UrlEncoded() throws Exception { @Test public void getNullBase64UrlEncoded() throws Exception { byte[] result = client.strings().getNullBase64UrlEncoded(); - Assert.assertNull(result); + Assert.assertEquals(0, result.length); } @Test diff --git a/tests/src/test/java/fixtures/paging/PagingTests.java b/tests/src/test/java/fixtures/paging/PagingTests.java new file mode 100644 index 0000000000..fd30470855 --- /dev/null +++ b/tests/src/test/java/fixtures/paging/PagingTests.java @@ -0,0 +1,126 @@ +package fixtures.paging; + +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.PagedIterable; +import fixtures.paging.models.Product; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.net.MalformedURLException; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import static org.junit.Assert.fail; + +public class PagingTests { + private static AutoRestPagingTestService client; + + @BeforeClass + public static void setup() { + client = new AutoRestPagingTestServiceBuilder().build(); + } + + @Test + public void getSinglePages() throws Exception { + PagedIterable response = client.pagings().getSinglePages(); + Assert.assertEquals(1, response.stream().count()); + } + + @Test + public void getMultiplePages() throws Exception { + List response = client.pagings().getMultiplePages(null, null, null) + .stream().collect(Collectors.toList()); + Assert.assertEquals(10, response.size()); + } + + @Test + public void getOdataMultiplePages() throws Exception { + List response = client.pagings().getOdataMultiplePages(null, null, null) + .stream().collect(Collectors.toList()); + Assert.assertEquals(10, response.size()); + } + +// TODO: Parameter grouping +// @Test +// public void getMultiplePagesWithOffset() throws Exception { +// PagingsGetMultiplePagesWithOffsetOptions options = new PagingsGetMultiplePagesWithOffsetOptions(); +// options.withOffset(100); +// List response = client.pagings().getMultiplePagesWithOffset(options, "client-id"); +// Assert.assertEquals(10, response.size()); +// Assert.assertEquals(110, (int) response.get(response.size() - 1).properties().id()); +// } +// + @Test + public void getMultiplePagesAsync() throws Exception { + final CountDownLatch lock = new CountDownLatch(1); + client.pagings().getMultiplePagesAsync("client-id", null, null) + .doOnError(throwable -> fail(throwable.getMessage())) + .doOnComplete(lock::countDown) + .blockLast(); + + Assert.assertTrue(lock.await(10000, TimeUnit.MILLISECONDS)); + } + + @Test + public void getMultiplePagesRetryFirst() throws Exception { + List response = client.pagings().getMultiplePagesRetryFirst() + .stream().collect(Collectors.toList()); + Assert.assertEquals(10, response.size()); + } + + @Test + public void getMultiplePagesRetrySecond() throws Exception { + List response = client.pagings().getMultiplePagesRetrySecond() + .stream().collect(Collectors.toList()); + Assert.assertEquals(10, response.size()); + } + + @Test + public void getSinglePagesFailure() throws Exception { + try { + List response = client.pagings().getSinglePagesFailure() + .stream().collect(Collectors.toList()); + fail(); + } catch (HttpResponseException ex) { + Assert.assertNotNull(ex.getResponse()); + } + } + + @Test + public void getMultiplePagesFailure() throws Exception { + try { + List response = client.pagings().getMultiplePagesFailure() + .stream().collect(Collectors.toList()); + response.size(); + fail(); + } catch (HttpResponseException ex) { + Assert.assertNotNull(ex.getResponse()); + } + } + + @Test + public void getMultiplePagesFailureUri() { + try { + client.pagings().getMultiplePagesFailureUri().stream().collect(Collectors.toList()); + fail(); + } catch (Exception e) { + Assert.assertTrue(e.getCause() instanceof MalformedURLException); + } + } + + @Test + public void getMultiplePagesFragmentNextLink() throws Exception { + PagedIterable response = client.pagings().getMultiplePagesFragmentNextLink("1.6", "test_user"); + Assert.assertEquals(10, response.stream().count()); + } +// +// TODO: Parameter grouping +// @Test +// public void getMultiplePagesFragmentWithGroupingNextLink() throws Exception { +// List response = client.pagings().getMultiplePagesFragmentWithGroupingNextLink(new CustomParameterGroup().withTenant("test_user").withApiVersion("1.6")); +// Assert.assertEquals(10, response.size()); +// } +}