Skip to content

Commit

Permalink
http-client-java, migrate to http-specs (#5215)
Browse files Browse the repository at this point in the history
as before, currently code is actually generated in azure mode (still
waiting for the release of Java clientcore for unbranded)

report upload is temporarily disabled `EnableCadlRanchReport: false`
will re-enable after Azure/autorest.java#2986

test release (on test branch) is good
  • Loading branch information
weidongxu-microsoft authored Dec 13, 2024
1 parent cc6f41a commit b1476de
Show file tree
Hide file tree
Showing 67 changed files with 4,713 additions and 3,314 deletions.
1 change: 1 addition & 0 deletions packages/http-client-java/eng/pipeline/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ extends:
LanguageShortName: "java"
HasNugetPackages: false
CadlRanchName: "@typespec/http-client-java"
EnableCadlRanchReport: false
17 changes: 9 additions & 8 deletions packages/http-client-java/eng/scripts/Test-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ try {

Write-Host "Updated PATH: $env:PATH"

# cadl-ranch tests (unit tests included in java/typescript package build)
# Run Spector tests (unit tests included in java/typescript package build)
try {
$generatorTestDir = Join-Path $packageRoot 'generator/http-client-generator-test'
Push-Location $generatorTestDir
try {
& ./Setup.ps1
& ./CadlRanch-Tests.ps1
& ./Spector-Tests.ps1
Set-Location $packageRoot
Write-Host 'Cadl ranch tests passed'
Write-Host "Spector tests passed"
}
finally {
Pop-Location
}
}
catch {
Write-Error "Cadl ranch tests failed: $_"
Write-Error "Spector tests failed: $_"
}
# copy coverage report to artifacts dir
# Copy coverage report to artifacts directory
try {
$coverageReportDir = Join-Path $packageRoot 'generator/artifacts/coverage'
if (!(Test-Path $coverageReportDir)) {
New-Item -ItemType Directory -Path $coverageReportDir

$sourceFile = Join-Path $packageRoot 'generator/http-client-generator-test/cadl-ranch-coverage-java-standard.json'
$targetFile = Join-Path $coverageReportDir 'cadl-ranch-coverage-java-standard.json'
$sourceFile = Join-Path $packageRoot 'generator/http-client-generator-test/tsp-spector-coverage-java-standard.json'
$targetFile = Join-Path $coverageReportDir 'tsp-spector-coverage-java-standard.json'
Copy-Item $sourceFile -Destination $targetFile
}
} catch {
Expand All @@ -62,11 +62,12 @@ try {
}
if ($GenerationChecks) {
Set-StrictMode -Version 1
# run E2E Test for TypeSpec emitter
# Generate code for Spector tests
Write-Host "Generating test projects ..."
& "$packageRoot/eng/scripts/Generate.ps1"
Write-Host 'Code generation is completed.'

# Check difference between code in branch, and code just generated
try {
Write-Host 'Checking for differences in generated code...'
& "$packageRoot/eng/scripts/Check-GitChanges.ps1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $generateScript = {
}

$tspTrace = "--trace import-resolution --trace projection --trace http-client-java"
$tspCommand = "npx tsp compile $tspFile $tspOptions $tspTrace"
$tspCommand = "npx --no-install tsp compile $tspFile $tspOptions $tspTrace"

$timer = [Diagnostics.Stopwatch]::StartNew()
$generateOutput = Invoke-Expression $tspCommand
Expand Down Expand Up @@ -137,28 +137,29 @@ if (Test-Path ./tsp-output) {
Remove-Item ./tsp-output -Recurse -Force
}

# run other local tests except partial update
# generate for other local test sources except partial update
$job = Get-Item ./tsp/* -Filter "*.tsp" -Exclude "*partialupdate*" | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob

$job | Wait-Job -Timeout 600
$job | Receive-Job

# partial update test
npx tsp compile ./tsp/partialupdate.tsp --option="@typespec/http-client-java.emitter-output-dir={project-root}/existingcode"
npx --no-install tsp compile ./tsp/partialupdate.tsp --option="@typespec/http-client-java.emitter-output-dir={project-root}/existingcode"
Copy-Item -Path ./existingcode/src/main/java/tsptest/partialupdate -Destination ./src/main/java/tsptest/partialupdate -Recurse -Force
Remove-Item ./existingcode -Recurse -Force

# run cadl ranch tests sources
Copy-Item -Path node_modules/@azure-tools/cadl-ranch-specs/http -Destination ./ -Recurse -Force
# generate for http-specs/azure-http-specs test sources
Copy-Item -Path node_modules/@typespec/http-specs/specs -Destination ./ -Recurse -Force
Copy-Item -Path node_modules/@azure-tools/azure-http-specs/specs -Destination ./ -Recurse -Force
# remove xml tests, emitter has not supported xml model
Remove-Item ./http/payload/xml -Recurse -Force
Remove-Item ./specs/payload/xml -Recurse -Force

$job = (Get-ChildItem ./http -Include "main.tsp","old.tsp" -File -Recurse) | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob
$job = (Get-ChildItem ./specs -Include "main.tsp","old.tsp" -File -Recurse) | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob

$job | Wait-Job -Timeout 1200
$job | Receive-Job

Remove-Item ./http -Recurse -Force
Remove-Item ./specs -Recurse -Force

Copy-Item -Path ./tsp-output/*/src -Destination ./ -Recurse -Force -Exclude @("ReadmeSamples.java", "module-info.java")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3.0

Write-Host "Running cadl ranch tests"
Write-Host "Running Spector tests"

Write-Host "Starting the test server"
npm run testserver-start
Write-Host "Starting the Spector server"
npm run spector-start
Write-Host "Compile and run the tests"
mvn clean test --no-transfer-progress -T 1C
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Write-Host "Stopping the test server"
npm run testserver-stop
Write-Host "Stopping the Spector server"
npm run spector-stop

Write-Host "Finished running the cadl ranch tests"
Write-Host "Finished running the Spector tests"
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"format": "npm run -s prettier -- --write",
"check-format": "npm run prettier -- --check",
"prettier": "prettier --config ./.prettierrc.yaml **/*.tsp",
"testserver-run": "cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./cadl-ranch-coverage-java-standard.json",
"testserver-start": "cadl-ranch server start ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./cadl-ranch-coverage-java-standard.json",
"testserver-stop": "cadl-ranch server stop"
"spector-serve": "tsp-spector serve ./node_modules/@typespec/http-specs/specs ./node_modules/@azure-tools/azure-http-specs/specs --coverageFile ./tsp-spector-coverage-java-standard.json",
"spector-start": "tsp-spector server start ./node_modules/@typespec/http-specs/specs ./node_modules/@azure-tools/azure-http-specs/specs --coverageFile ./tsp-spector-coverage-java-standard.json",
"spector-stop": "tsp-spector server stop"
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.39.5",
"@typespec/http-specs": "0.1.0-alpha.5",
"@azure-tools/azure-http-specs": "0.1.0-alpha.4",
"@typespec/http-client-java": "file:/../../typespec-http-client-java-0.1.4.tgz",
"@typespec/http-client-java-tests": "file:"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Mono<Response<BinaryData>> operationWithResponse(String name, RequestOptions req
}

/**
* Expected query parameter: kind= "real"
* Expected query parameter: kind="real"
* Expected response body:
* ```json
* {
Expand Down Expand Up @@ -147,7 +147,7 @@ Mono<OuterModel> operation(String name) {
}

/**
* Expected query parameter: kind= "real"
* Expected query parameter: kind="real"
* Expected response body:
* ```json
* {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Response<BinaryData> operationWithResponse(String name, RequestOptions requestOp
}

/**
* Expected query parameter: kind= "real"
* Expected query parameter: kind="real"
* Expected response body:
* ```json
* {
Expand Down Expand Up @@ -141,7 +141,7 @@ OuterModel operation(String name) {
}

/**
* Expected query parameter: kind= "real"
* Expected query parameter: kind="real"
* Expected response body:
* ```json
* {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public Response<BinaryData> operationWithResponse(String name, RequestOptions re
}

/**
* Expected query parameter: kind= "real"
* Expected query parameter: kind="real"
* Expected response body:
* ```json
* {
Expand Down Expand Up @@ -213,7 +213,7 @@ public Mono<Response<BinaryData>> discriminatorWithResponseAsync(String kind, Re
}

/**
* Expected query parameter: kind= "real"
* Expected query parameter: kind="real"
* Expected response body:
* ```json
* {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package azure.payload.pageable;

import azure.payload.pageable.implementation.PageableClientImpl;
import azure.payload.pageable.models.User;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.util.BinaryData;
import java.util.stream.Collectors;
import reactor.core.publisher.Flux;

/**
* Initializes a new instance of the asynchronous PageableClient type.
*/
@ServiceClient(builder = PageableClientBuilder.class, isAsync = true)
public final class PageableAsyncClient {
@Generated
private final PageableClientImpl serviceClient;

/**
* Initializes an instance of PageableAsyncClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
PageableAsyncClient(PageableClientImpl serviceClient) {
this.serviceClient = serviceClient;
}

/**
* List users.
* <p><strong>Query Parameters</strong></p>
* <table border="1">
* <caption>Query Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>maxpagesize</td><td>Integer</td><td>No</td><td>The maximum number of result items per page.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addQueryParam}
* <p><strong>Response Body Schema</strong></p>
*
* <pre>
* {@code
* {
* name: String (Required)
* }
* }
* </pre>
*
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return paged collection of User items as paginated response with {@link PagedFlux}.
*/
@Generated
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<BinaryData> list(RequestOptions requestOptions) {
return this.serviceClient.listAsync(requestOptions);
}

/**
* List users.
*
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return paged collection of User items as paginated response with {@link PagedFlux}.
*/
@Generated
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<User> list() {
// Generated convenience method for list
RequestOptions requestOptions = new RequestOptions();
PagedFlux<BinaryData> pagedFluxResponse = list(requestOptions);
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
? pagedFluxResponse.byPage().take(1)
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
return flux.map(pagedResponse -> new PagedResponseBase<Void, User>(pagedResponse.getRequest(),
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
pagedResponse.getValue()
.stream()
.map(protocolMethodData -> protocolMethodData.toObject(User.class))
.collect(Collectors.toList()),
pagedResponse.getContinuationToken(), null));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package azure.payload.pageable;

import azure.payload.pageable.implementation.PageableClientImpl;
import azure.payload.pageable.models.User;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.util.BinaryData;

/**
* Initializes a new instance of the synchronous PageableClient type.
*/
@ServiceClient(builder = PageableClientBuilder.class)
public final class PageableClient {
@Generated
private final PageableClientImpl serviceClient;

/**
* Initializes an instance of PageableClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
PageableClient(PageableClientImpl serviceClient) {
this.serviceClient = serviceClient;
}

/**
* List users.
* <p><strong>Query Parameters</strong></p>
* <table border="1">
* <caption>Query Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>maxpagesize</td><td>Integer</td><td>No</td><td>The maximum number of result items per page.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addQueryParam}
* <p><strong>Response Body Schema</strong></p>
*
* <pre>
* {@code
* {
* name: String (Required)
* }
* }
* </pre>
*
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return paged collection of User items as paginated response with {@link PagedIterable}.
*/
@Generated
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<BinaryData> list(RequestOptions requestOptions) {
return this.serviceClient.list(requestOptions);
}

/**
* List users.
*
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return paged collection of User items as paginated response with {@link PagedIterable}.
*/
@Generated
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<User> list() {
// Generated convenience method for list
RequestOptions requestOptions = new RequestOptions();
return serviceClient.list(requestOptions).mapPage(bodyItemValue -> bodyItemValue.toObject(User.class));
}
}
Loading

0 comments on commit b1476de

Please sign in to comment.