@autorest/java 4.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,148 @@
1
+ # Prerequisite
2
+
3
+ Install [Node.js](https://nodejs.org/en/download/) 16 or above. (Verify by `node --version`)
4
+
5
+ Install [Java](https://docs.microsoft.com/java/openjdk/download) 11 or above. (Verify by `java --version`)
6
+
7
+ Install [TypeSpec](https://github.com/microsoft/typespec/) 0.46.
8
+
9
+ # Initialize TypeSpec Project
10
+
11
+ Follow [TypeSpec Getting Started](https://github.com/microsoft/typespec/#using-node--npm) to initialize your TypeSpec project.
12
+
13
+ Make sure `npx tsp compile .` runs correctly.
14
+
15
+ # Add TypeSpec-Java
16
+
17
+ Make sure the version of [TypeSpec-java release](https://github.com/Azure/autorest.java/releases) depends on same version of "@typespec/compiler" as in your TypeSpec project.
18
+
19
+ Modify `package.json`, add one line under `dependencies`:
20
+ ```diff
21
+ "dependencies": {
22
+ "@typespec/compiler": "latest",
23
+ "@typespec/rest": "latest",
24
+ "@azure-tools/typespec-azure-core": "latest",
25
+ + "@azure-tools/typespec-java": "latest"
26
+ },
27
+ ```
28
+
29
+ Run `npm install` again to install `@azure-tools/typespec-java`.
30
+
31
+ Modify (or create) `tspconfig.yaml`, specify emit as `@azure-tools/typespec-java`:
32
+ ```diff
33
+ emit:
34
+ - "@azure-tools/typespec-java"
35
+ ```
36
+
37
+ # Generate Java
38
+
39
+ `npx tsp compile client.tsp --emit=@azure-tools/typespec-java` or `npx tsp compile client.tsp --emit=@azure-tools/typespec-java --options='@azure-tools/typespec-java.emitter-output-dir=<target-folder>`.
40
+
41
+ If `emitter-output-dir` option is not provided, generated Java code will be under `tsp-output/@azure-tools/typespec-java` folder.
42
+
43
+ # Optional Configuration
44
+
45
+ ## SDK
46
+
47
+ One can further configure the SDK generated, using the emitter options on `@azure-tools/typespec-java`.
48
+
49
+ ```yaml
50
+ emit:
51
+ - "@azure-tools/typespec-java"
52
+ options:
53
+ "@azure-tools/typespec-java":
54
+ emitter-output-dir: "{project-root}/azure-ai-language-authoring"
55
+ namespace: "com.azure.ai.language.authoring"
56
+ service-name: "Authoring"
57
+ partial-update: false
58
+ service-versions:
59
+ - "2022-05-15-preview"
60
+ namer: false
61
+ generate-samples: true
62
+ generate-tests: true
63
+ examples-directory: "./examples"
64
+ custom-types-subpackage: "implementation.models"
65
+ custom-types: InternalModel1,InternalModel2
66
+ ```
67
+
68
+ ## Convenience API
69
+
70
+ By default, TypeSpec-Java generates all protocol APIs and convenience APIs.
71
+ A few exceptions are API of JSON Merge Patch, and API of long-running operation with ambiguous response type.
72
+
73
+ See "convenientAPI" decorator from [typespec-client-generator-core](https://github.com/Azure/typespec-azure/tree/main/packages/typespec-client-generator-core).
74
+
75
+
76
+ # Customization
77
+ 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.
78
+
79
+ 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:
80
+
81
+ ```yaml
82
+ emit:
83
+ - "@azure-tools/typespec-java"
84
+ options:
85
+ "@azure-tools/typespec-java":
86
+ emitter-output-dir: "{project-root}/azure-ai-language-authoring"
87
+ namespace: "com.azure.ai.language.authoring"
88
+ customization-class: customization/src/main/java/MyCustomization.java
89
+ ```
90
+
91
+ # Changelog
92
+
93
+ See [changelog](https://github.com/Azure/autorest.java/blob/main/typespec-extension/changelog.md).
94
+
95
+ # Troubleshooting
96
+
97
+ ### Enable logging in Java code
98
+
99
+ To enable logging, use `tspconfig.yaml` to add the `loglevel: ` option. Typically, `tspconfig.yaml` file will be
100
+ located in the same directory as the `<target.tsp>` file. The `loglevel` setting is a developer option and should be set under `options->dev-options`. The acceptable values for `loglevel` are
101
+ `off`, `debug`, `info`, `warn` and `error`. A sample `tspconfig.yaml` is shown below that enables logging at `info` level. By default,
102
+ logging is enabled at `error` level.
103
+
104
+ ```yaml
105
+ emit:
106
+ - "@azure-tools/typespec-java"
107
+ options:
108
+ "@azure-tools/typespec-java":
109
+ emitter-output-dir: "{project-root}/tsp-output"
110
+ namespace: "com.azure.ai.language.authoring"
111
+ dev-options:
112
+ loglevel: info
113
+ ```
114
+
115
+ ### Debugging Java code
116
+
117
+ In order to set breakpoints and debug Java code locally on your development workspace, use the `tspconfig.yaml` file to
118
+ set the `debug` option to `true` under `options->dev-options` as shown in the example below. If the `debug` option is set
119
+ to `true`, then `tsp compile <target.tsp>` command will start the emitter which then invokes the Java process but the process
120
+ will be suspended until a debugger is attached to the process. The process listens on port 5005. Run the remote debugger
121
+ with this port on your IntelliJ or VS Code to connect to the Java process. This should now run the Java code generator
122
+ and breaks at all applicable breakpoints.
123
+
124
+ The remote debugger configuration is shown below for reference.
125
+
126
+ ![img.png](../docs/images/remote-debugger-config.png)
127
+
128
+ ```yaml
129
+ emit:
130
+ - "@azure-tools/typespec-java"
131
+ options:
132
+ "@azure-tools/typespec-java":
133
+ emitter-output-dir: "{project-root}/tsp-output"
134
+ partial-update: true
135
+ namer: true
136
+ dev-options:
137
+ support-versioning: true
138
+ debug: true
139
+ ```
140
+
141
+ ### New version of `@typespec/compiler` etc.
142
+
143
+ Force an installation of new version via deleting `package-lock.json` and `node_modules` in `./typespec-extension` folder.
144
+
145
+ ```shell
146
+ rm -rf node_modules
147
+ rm package-lock.json
148
+ ```
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "typespec-java-tests",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "scripts": {
6
+ "format": "npm run -s prettier -- --write",
7
+ "check-format": "npm run prettier -- --check",
8
+ "prettier": "prettier --config ./.prettierrc.yaml **/*.tsp",
9
+ "start-test-server": "npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./cadl-ranch-coverage-java.json"
10
+ },
11
+ "dependencies": {
12
+ "@typespec/openapi": ">=0.45.0 <1.0.0",
13
+ "@azure-tools/typespec-autorest": ">=0.31.0 <1.0.0",
14
+ "@azure-tools/cadl-ranch-specs": "0.16.2",
15
+ "@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.8.5.tgz"
16
+ },
17
+ "devDependencies": {
18
+ "@typespec/prettier-plugin-typespec": ">=0.45.0 <1.0.0",
19
+ "prettier": "~2.8.8"
20
+ },
21
+ "overrides": {
22
+ "@typespec/compiler": ">=0.45.0 <1.0.0",
23
+ "@typespec/http": ">=0.45.0 <1.0.0",
24
+ "@typespec/rest": ">=0.45.0 <1.0.0",
25
+ "@typespec/versioning": ">=0.45.0 <1.0.0",
26
+ "@azure-tools/typespec-azure-core": ">=0.31.0 <1.0.0"
27
+ },
28
+ "private": true
29
+ }
@@ -0,0 +1,38 @@
1
+ # Install and Test on TypeSpec-Java
2
+
3
+ ## Install TypeSpec
4
+
5
+ Install Node.js and [TypeSpec](https://github.com/microsoft/typespec/).
6
+
7
+ ```shell
8
+ npm install -g @typespec/compiler
9
+ ```
10
+
11
+ ## Build JAR
12
+
13
+ `mvn package -P local,tsp` in project root.
14
+
15
+ This will build `./typespec-extension`, which is basically `preprocessor` and `javagen` combined.
16
+
17
+ ## Build and Install TypeSpec-Java
18
+
19
+ `pwsh Setup.ps1` in `./typespec-tests` folder.
20
+
21
+ It makes the npm package in `./typespec-extension`, then install it to `./typespec-tests` folder.
22
+
23
+ ## Generate Code
24
+
25
+ `tsp compile <target.tsp>` in `./typespec-tests` folder.
26
+
27
+ Generated code will be at `./typespec-tests/tsp-output/` folder.
28
+
29
+ ## Troubleshooting
30
+
31
+ ### New version of `@typespec/compiler` etc.
32
+
33
+ Force an installation of new version via deleting `package-lock.json` and `node_modules` in `./typespec-extension` folder.
34
+
35
+ ```shell
36
+ rm -rf node_modules
37
+ rm package-lock.json
38
+ ```