You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AutoRest with flag `--java`. This is used primary for lib that involves a handwritten (data-plane) client over generated code. For example, `azure-storage-blob`.
6
+
7
+
This mode is not recommended to be used for new lib.
The request body and response body both take the type of `BinaryData`. And optional parameters are set via `RequestOptions`. This pattern of client method is called "Protocol API".
In additional to "Protocol API", it also generates the client method overloads with model class and optional parameters. This is called "Convenience API".
73
+
74
+
### Client
75
+
76
+
By default, The client is accessed via the Builder pattern, same as those in [Data-plane from Swagger](#data-plane-from-swagger).
77
+
78
+
`enable-subclient` emitter options can be used to switch the client structure to parent-child clients.
This is used for management-plane lib generated from Swagger, with flag `--java --fluent=LITE`, or from TypeSpec.
95
+
96
+
The generated client method is similar to that generated from [Vanilla mode](#vanilla).
97
+
98
+
### Client
99
+
100
+
Model class would be modeled as `Resource`, `ProxyResource`.
101
+
102
+
Another Fluent code layer would be generated, modeling concept as "subscription", "resource group", "resource", "parent resource", "extension resource", and CRUD of the resource.
103
+
104
+
## Unbranded
105
+
106
+
This is used for 3rd-party lib that generated from TypeSpec.
Copy file name to clipboardExpand all lines: docs/developer/design.md
+29-35Lines changed: 29 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,16 @@
2
2
3
3
## Modules
4
4
5
-
`extension-base` is the shared module providing `CodeModel` represented in Java language, JSON RPC, and `NewPlugin` plugin entry.
5
+
`javagen` is the shared module on models and operations. It contains the shared classes such as: `CodeModel` represented in Java language, JSON RPC, and `NewPlugin` plugin entry.
6
+
It alone is the pipeline for data-plane SDK generator (includes "vanilla" -- the mode that requires a handwritten client).
7
+
It uses Eclipse JDT Language Server to provide [Customizations](../../readme.md#customizations), in postprocess stage.
6
8
7
-
`preprocessor`, `javagen`, `postprocessor` is the shared modules on models and operations.
8
-
Also, they are the pipeline for data-plane SDK generator.
9
-
`postprocessor` uses Eclipse JDT Language Server to provide customizations.
10
-
11
-
`fluentnamer`, `fluentgen` is activated when `--fluent` option is specified.
12
-
They are the pipeline for management-plane SDK generator.
13
-
14
-
`javagen` with Android-style generation is activated when `--android` option is specified.
15
-
Together with `preprocessor`, they are the pipeline for data-plane SDK generator for Android.
9
+
`fluentgen` is activated when `--fluent` option is specified.
10
+
Built with code in `javagen` module, it is the pipeline for management-plane SDK generator.
16
11
17
12
## Configure on Modeler Four
18
13
19
-
Modeler Four is configured on `readme.md` of `preprocessor` and `fluentnamer`.
14
+
Modeler Four is configured on `readme.md`at repository root, as well as that of `javagen` and `fluentgen`. [The readme.md at repository root](../../readme.md#autorest-plugin-configuration) determined whether the entry point be `javagen` or `fluentgen`.
20
15
21
16
The most important configure is the version of Modeler Four.
22
17
The important options are:
@@ -27,25 +22,18 @@ The important options are:
27
22
28
23
Historically, data-plane leaves all of these options as `true`, while management-plane try to turn them to `false`.
29
24
30
-
Usually `preprocessor` and `fluentnamer` would save the input from pipeline to `code-model.yaml` in module root.
25
+
At preprocess stage, `javagen` or `fluentgen` would save the input from pipeline to `code-model.yaml` in a temporary folder (the environment variable `codegen.java.temp.directory` can be used to specify a path).
31
26
The content of this file is helpful for inspecting Modeler Four output.
32
27
33
28
One can set `--output-artifact=code-model-v4-no-tags` option to let AutoRest write the code-model file to output folder.
34
29
35
-
## RPC within AutoRest Java
36
-
37
-
### Between `preprocessor` and `javagen`
38
-
39
-
The content of RPC still follows `CodeModel`, after transformation of `preprocessor`.
40
-
However, it could look quite different from output of Modeler Four.
30
+
## Details on Modules
41
31
42
-
### Between `java` and `postprocessor`
32
+
### `javagen` Module
43
33
44
-
The content would be Java files.
34
+
This module re-uses code from `com.microsoft.typespec:http-client-generator-core` module.
45
35
46
-
## Details on Modules
47
-
48
-
### `extension-base` Module
36
+
#### Code Model
49
37
50
38
`NewPlugin` as entry for plugin, providing RPC for pipeline.
51
39
@@ -55,22 +43,12 @@ Roughly speaking, `schemas` contain the models, while `operations` grouped into
55
43
56
44
`JavaSettings` provides basic configuration for AutoRest Java.
57
45
58
-
###`preprocessor` Module
46
+
#### Pre-process
59
47
60
-
`Transformer` renames model/property/method/parameter to be consistent to Java naming. It also supplies the `next` operation for `x-ms-pageable` extension.
48
+
`Preprocessor` with `Transformer` renames model/property/method/parameter to be consistent to Java naming. It also supplies the `next` operation for `x-ms-pageable` extension.
61
49
62
50
`CodeNamer` as utility for Java naming, including conflict handling e.g. from reserved word in Java.
63
51
64
-
### `fluentnamer` Module
65
-
66
-
In addition to what is done in `preprocessor` module, its `Transformer` handles normalization of resource type (e.g. subclass of `Resource`), error type (e.g. subclass of `ManagementException` and `ManagementError`), operation name (e.g. `getByResourceGroup` and `listByResourceGroup`).
67
-
68
-
It also handles naming conflict between operation groups and models (e.g. `FooClient` from operation group client and `FooClient` from model, maybe another `FooClient` of the service client), naming of anonymous model (e.g. property of anonymous schema, anonymous superclass), rename from options, cleaning up of unused schemas (which is necessary because of the normalization).
69
-
70
-
`FluentJavaSettings` provides additional configuration on fluentnamer and fluentgen.
71
-
72
-
### `javagen` Module
73
-
74
52
#### Client Model
75
53
76
54
Classes under `model.clientmodel` namespace is the client model, which is the representation of Java code to be generated in memory.
@@ -122,11 +100,27 @@ It writes Java code using classes under `model.javamodel` namespace.
122
100
123
101
Classes of mapper and template is constructed by abstract factory, which enables overriding the behavior in other modules.
124
102
103
+
#### Post-process
104
+
105
+
`Postprocessor` modifies generated Java code, with `PartialUpdateHandler` for [Partial Update](../generate/dataplane-customization.md), and with `Customization` for [Customizations via code](../../readme.md#customizations).
106
+
107
+
The formatting of generated Java code is also done in this stage, leverage [spotless Maven plugin](https://github.com/diffplug/spotless).
108
+
125
109
### `fluentgen` Module
126
110
127
111
Fluent Java SDK for management-plane has a different [API design](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/DESIGN.md).
128
112
Simply speaking, the Fluent interface wraps the vanilla Client and REST API.
129
113
114
+
This module re-uses code from `com.microsoft.typespec:http-client-generator-mgmt` module.
115
+
116
+
#### Pre-process
117
+
118
+
In addition to what is done in [Pre-process of javagen](#pre-process), its `Transformer` handles normalization of resource type (e.g. subclass of `Resource`), error type (e.g. subclass of `ManagementException` and `ManagementError`), operation name (e.g. `getByResourceGroup` and `listByResourceGroup`).
119
+
120
+
It also handles naming conflict between operation groups and models (e.g. `FooClient` from operation group client and `FooClient` from model, maybe another `FooClient` of the service client), naming of anonymous model (e.g. property of anonymous schema, anonymous superclass), rename from options, cleaning up of unused schemas (which is necessary because of the normalization).
121
+
122
+
`FluentJavaSettings` provides additional configuration on fluentnamer and fluentgen.
123
+
130
124
#### Client Model
131
125
132
126
`FluentClient` is the container of the client model objects, which includes `Client`.
Copy file name to clipboardExpand all lines: docs/developer/readme.md
+18-20Lines changed: 18 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,21 @@
4
4
5
5
AutoRest Java is the Java language generator for AutoRest.
6
6
7
-
As [npm package](https://github.com/Azure/autorest/blob/main/docs/developer/writing-an-extension.md), it is defined by the [`package.json`](https://github.com/Azure/autorest.java/blob/main/package.json) located in project root, and the `package.json` in `preprocessor`, `javagen`, `postprocessor`, `fluentnamer`,`fluentgen`.
7
+
As [NPM package](https://github.com/Azure/autorest/blob/main/docs/developer/writing-an-extension.md), it is defined by the [`package.json`](https://github.com/Azure/autorest.java/blob/main/package.json) located in project root, and the `package.json` in `javagen` and`fluentgen`.
8
8
9
9
As AutoRest plugin, it is defined by the [YAML section in `readme.md`](https://github.com/Azure/autorest.java/blob/main/javagen/readme.md), located in the same folders of `package.json`.
10
10
11
-
## Build and Unit Test
11
+
## Build and Test
12
12
13
13
### Build
14
14
15
15
Build is configured via Maven.
16
16
17
17
There is several build profiles:
18
-
-`local` profile. It is required to be enabled. It uses `maven-shade-plugin` to combine project output to a single jar.
19
-
-`testVanilla` profile. It enables the integrated vanilla tests, which is the common ground for all modules.
20
-
-`testAzure` profile. It enables the integrated Azure tests, which tests handling of some advanced [AutoRest Extensions for OpenAPI 2.0](https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md).
21
-
-`testFluent` profile. It enables the integrated Fluent tests, which tests generation of Fluent management SDKs for [ARM](https://docs.microsoft.com/azure/azure-resource-manager/management/overview).
18
+
-**`local` profile**: It is required to be enabled. It uses `maven-shade-plugin` to combine project output to a single jar.
19
+
-**`testVanilla` profile**: It enables the integrated vanilla tests, which is the common ground for all modules.
20
+
-**testAzure profile**: It enables the integrated Azure tests, which tests handling of some advanced [AutoRest Extensions for OpenAPI 2.0](https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md).
21
+
-**`testFluent` profile**: It enables the integrated Fluent tests, which tests generation of Fluent management SDKs for [ARM](https://docs.microsoft.com/azure/azure-resource-manager/management/overview).
22
22
23
23
### Unit Test
24
24
@@ -51,12 +51,20 @@ Use `--use` option of the AutoRest to load the local AutoRest Java build (instea
51
51
52
52
The `name` of `@autorest/java` in `package.json` makes sure that it is loaded when `--java` option is provided.
53
53
54
-
## Pre-release
54
+
## Publish `@autorest/java` to NPM
55
55
56
-
1. Update `version` in root `package.json`.
57
-
2. Run "Pre-release autorest.java" in [GitHub Actions](https://github.com/Azure/autorest.java/actions). Provide the same `release version`.
56
+
1. Update `version` in root `package.json`, merge the PR.
57
+
2. Run "autorest.java - publish" in (internal) DevOps.
58
58
3. Update Release notes in [GitHub Releases](https://github.com/Azure/autorest.java/releases).
59
59
60
+
## Publish customization libraries to Maven
61
+
62
+
Modules in following folders are published to Maven
The publish task involves local build and manual operation via Partner release pipeline.
67
+
60
68
## Logging
61
69
62
70
**DO NOT** log to stdout. AutoRest uses stdin and stdout as [RPC channel for plugins](https://github.com/Azure/autorest/blob/main/docs/developer/writing-an-extension.md#rpc-channel).
@@ -105,14 +113,4 @@ suspend=n,address=*:5005".
105
113
106
114
After the remote debugger is configured, run autorest with this additional argument `--java.debugger`. The AutoRest
107
115
process will block until the JVM debugger is attached, so, after the AutoRest process pauses, start the debugger
108
-
which will connect to the remote debugger and this will hit the breakpoints set in the "Javagen" plugin. If you want
109
-
to set up a breakpoint in a different plugin like preprocessor or postprocessor, you can change the argument to
110
-
`--preprocessor.debugger` or `postprocessor.debugger` respectively.
111
-
112
-
113
-
### Interactive UI to trace AutoRest pipeline
114
-
115
-
Running autorest with `--interactive` mode on will pop up a browser window to show an interactive UI of the AutoRest
116
-
pipeline. This generally helps in identifying all the plugins that are executed, their order of execution, their
117
-
inputs and outputs.
118
-
116
+
which will connect to the remote debugger and this will hit the breakpoints set in the "Javagen" plugin.
As [NPM package](https://www.npmjs.com/package/@azure-tools/typespec-java), it is the Java client [emitter](https://typespec.io/docs/extending-typespec/emitters-basics/) for Azure SDKs.
6
+
7
+
## Build and Test
8
+
9
+
At present, almost all the code of the emitter is in [microsoft/typespec repository](https://github.com/microsoft/typespec/tree/main/packages/http-client-java).
10
+
11
+
### Build
12
+
13
+
NPM package is in `typespec-extension` folder.
14
+
15
+
The [`Build-TypeSpec.ps1` script](../../../Build-TypeSpec.ps1) builds the emitter.
16
+
It first build the JAR using Maven, copy it into `typespec-extension` folder, then build and pack the NPM package to a `tgz` file.
17
+
18
+
### Integrated Test
19
+
20
+
End-to-end test resides in `typespec-tests` folder.
21
+
22
+
At present, the tests is copied from
23
+
24
+
The [`Generate.ps1` script](../../../typespec-tests/Generate.ps1) generates the test code from [http-specs](https://github.com/microsoft/typespec/tree/main/packages/http-specs) and [azure-http-specs](https://github.com/Azure/typespec-azure/tree/main/packages/azure-http-specs).
25
+
26
+
`npm run spector-serve` starts the mock server.
27
+
28
+
Then standard Maven Surefire would run the tests.
29
+
30
+
## Publish `@azure-tools/typespec-java` to NPM
31
+
32
+
1. Update `version` in `typespec-extension/package.json`.
33
+
2. Update `typespec-java``version` in `typespec-test/package.json`.
34
+
3. Update `typespec-extensions/changelog.md`, merge the PR.
35
+
4. Run "typespec-java - publish" in (internal) DevOps.
36
+
5. Update Release notes in [GitHub Releases](https://github.com/Azure/autorest.java/releases).
37
+
38
+
## Debugging
39
+
40
+
### Debugging TypeScript Code
41
+
42
+
In project that runs TypeSpec compiler (e.g. `typespec-tests` folder), run
to run `tsp compile` in debug mode (as Node.js process).
47
+
48
+
Then, have the debugging client attach to port 9229 of the Node.js process.
49
+
Here is a [Visual Studio Code configuration](../../../typespec-tests/.vscode/launch.json).
50
+
51
+
Add break point to the `emitter.js` or `code-model-builder.js` under `node_modules/@azure-tools/typespec-java/dist/src` to debug the emitter.
52
+
53
+
### Debugging Java Code
54
+
55
+
See [Debugging Java Code](../../../typespec-extension/readme.md#debugging-java-code).
56
+
57
+
Alternatively, since the communication from TypeScript to Java is via the `code-model.yaml` file (plus the `EmitterOptions`), one can modify the `DEFAULT_OUTPUT_DIR` in `Main.java` under `core/packages/http-client-java/generator/http-client-generator` and debug `Main.main()`.
0 commit comments