Skip to content

Commit 90d9987

Browse files
eng, update core, default flavor should be azure now (#2999)
1 parent 8b1147b commit 90d9987

File tree

13 files changed

+291
-17
lines changed

13 files changed

+291
-17
lines changed

Generate.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ $job = @(
146146
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/client-default-value.json --namespace=fixtures.annotatedgettersandsetters --annotate-getters-and-setters-for-serialization=true --stream-style-serialization=false",
147147
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/xml-tag-with-attribute-and-value.json --namespace=fixtures.complexxmltag --stream-style-serialization=false",
148148
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/xml-tag-with-attribute-and-value.json --namespace=fixtures.complexstreamstylexmlserialization",
149+
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/xml-constant.json --namespace=fixtures.xmlconstant",
149150
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/security-info.json --namespace=fixtures.securityinfo --use-key-credential",
150151
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/special-header.json --namespace=fixtures.specialheader",
151152
"$VANILLA_ARGUMENTS --input-file=vanilla-tests/swagger/required-fields-as-ctor-args-transformation.json --namespace=fixtures.requiredfieldsascotrargstransformation --required-fields-as-ctor-args=true --output-model-immutable --null-byte-array-maps-to-empty-array",

core

Submodule core updated 79 files

core.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts
2-
index 5375778e0..917a4a957 100644
2+
index 691af914b..436ae3c8c 100644
33
--- a/packages/http-client-java/emitter/src/code-model-builder.ts
44
+++ b/packages/http-client-java/emitter/src/code-model-builder.ts
5-
@@ -241,7 +241,7 @@ export class CodeModelBuilder {
6-
}
5+
@@ -242,7 +242,7 @@ export class CodeModelBuilder {
6+
return this.codeModel;
7+
}
78

8-
public async build(): Promise<CodeModel> {
99
- this.sdkContext = await createSdkContext(this.emitterContext, "@typespec/http-client-java", {
1010
+ this.sdkContext = await createSdkContext(this.emitterContext, "@azure-tools/typespec-java", {
1111
versioning: { previewStringRegex: /$/ },
1212
}); // include all versions and do the filter by ourselves
1313

1414
diff --git a/packages/http-client-java/emitter/src/emitter.ts b/packages/http-client-java/emitter/src/emitter.ts
15-
index 317e746d2..848b46275 100644
15+
index ca4246c47..e4ec721eb 100644
1616
--- a/packages/http-client-java/emitter/src/emitter.ts
1717
+++ b/packages/http-client-java/emitter/src/emitter.ts
18-
@@ -98,7 +98,7 @@ const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
18+
@@ -107,7 +107,7 @@ const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
1919
};
2020

2121
export const $lib = createTypeSpecLibrary({
@@ -25,7 +25,7 @@ index 317e746d2..848b46275 100644
2525
emitter: {
2626
options: EmitterOptionsSchema,
2727
diff --git a/packages/http-client-java/generator/http-client-generator-core/pom.xml b/packages/http-client-java/generator/http-client-generator-core/pom.xml
28-
index afa83e5c4..db70c748e 100644
28+
index b65210b56..cd015f70f 100644
2929
--- a/packages/http-client-java/generator/http-client-generator-core/pom.xml
3030
+++ b/packages/http-client-java/generator/http-client-generator-core/pom.xml
3131
@@ -21,6 +21,11 @@
@@ -57,7 +57,7 @@ index d44ce8ec4..7953870bc 100644
5757
import com.microsoft.typespec.http.client.generator.core.extension.plugin.JavaSettings;
5858
import com.microsoft.typespec.http.client.generator.core.extension.plugin.NewPlugin;
5959
diff --git a/packages/http-client-java/generator/http-client-generator/src/main/resources/readme/pom.xml b/packages/http-client-java/generator/http-client-generator/src/main/resources/readme/pom.xml
60-
index c99896650..358938595 100644
60+
index c99896650..fef2a4caf 100644
6161
--- a/packages/http-client-java/generator/http-client-generator/src/main/resources/readme/pom.xml
6262
+++ b/packages/http-client-java/generator/http-client-generator/src/main/resources/readme/pom.xml
6363
@@ -16,9 +16,9 @@

typespec-extension/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 0.27.1 (2024-12-17)
4+
5+
Compatible with compiler 0.63.
6+
7+
- Default value for emitter option `flavor` is always `azure`.
8+
39
## 0.27.0 (2024-12-11)
410

511
Compatible with compiler 0.63.

typespec-extension/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typespec-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure-tools/typespec-java",
3-
"version": "0.27.0",
3+
"version": "0.27.1",
44
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
55
"keywords": [
66
"TypeSpec"

typespec-extension/readme.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Install [Node.js](https://nodejs.org/en/download/) 20 or above. (Verify by runni
44

55
Install [Java](https://docs.microsoft.com/java/openjdk/download) 11 or above. (Verify by running `java --version`)
66

7-
Install [Maven](https://maven.apache.org/install.html). (Verify by running `mvn --version`)
7+
Install [Maven](https://maven.apache.org/download.cgi). (Verify by running `mvn --version`)
88

99
Install [TypeSpec](https://typespec.io/) 0.63.
1010

@@ -36,23 +36,87 @@ emit:
3636
options:
3737
"@azure-tools/typespec-java":
3838
emitter-output-dir: "{project-root}/azure-ai-language-authoring"
39-
namespace: "com.azure.ai.language.authoring"
4039
service-name: "Authoring"
4140
generate-samples: true
4241
generate-tests: true
4342
partial-update: false
4443
api-version: "2023-11-01"
4544
```
4645
46+
### SDK Related Configuration in Emitter options `tspconfig.yaml`
47+
48+
#### `api-version`
49+
50+
By default, the emitter generates code from the latest api-version in TypeSpec.
51+
52+
In cases where a service needs to generate code from a previous api-version, set the value to that specific api-version.
53+
54+
#### `service-name`
55+
56+
This emitter option is for management-plane SDK.
57+
58+
It is advised for the service to set an appropriate service name. E.g. `service-name: Standby Pool`.
59+
60+
The name will appear in documentation (e.g. "README.md") that describes the service and the SDK. It would also affect the name of the entry class of the SDK.
61+
62+
#### `partial-update`
63+
64+
Default value is `false`.
65+
66+
This emitter option is for data-plane SDK.
67+
68+
In the case that the generated code is not good enough for the SDK, the developer can choose to customize the generated SDK via [Partial Update](https://github.com/Azure/azure-sdk-for-java/wiki/TypeSpec-Java-QuickStart#partial-update). Set the value to `true` to enable this feature.
69+
70+
#### `generate-samples`
71+
72+
Default value is `true`. The emitter generates code samples under the `generated` package.
73+
74+
For data-plane SDK, the generated samples are for reference. The motivation is to show how samples can be written. It is expected that developers write correct and concise samples outside of the `generated` package.
75+
76+
If there is customization of the generated SDK, the generated samples may not compile after customization. One can delete the `generated` package, and set the value to `false` to disable the generated samples.
77+
78+
#### `generate-tests`
79+
80+
Default value is `true`. The emitter generates tests under the `generated` package.
81+
82+
For data-plane SDK, the generated tests are (disabled) live tests. The motivation is to show how test cases can be written in Java with JUnit. It is expected that developers write runnable tests outside of the `generated` package.
83+
84+
For management-plane SDK, the generated tests are mock tests, for JSON serialization and API requests.
85+
86+
If there is customization of the generated SDK, the generated tests may not compile after customization. One can delete the `generated` package, and set the value to `false` to disable the generated tests.
87+
88+
### SDK Related Configuration in Client Customization `client.tsp`
89+
90+
For Java SDK, it is required to provide a Java package name via `@clientNamespace`.
91+
92+
Here is an example:
93+
94+
```ts
95+
@@clientNamespace(Client, "com.azure.ai.openai", "java");
96+
@@clientNamespace(Azure.OpenAI, "com.azure.ai.openai", "java");
97+
```
98+
99+
For management-plane SDK, one can provide a client name via `@clientName`.
100+
101+
Here is an example:
102+
103+
```ts
104+
@@clientNamespace(Microsoft.StandbyPool,
105+
"com.azure.resourcemanager.standbypool",
106+
"java"
107+
);
108+
@@clientName(Microsoft.StandbyPool, "StandbyPoolManagementClient", "java");
109+
```
110+
47111
## Convenience API
48112

49113
By default, TypeSpec-Java generates all protocol APIs and convenience APIs.
50114
A few exceptions are API of JSON Merge Patch, and API of long-running operation with ambiguous response type.
51115

52116
See "convenientAPI" decorator from [typespec-client-generator-core](https://github.com/Azure/typespec-azure/tree/main/packages/typespec-client-generator-core).
53117

54-
55118
# Customization
119+
56120
All post-code customizations listed in this [documentation](https://github.com/Azure/autorest.java/tree/main/customization-base/README.md) are supported for code generated from TypeSpec.
57121

58122
To configure customization with TypeSpec, Java's emitter options should include a `customization-class`. The `customization-class` option should specify the path to the file containing the customization code relative to `emitter-output-dir`. Note that the path should end with `src/main/java/<YourCustomizationClassName>.java`. The recommended practice is to place the customization class in `<output-dir>/customization/src/main/java/<YourCustomizationClassName>.java` and the `customization-class` option will have the value of `customization-class: customization/src/main/java/<YourCustomizationClassName>.java`. See example `tspconfig.yaml` below:

typespec-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@typespec/http-specs": "0.1.0-alpha.5",
1313
"@azure-tools/azure-http-specs": "0.1.0-alpha.4",
14-
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.27.0.tgz"
14+
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.27.1.tgz"
1515
},
1616
"devDependencies": {
1717
"@typespec/prettier-plugin-typespec": "~0.63.0",

typespec-tests/tspconfig.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ options:
77
generate-samples: true
88
generate-tests: true
99
examples-dir: "{project-root}/tsp/examples"
10-
flavor: "Azure"
1110
dev-options:
1211
generate-code-model: true
1312
loglevel: info
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
5+
package fixtures.xmlconstant.models;
6+
7+
import com.azure.core.annotation.Fluent;
8+
import com.azure.core.util.CoreUtils;
9+
import com.azure.xml.XmlReader;
10+
import com.azure.xml.XmlSerializable;
11+
import com.azure.xml.XmlToken;
12+
import com.azure.xml.XmlWriter;
13+
import javax.xml.namespace.QName;
14+
import javax.xml.stream.XMLStreamException;
15+
16+
/**
17+
* Groups the set of query request settings.
18+
*/
19+
@Fluent
20+
public final class QueryRequest implements XmlSerializable<QueryRequest> {
21+
/*
22+
* Required. The type of the provided query expression.
23+
*/
24+
private final String queryType = "SQL";
25+
26+
/*
27+
* The query expression in SQL. The maximum size of the query expression is 256KiB.
28+
*/
29+
private String expression;
30+
31+
/**
32+
* Creates an instance of QueryRequest class.
33+
*/
34+
public QueryRequest() {
35+
}
36+
37+
/**
38+
* Get the queryType property: Required. The type of the provided query expression.
39+
*
40+
* @return the queryType value.
41+
*/
42+
public String getQueryType() {
43+
return this.queryType;
44+
}
45+
46+
/**
47+
* Get the expression property: The query expression in SQL. The maximum size of the query expression is 256KiB.
48+
*
49+
* @return the expression value.
50+
*/
51+
public String getExpression() {
52+
return this.expression;
53+
}
54+
55+
/**
56+
* Set the expression property: The query expression in SQL. The maximum size of the query expression is 256KiB.
57+
*
58+
* @param expression the expression value to set.
59+
* @return the QueryRequest object itself.
60+
*/
61+
public QueryRequest setExpression(String expression) {
62+
this.expression = expression;
63+
return this;
64+
}
65+
66+
/**
67+
* Validates the instance.
68+
*
69+
* @throws IllegalArgumentException thrown if the instance is not valid.
70+
*/
71+
public void validate() {
72+
if (getExpression() == null) {
73+
throw new IllegalArgumentException("Missing required property expression in model QueryRequest");
74+
}
75+
}
76+
77+
@Override
78+
public XmlWriter toXml(XmlWriter xmlWriter) throws XMLStreamException {
79+
return toXml(xmlWriter, null);
80+
}
81+
82+
@Override
83+
public XmlWriter toXml(XmlWriter xmlWriter, String rootElementName) throws XMLStreamException {
84+
rootElementName = CoreUtils.isNullOrEmpty(rootElementName) ? "QueryRequest" : rootElementName;
85+
xmlWriter.writeStartElement(rootElementName);
86+
xmlWriter.writeStringElement("QueryType", this.queryType);
87+
xmlWriter.writeStringElement("Expression", this.expression);
88+
return xmlWriter.writeEndElement();
89+
}
90+
91+
/**
92+
* Reads an instance of QueryRequest from the XmlReader.
93+
*
94+
* @param xmlReader The XmlReader being read.
95+
* @return An instance of QueryRequest if the XmlReader was pointing to an instance of it, or null if it was
96+
* pointing to XML null.
97+
* @throws XMLStreamException If an error occurs while reading the QueryRequest.
98+
*/
99+
public static QueryRequest fromXml(XmlReader xmlReader) throws XMLStreamException {
100+
return fromXml(xmlReader, null);
101+
}
102+
103+
/**
104+
* Reads an instance of QueryRequest from the XmlReader.
105+
*
106+
* @param xmlReader The XmlReader being read.
107+
* @param rootElementName Optional root element name to override the default defined by the model. Used to support
108+
* cases where the model can deserialize from different root element names.
109+
* @return An instance of QueryRequest if the XmlReader was pointing to an instance of it, or null if it was
110+
* pointing to XML null.
111+
* @throws XMLStreamException If an error occurs while reading the QueryRequest.
112+
*/
113+
public static QueryRequest fromXml(XmlReader xmlReader, String rootElementName) throws XMLStreamException {
114+
String finalRootElementName = CoreUtils.isNullOrEmpty(rootElementName) ? "QueryRequest" : rootElementName;
115+
return xmlReader.readObject(finalRootElementName, reader -> {
116+
QueryRequest deserializedQueryRequest = new QueryRequest();
117+
while (reader.nextElement() != XmlToken.END_ELEMENT) {
118+
QName elementName = reader.getElementName();
119+
120+
if ("Expression".equals(elementName.getLocalPart())) {
121+
deserializedQueryRequest.expression = reader.getStringElement();
122+
} else {
123+
reader.skipElement();
124+
}
125+
}
126+
127+
return deserializedQueryRequest;
128+
});
129+
}
130+
}

0 commit comments

Comments
 (0)