这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilled-pumas-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix(parser): add `propertiesRequiredByDefault` transform option
34 changes: 34 additions & 0 deletions docs/openapi-ts/configuration/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,40 @@ export default {

You can customize the naming and casing pattern for `enums` schemas using the `.name` and `.case` options.

### Properties required by default

By default, any object schema with a missing `required` keyword is interpreted as "no properties are required." This is the correct behavior according to the OpenAPI standard. However, some specifications interpret a missing `required` keyword as "all properties should be required."

This option allows you to change the default behavior so that properties are required by default unless explicitly marked as optional.

::: code-group

```js [default]
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
transforms: {
propertiesRequiredByDefault: false, // [!code ++]
},
},
};
```

```js [required]
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
transforms: {
propertiesRequiredByDefault: true, // [!code ++]
},
},
};
```

:::

### Read-write

Your schemas might contain read-only or write-only fields. Using such schemas directly could mean asking the user to provide a read-only field in requests, or expecting a write-only field in responses. We separate schemas for requests and responses if direct usage would result in such scenarios.
Expand Down
13 changes: 13 additions & 0 deletions packages/openapi-ts-tests/main/test/3.0.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,19 @@ describe(`OpenAPI ${version}`, () => {
}),
description: 'transforms an array',
},
{
config: createConfig({
input: 'dutchie.json',
output: 'transforms-properties-required-by-default',
parser: {
transforms: {
propertiesRequiredByDefault: true,
},
},
plugins: ['@hey-api/typescript'],
}),
description: 'makes all object properties required by default',
},
{
config: createConfig({
input: 'type-invalid.json',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is auto-generated by @hey-api/openapi-ts

export type * from './types.gen';
Loading
Loading