Skip to content

Commit 7001fa3

Browse files
Merge branch 'main' into docs/library-docs-rest
2 parents c1ecc9d + b2fe512 commit 7001fa3

24 files changed

Lines changed: 737 additions & 30 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-java"
5+
---
6+
7+
Add reference documentation for Java emitter diagnostics.

‎.github/workflows/copilot-setup-steps.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ jobs:
2121
- name: Checkout repository
2222
uses: actions/checkout@v7
2323
- name: Install gh-aw extension
24-
uses: github/gh-aw/actions/setup-cli@v0.82.14
24+
uses: github/gh-aw/actions/setup-cli@v0.83.4
2525
with:
2626
version: v0.50.1
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
This diagnostic is issued when an authentication scheme cannot be represented by the selected Java client flavor.
2+
3+
## Impact
4+
5+
The generated client may omit the scheme or fall back to a less specific credential type.
6+
7+
## ❌ Incorrect Usage
8+
9+
### API key outside a header
10+
11+
```typespec
12+
@service
13+
@useAuth(ApiKeyAuth<ApiKeyLocation.query, "api-key">)
14+
namespace Contoso;
15+
```
16+
17+
### Basic authentication for an Azure client
18+
19+
```typespec
20+
@service
21+
@useAuth(BasicAuth)
22+
namespace Contoso;
23+
```
24+
25+
```yaml
26+
options:
27+
"@typespec/http-client-java":
28+
flavor: azure
29+
```
30+
31+
## Diagnostic Message
32+
33+
The message identifies the unsupported scheme, location, or flavor. For example:
34+
35+
```text
36+
ApiKey auth is currently only supported for ApiKeyLocation.header.
37+
```
38+
39+
## ✅ How to Fix
40+
41+
Use OAuth2 authentication.
42+
43+
```typespec
44+
@service
45+
@useAuth(OAuth2Auth<[OAuthFlow]>)
46+
namespace Contoso;
47+
48+
model OAuthFlow {
49+
type: OAuth2FlowType.clientCredentials;
50+
tokenUrl: "https://login.microsoftonline.com/common/oauth2/v2.0/token";
51+
scopes: ["https://contoso.com/.default"];
52+
}
53+
```
54+
55+
## Suppression
56+
57+
Do not suppress this warning unless custom code will provide the intended authentication behavior.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
This diagnostic is issued when the Java `clientRequired` client option is explicitly set to `false`.
2+
3+
## Impact
4+
5+
Java client generation fails because the option only supports promoting a parameter to required; it cannot make a required parameter optional.
6+
7+
## ❌ Incorrect Usage
8+
9+
```typespec
10+
model ReadOptions {
11+
@query filter: string;
12+
}
13+
14+
op read(...ReadOptions): void;
15+
16+
@@clientOption(ReadOptions.filter, "clientRequired", false, "java");
17+
```
18+
19+
## Diagnostic Message
20+
21+
```text
22+
Client option 'clientRequired' can only be set to 'true'.
23+
```
24+
25+
## ✅ How to Fix
26+
27+
Remove the client option, or set it to `true` for an optional TypeSpec parameter that must be required in the Java client.
28+
29+
```typespec
30+
model ReadOptions {
31+
@query filter?: string;
32+
}
33+
34+
op read(...ReadOptions): void;
35+
36+
@@clientOption(ReadOptions.filter, "clientRequired", true, "java");
37+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This diagnostic is issued when a response content-type header has a constant value and the Java emitter removes it from the generated response-header model.
2+
3+
## Impact
4+
5+
The constant header is not generated as a property in the response-header model because its value cannot vary.
6+
7+
## Example Usage
8+
9+
```typespec
10+
op read(): {
11+
@statusCode statusCode: 200;
12+
@header contentType: "application/json";
13+
@body body: Widget;
14+
};
15+
```
16+
17+
## Diagnostic Message
18+
19+
```text
20+
Constant header 'content-type' is removed from response headers.
21+
```
22+
23+
## How to Address
24+
25+
No change is required. The TypeSpec definition is valid, and the warning only explains why the generated response-header model does not contain a property for this header.
26+
27+
## Suppression
28+
29+
It is safe to ignore or suppress this warning when the constant header does not need to be exposed as a property.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
This diagnostic is issued when the Java emitter cannot form a safe convenience-method signature.
2+
3+
## Impact
4+
5+
The protocol API remains available, but the convenience API is omitted for the operation.
6+
7+
## Multiple Content Types
8+
9+
```typespec
10+
@post
11+
op upload(@body data: bytes, @header contentType: "application/octet-stream" | "image/png"): void;
12+
```
13+
14+
```yaml
15+
options:
16+
"@typespec/http-client-java":
17+
flavor: azure
18+
```
19+
20+
This TypeSpec definition is valid. Customize the generated Java library to add a convenience API with the appropriate method signature and behavior for the operation. The generated protocol API can be used as the underlying implementation.
21+
22+
## JSON Merge Patch Without Stream-Style Serialization
23+
24+
```typespec
25+
@patch
26+
op update(@header contentType: "application/merge-patch+json", @body body: WidgetPatch): void;
27+
```
28+
29+
```yaml
30+
options:
31+
"@typespec/http-client-java":
32+
flavor: azure
33+
stream-style-serialization: false
34+
```
35+
36+
Enable stream-style serialization:
37+
38+
```yaml
39+
options:
40+
"@typespec/http-client-java":
41+
flavor: azure
42+
stream-style-serialization: true
43+
```
44+
45+
## Diagnostic Message
46+
47+
The message identifies either multiple content types or JSON merge patch as the reason the convenience API was not generated.
48+
49+
## Suppression
50+
51+
For multiple content types, suppress the warning after adding the required convenience API customization, or when a protocol-only API surface is intentional. Do not suppress the JSON merge patch warning; enable stream-style serialization instead.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This diagnostic is issued when TCGC supplies a model without a usable generated name.
2+
3+
## Impact
4+
5+
Java client generation stops because every emitted Java model requires a class name.
6+
7+
## ❌ Incorrect Usage
8+
9+
The diagnostic is generally caused by an anonymous or synthesized model shape for which the SDK model did not produce a name. There is no single TypeSpec construct that always triggers it.
10+
11+
## Diagnostic Message
12+
13+
```text
14+
Name from TCGC is empty.
15+
```
16+
17+
## ✅ How to Fix
18+
19+
Give anonymous request or response shapes an explicit model name and reference that model from the operation.
20+
21+
```typespec
22+
model WidgetResponse {
23+
value: string;
24+
}
25+
26+
op getWidget(): WidgetResponse;
27+
```
28+
29+
If all involved models are already named, update the emitter dependencies and report a minimal reproduction.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
This diagnostic is issued when an array-valued header uses any collection format other than CSV. The Java emitter supports only comma-delimited arrays for header parameters.
2+
3+
## Impact
4+
5+
The requested header serialization format is ignored, which can produce a request that does not match the service contract.
6+
7+
## ❌ Incorrect Usage
8+
9+
```typespec
10+
op read(
11+
@header
12+
@encode(ArrayEncoding.pipeDelimited)
13+
values: string[],
14+
): void;
15+
```
16+
17+
## Diagnostic Message
18+
19+
```text
20+
Header parameter format '<format>' is not supported.
21+
```
22+
23+
## ✅ How to Fix
24+
25+
Use the default comma-delimited header representation.
26+
27+
```typespec
28+
op read(@header values: string[]): void;
29+
```
30+
31+
## Suppression
32+
33+
This warning should not be suppressed. Change the service contract or header encoding to CSV.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
This diagnostic is issued when the `api-version` emitter option is neither a declared service version nor `latest` or `all`.
2+
3+
## Impact
4+
5+
The requested API-version projection cannot be selected, so Java client generation fails.
6+
7+
## ❌ Incorrect Usage
8+
9+
```typespec
10+
@service
11+
@versioned(Versions)
12+
namespace Contoso;
13+
14+
enum Versions {
15+
v1,
16+
v2,
17+
}
18+
```
19+
20+
```yaml
21+
options:
22+
"@typespec/http-client-java":
23+
api-version: v3
24+
```
25+
26+
## Diagnostic Message
27+
28+
```text
29+
Invalid api-version option: 'v3'. The value should be an api-version, 'latest', or 'all'.
30+
```
31+
32+
## ✅ How to Fix
33+
34+
Use a version declared by the service, or use `latest` or `all`.
35+
36+
```yaml
37+
options:
38+
"@typespec/http-client-java":
39+
api-version: v2
40+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
This diagnostic is issued when a generated Java package segment is a reserved Java keyword.
2+
3+
## Impact
4+
5+
The emitter appends `namespace` to the reserved package segment, so the generated package differs from the requested namespace.
6+
7+
## ❌ Incorrect Usage
8+
9+
```typespec
10+
@service
11+
namespace Contoso.Public;
12+
```
13+
14+
The derived Java namespace contains the reserved keyword `public`.
15+
16+
## Diagnostic Message
17+
18+
```text
19+
Namespace 'contoso.public' contains reserved Java keywords, replaced it with 'contoso.publicnamespace'.
20+
```
21+
22+
## ✅ How to Fix
23+
24+
Rename the TypeSpec namespace or configure a Java namespace that does not contain Java keywords.
25+
26+
```typespec
27+
@service
28+
namespace Contoso.PublicApi;
29+
```
30+
31+
## Suppression
32+
33+
Suppress the warning only when the adjusted package name is intentionally accepted.

0 commit comments

Comments
 (0)