Skip to content

Commit 37ebc4f

Browse files
authored
[JS] Add documentation for setting custom base path (v4) (#1975)
* chore: add documentation for setting custom base path * Revert "chore: add documentation for setting custom base path" This reverts commit c6af354. * chore: add documentation for setting custom base path in v4 * fix: prettier * chore: address review comments * chore: address review comments
1 parent 9345584 commit 37ebc4f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs-js/features/openapi/execute-openapi-request.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ MyEntity.requestBuilder()
114114

115115
<CustomRequestConfigNote />
116116

117+
### Setting a Custom Service Path
118+
119+
A custom service path can be manually set in the `options-per-service.json` by providing a `basePath` property during client generation.
120+
It can also be adjusted per request by using the `setBasePath()` method:
121+
122+
```ts
123+
MyApi.myFunction().setBasePath('/base/path/to/service').execute(destination);
124+
```
125+
126+
This will change the base path of the request.
127+
Executing the example request above against a destination with the URL `https://my.some-system.com` will result in a request against the target like this: `https://my.some-system.com/base/path/to/service/myFunctionPath`, where `/myFunctionPath` is the API path parameter.
128+
117129
### Setting Middlewares
118130

119131
You can specify middlewares for a request via the `middleware()` method on the request builder:

docs-js/features/openapi/generate-openapi-client.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@ npx openapi-generator --input <input> --outputDir <outputDirectory>
4141

4242
The `<input>` points to your specification file or a directory containing the specification(s) and `<outputDirectory>` to the target folder where the generated client(s) will be saved.
4343

44+
An `options-per-service.json` file is created using the `--optionsPerService` option.
45+
46+
- When set to a directory path, an `options-per-service.json` file is read from or created in the given directory.
47+
- When set to a file path, the file is read or created with the given name.
48+
49+
This file is used for customizing subdirectory naming and contains a mapping from the original file name to the following information:
50+
51+
- `directoryName`: the name of the subdirectory the client code will be generated into.
52+
- `packageName`: the name of the npm package, if a package.json file is generated.
53+
This information is optional.
54+
- `basePath`: the URL path to be prepended to the API path before every request.
55+
56+
This information can be adjusted manually and ensures that every run of the generator produces the same names for the generation.
57+
58+
Example:
59+
60+
```json
61+
{
62+
"path/to/your/service-specifications/MyService.yaml": {
63+
"directoryName": "my-service",
64+
"basePath": "/base/path/to/service",
65+
"packageName": "my-service"
66+
}
67+
}
68+
```
69+
4470
By default, the generated clients will each contain:
4571

4672
- API files as `.ts` files - one for each "API" in the service.

0 commit comments

Comments
 (0)