Skip to content

Commit

Permalink
tsp, upgrade compiler 0.52 (#2527)
Browse files Browse the repository at this point in the history
* support clientName

* use 0.13.0
  • Loading branch information
weidongxu-microsoft authored Jan 25, 2024
1 parent 6acad68 commit 171aaf1
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 393 deletions.
6 changes: 6 additions & 0 deletions typespec-extension/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 0.13.0 (2024-01-25)

Compatible with compiler 0.52.

- Supported `@clientName` from "@azure-tools/typespec-client-generator-core".

## 0.12.3 (2024-01-22)

Compatible with compiler 0.51.
Expand Down
580 changes: 234 additions & 346 deletions typespec-extension/package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions typespec-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-java",
"version": "0.12.3",
"version": "0.13.0",
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
"keywords": [
"TypeSpec"
Expand Down Expand Up @@ -45,39 +45,39 @@
"target/emitter.jar"
],
"peerDependencies": {
"@typespec/compiler": ">=0.51.0 <1.0.0",
"@typespec/http": ">=0.51.0 <1.0.0",
"@typespec/rest": ">=0.51.0 <1.0.0",
"@typespec/openapi": ">=0.51.0 <1.0.0",
"@typespec/versioning": ">=0.51.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.37.2 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.37.0 <1.0.0"
"@typespec/compiler": ">=0.52.0 <1.0.0",
"@typespec/http": ">=0.52.0 <1.0.0",
"@typespec/rest": ">=0.52.0 <1.0.0",
"@typespec/openapi": ">=0.52.0 <1.0.0",
"@typespec/versioning": ">=0.52.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.38.0 <1.0.0"
},
"dependencies": {
"@autorest/codemodel": "~4.20.0",
"lodash": "~4.17.21",
"js-yaml": "~4.1.0"
},
"devDependencies": {
"prettier": "~3.1.0",
"prettier": "~3.2.4",
"@types/lodash": "~4.14.202",
"@types/js-yaml": "~4.0.9",
"@types/mocha": "~10.0.6",
"@types/node": "~20.10.3",
"c8": "~8.0.1",
"eslint": "~8.55.0",
"@types/node": "~20.11.6",
"c8": "~9.1.0",
"eslint": "~8.56.0",
"mocha": "~10.2.0",
"rimraf": "~5.0.5",
"typescript": "~5.3.3",
"@typescript-eslint/parser": "~6.13.2",
"@typescript-eslint/eslint-plugin": "~6.13.2",
"@typescript-eslint/parser": "~6.19.1",
"@typescript-eslint/eslint-plugin": "~6.19.1",
"eslint-plugin-deprecation": "~2.0.0",
"@azure-tools/typespec-azure-core": "0.37.2",
"@azure-tools/typespec-client-generator-core": "0.37.0",
"@typespec/compiler": "0.51.0",
"@typespec/http": "0.51.0",
"@typespec/openapi": "0.51.0",
"@typespec/rest": "0.51.0",
"@typespec/versioning": "0.51.0"
"@azure-tools/typespec-azure-core": "0.38.0",
"@azure-tools/typespec-client-generator-core": "0.38.0",
"@typespec/compiler": "0.52.0",
"@typespec/http": "0.52.0",
"@typespec/openapi": "0.52.0",
"@typespec/rest": "0.52.0",
"@typespec/versioning": "0.52.0"
}
}
2 changes: 1 addition & 1 deletion typespec-extension/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Install [Node.js](https://nodejs.org/en/download/) 16 or above. (Verify by `node

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

Install [TypeSpec](https://github.com/microsoft/typespec/) 0.51.
Install [TypeSpec](https://github.com/microsoft/typespec/) 0.52.

# Initialize TypeSpec Project

Expand Down
5 changes: 5 additions & 0 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
isInternal,
SdkClient,
getCrossLanguageDefinitionId,
getClientNameOverride,
} from "@azure-tools/typespec-client-generator-core";
import { fail } from "assert";
import {
Expand Down Expand Up @@ -2455,6 +2456,10 @@ export class CodeModelBuilder {
nameHint: string | undefined = undefined,
): string {
// TODO: once getLibraryName API in typespec-client-generator-core can get projected name from language and client, as well as can handle template case, use getLibraryName API
const emitterClientName = getClientNameOverride(this.sdkContext, target);
if (emitterClientName) {
return emitterClientName;
}
const languageProjectedName = getProjectedName(this.program, target, "java");
if (languageProjectedName) {
return languageProjectedName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public String handlePartialUpdate(String filePath, String generatedContent) {
SETTINGS_MAP.put("required-parameter-client-methods", true);
SETTINGS_MAP.put("generic-response-type", true);
SETTINGS_MAP.put("output-model-immutable", true);
SETTINGS_MAP.put("client-flattened-annotation-target", "disabled");
SETTINGS_MAP.put("disable-required-property-annotation", true);
// Defaulting to KeyCredential and not providing TypeSpec services to generate with AzureKeyCredential.
SETTINGS_MAP.put("use-key-credential", true);
Expand Down
22 changes: 11 additions & 11 deletions typespec-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.28.7",
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.12.3.tgz"
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.13.0.tgz"
},
"devDependencies": {
"@typespec/prettier-plugin-typespec": "~0.51.0",
"@azure-tools/typespec-azure-resource-manager": "~0.37.1",
"@typespec/prettier-plugin-typespec": "~0.52.0",
"@azure-tools/typespec-azure-resource-manager": "~0.38.0",
"prettier-plugin-organize-imports": "3.2.4",
"prettier": "~3.1.0"
"prettier": "~3.2.4"
},
"overrides": {
"@typespec/compiler": ">=0.51.0 <1.0.0",
"@typespec/http": ">=0.51.0 <1.0.0",
"@typespec/rest": ">=0.51.0 <1.0.0",
"@typespec/versioning": ">=0.51.0 <1.0.0",
"@typespec/openapi": ">=0.51.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.37.2 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.37.0 <1.0.0"
"@typespec/compiler": ">=0.52.0 <1.0.0",
"@typespec/http": ">=0.52.0 <1.0.0",
"@typespec/rest": ">=0.52.0 <1.0.0",
"@typespec/versioning": ">=0.52.0 <1.0.0",
"@typespec/openapi": ">=0.52.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.38.0 <1.0.0"
},
"private": true
}
28 changes: 14 additions & 14 deletions typespec-tests/src/main/java/com/cadl/naming/models/BytesData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,36 @@
@Immutable
public final class BytesData extends Data {
/*
* The data property.
* The data_bytes property.
*/
@Generated
private final byte[] data;
private final byte[] dataAsBytes;

/**
* Creates an instance of BytesData class.
*
* @param data the data value to set.
* @param dataAsBytes the dataAsBytes value to set.
*/
@Generated
private BytesData(byte[] data) {
this.data = data;
private BytesData(byte[] dataAsBytes) {
this.dataAsBytes = dataAsBytes;
}

/**
* Get the data property: The data property.
* Get the dataAsBytes property: The data_bytes property.
*
* @return the data value.
* @return the dataAsBytes value.
*/
@Generated
public byte[] getData() {
return CoreUtils.clone(this.data);
public byte[] getDataAsBytes() {
return CoreUtils.clone(this.dataAsBytes);
}

@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("kind_id", "bytes");
jsonWriter.writeBinaryField("data", this.data);
jsonWriter.writeBinaryField("data_bytes", this.dataAsBytes);
return jsonWriter.writeEndObject();
}

Expand All @@ -63,7 +63,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
*/
public static BytesData fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
byte[] data = null;
byte[] dataAsBytes = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
Expand All @@ -75,13 +75,13 @@ public static BytesData fromJson(JsonReader jsonReader) throws IOException {
"'kind_id' was expected to be non-null and equal to 'bytes'. The found 'kind_id' was '"
+ type + "'.");
}
} else if ("data".equals(fieldName)) {
data = reader.getBinary();
} else if ("data_bytes".equals(fieldName)) {
dataAsBytes = reader.getBinary();
} else {
reader.skipChildren();
}
}
return new BytesData(data);
return new BytesData(dataAsBytes);
});
}
}
6 changes: 6 additions & 0 deletions typespec-tests/tsp/naming.tsp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import "@typespec/rest";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.Core;
using Azure.Core.Foundations;
using Azure.ClientGenerator.Core;

@summary("summary of Naming")
@doc("description of Naming")
Expand Down Expand Up @@ -52,6 +54,10 @@ model Data {

model BytesData extends Data {
kind: "bytes";

@clientName("dataAsBytes")
@projectedName("json", "data_bytes")
@projectedName("client", "noeffect")
data: bytes;
}

Expand Down

0 comments on commit 171aaf1

Please sign in to comment.