Skip to content

Commit c6af354

Browse files
committed
chore: add documentation for setting custom base path
1 parent bcf3629 commit c6af354

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

docs-js_versioned_docs/version-v3/features/openapi/execute-openapi-request.mdx

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

115115
<CustomRequestConfigNote />
116116

117+
### Setting a Custom Base Path
118+
119+
A custom base path can be manually set in the `options-per-service.json` during client generation.
120+
It can also be adjusted per request by using the `setBasePath()` method:
121+
122+
```ts
123+
MyApi.myFunction()
124+
.setBasePath('/base/path/to/service')
125+
.execute(destination);
126+
```
127+
128+
This will change the base path of your request.
129+
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/function/path`, where `/function/path` is the API path parameter.
130+
117131
### Setting Middlewares
118132

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

docs-js_versioned_docs/version-v3/features/openapi/generate-openapi-client.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ 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. This information is optional.
53+
- `basePath`: the URL path to be prepended before the API path parameter for every request.
54+
55+
This information can be adjusted manually and ensures that every run of the generator produces the same names for the generation.
56+
57+
Example:
58+
59+
```json
60+
{
61+
"path/to/your/service-specifications/MyService.yaml": {
62+
"directoryName": "my-service",
63+
"basePath": "/base/path/to/service",
64+
"packageName": "my-service"
65+
}
66+
}
67+
```
68+
4469
By default, the generated clients will each contain:
4570

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

0 commit comments

Comments
 (0)