Skip to content

Commit 9f2ea32

Browse files
feat(open-api-typescript): generate path params flag
generate path params flag
1 parent 7d6e896 commit 9f2ea32

File tree

10 files changed

+64611
-3
lines changed

10 files changed

+64611
-3
lines changed

.changeset/purple-walls-repeat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": minor
3+
---
4+
5+
Support generating path params for flaky schemas using --generate-path-params option

docs/cli.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ The following flags are supported in the CLI:
121121
| `--path-params-as-types` | | `false` | Allow dynamic string lookups on the `paths` object |
122122
| `--root-types` | | `false` | Exports types from `components` as root level type aliases |
123123
| `--root-types-no-schema-prefix` | | `false` | Do not add "Schema" prefix to types at the root level (should only be used with --root-types) |
124-
| `--make-paths-enum ` | | `false` | Generate ApiPaths enum for all paths |
124+
| `--make-paths-enum` | | `false` | Generate ApiPaths enum for all paths |
125+
| `--generate-path-params` | | `false` | Generate path parameters for all paths where they are undefined by schema |
125126

126127
### pathParamsAsTypes
127128

@@ -227,3 +228,9 @@ export enum ApiPaths {
227228
```
228229

229230
:::
231+
232+
### generatePathParams
233+
234+
This option is useful for generating path params optimistically when the schema has flaky path parameter definitions.
235+
Checks the path for opening and closing brackets and extracts them as path parameters.
236+
Does not override already defined by schema path parameters.

packages/openapi-typescript/bin/cli.js

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const flags = parser(args, {
8484
"rootTypes",
8585
"rootTypesNoSchemaPrefix",
8686
"makePathsEnum",
87+
"generatePathParams",
8788
],
8889
string: ["output", "redocly"],
8990
alias: {
@@ -146,6 +147,7 @@ async function generateSchema(schema, { redocly, silent = false }) {
146147
rootTypes: flags.rootTypes,
147148
rootTypesNoSchemaPrefix: flags.rootTypesNoSchemaPrefix,
148149
makePathsEnum: flags.makePathsEnum,
150+
generatePathParams: flags.generatePathParams,
149151
redocly,
150152
silent,
151153
}),

0 commit comments

Comments
 (0)