Skip to content

Commit 8413897

Browse files
fix: Use of x-nullable and nullable for additionalProperties. (#1236)
1 parent e5c0424 commit 8413897

File tree

9 files changed

+199
-1
lines changed

9 files changed

+199
-1
lines changed

.changeset/fair-mice-impress.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kubb/plugin-oas": patch
3+
---
4+
5+
Use of `x-nullable` and `nullable` for additionalProperties.

docs/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Changelog
44

55
# Changelog
66

7+
## 3.0.0-alpha.22
8+
- [`plugin-zod`](/plugins/plugin-zod): Use of `x-nullable` and `nullable` for additionalProperties.
9+
10+
711
## 3.0.0-alpha.21
812
- [`plugin-faker`](/plugins/plugin-faker): use of `faker.image.url()` instead of `faker.image.imageUrl()`
913

packages/plugin-faker/src/parser/__snapshots__/index.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ exports[`faker parse > 'min' 1`] = `undefined`;
4242
4343
exports[`faker parse > 'nullable' 1`] = `undefined`;
4444
45+
exports[`faker parse > 'nullableAdditionalProperties' 1`] = `"{}"`;
46+
4547
exports[`faker parse > 'number' 1`] = `"faker.number.float()"`;
4648
4749
exports[`faker parse > 'object' 1`] = `"{"firstName": faker.string.alpha(),"address": faker.string.alpha()}"`;

packages/plugin-oas/mocks/petStore.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ components:
113113
type: string
114114
tag:
115115
type: string
116+
schema:
117+
type: object
118+
additionalProperties:
119+
x-nullable: true
120+
type: string
116121
Pets:
117122
type: array
118123
items:

packages/plugin-oas/mocks/schemas.ts

+50
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,30 @@ const basic: Array<{ name: string; schema: Schema }> = [
443443
keyword: schemaKeywords.blob,
444444
},
445445
},
446+
{
447+
name: 'nullableAdditionalProperties',
448+
schema: {
449+
keyword: schemaKeywords.object,
450+
args: {
451+
properties: {},
452+
additionalProperties: [
453+
{
454+
keyword: schemaKeywords.string,
455+
},
456+
{
457+
args: {
458+
format: undefined,
459+
type: schemaKeywords.string,
460+
},
461+
keyword: schemaKeywords.schema,
462+
},
463+
{
464+
keyword: schemaKeywords.nullable,
465+
},
466+
],
467+
},
468+
},
469+
},
446470
]
447471

448472
const full: Array<{ name: string; schema: Schema[] }> = [
@@ -556,6 +580,32 @@ const full: Array<{ name: string; schema: Schema[] }> = [
556580
},
557581
],
558582
},
583+
{
584+
name: 'nullableAdditionalProperties',
585+
schema: [
586+
{
587+
keyword: schemaKeywords.object,
588+
args: {
589+
properties: {},
590+
additionalProperties: [
591+
{
592+
keyword: schemaKeywords.string,
593+
},
594+
{
595+
args: {
596+
format: undefined,
597+
type: schemaKeywords.string,
598+
},
599+
keyword: schemaKeywords.schema,
600+
},
601+
{
602+
keyword: schemaKeywords.number,
603+
},
604+
],
605+
},
606+
},
607+
],
608+
},
559609
{
560610
name: 'Record',
561611
schema: [

packages/plugin-oas/src/__snapshots__/SchemaGenerator.test.ts.snap

+37
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,43 @@ exports[`SchemaGenerator core > 'Pet' 1`] = `
6565
"keyword": "name",
6666
},
6767
],
68+
"schema": [
69+
{
70+
"args": {
71+
"additionalProperties": [
72+
{
73+
"keyword": "string",
74+
},
75+
{
76+
"args": {
77+
"format": undefined,
78+
"type": "string",
79+
},
80+
"keyword": "schema",
81+
},
82+
{
83+
"keyword": "nullable",
84+
},
85+
],
86+
"properties": {},
87+
},
88+
"keyword": "object",
89+
},
90+
{
91+
"args": {
92+
"format": undefined,
93+
"type": "object",
94+
},
95+
"keyword": "schema",
96+
},
97+
{
98+
"args": "schema",
99+
"keyword": "name",
100+
},
101+
{
102+
"keyword": "optional",
103+
},
104+
],
68105
"tag": [
69106
{
70107
"keyword": "string",

packages/plugin-ts/src/parser/__snapshots__/index.test.ts.snap

+93
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,99 @@ exports[`type parse > 'min' 1`] = `undefined`;
467467

468468
exports[`type parse > 'nullable' 1`] = `undefined`;
469469

470+
exports[`type parse > 'nullableAdditionalProperties' 1`] = `
471+
NodeObject {
472+
"emitNode": undefined,
473+
"end": -1,
474+
"flags": 16,
475+
"id": 0,
476+
"kind": 187,
477+
"localSymbol": undefined,
478+
"members": [
479+
NodeObject {
480+
"emitNode": undefined,
481+
"end": -1,
482+
"flags": 16,
483+
"id": 0,
484+
"jsDoc": undefined,
485+
"kind": 181,
486+
"localSymbol": undefined,
487+
"locals": undefined,
488+
"modifierFlagsCache": 0,
489+
"modifiers": undefined,
490+
"nextContainer": undefined,
491+
"original": undefined,
492+
"parameters": [
493+
NodeObject {
494+
"dotDotDotToken": undefined,
495+
"emitNode": undefined,
496+
"end": -1,
497+
"flags": 16,
498+
"id": 0,
499+
"initializer": undefined,
500+
"jsDoc": undefined,
501+
"kind": 169,
502+
"localSymbol": undefined,
503+
"modifierFlagsCache": 0,
504+
"modifiers": undefined,
505+
"name": IdentifierObject {
506+
"emitNode": undefined,
507+
"end": -1,
508+
"escapedText": "key",
509+
"flags": 16,
510+
"flowNode": undefined,
511+
"id": 0,
512+
"jsDoc": undefined,
513+
"kind": 80,
514+
"parent": undefined,
515+
"pos": -1,
516+
"symbol": undefined,
517+
"transformFlags": 0,
518+
},
519+
"original": undefined,
520+
"parent": undefined,
521+
"pos": -1,
522+
"questionToken": undefined,
523+
"symbol": undefined,
524+
"transformFlags": 1,
525+
"type": TokenObject {
526+
"emitNode": undefined,
527+
"end": -1,
528+
"flags": 16,
529+
"id": 0,
530+
"kind": 154,
531+
"parent": undefined,
532+
"pos": -1,
533+
"transformFlags": 1,
534+
},
535+
},
536+
],
537+
"parent": undefined,
538+
"pos": -1,
539+
"symbol": undefined,
540+
"transformFlags": 1,
541+
"type": TokenObject {
542+
"emitNode": undefined,
543+
"end": -1,
544+
"flags": 16,
545+
"id": 0,
546+
"kind": 154,
547+
"parent": undefined,
548+
"pos": -1,
549+
"transformFlags": 1,
550+
},
551+
"typeArguments": undefined,
552+
},
553+
],
554+
"modifierFlagsCache": 0,
555+
"original": undefined,
556+
"parent": undefined,
557+
"pos": -1,
558+
"symbol": undefined,
559+
"transformFlags": 1,
560+
}
561+
`;
562+
470563
exports[`type parse > 'number' 1`] = `
471564
TokenObject {
472565
"emitNode": undefined,

packages/plugin-zod/src/parser/__snapshots__/index.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ exports[`zod parse > 'min' 1`] = `".min(2)"`;
4242

4343
exports[`zod parse > 'nullable' 1`] = `".nullable()"`;
4444

45+
exports[`zod parse > 'nullableAdditionalProperties' 1`] = `"z.object({}).catchall(z.string().nullable())"`;
46+
4547
exports[`zod parse > 'number' 1`] = `"z.number()"`;
4648

4749
exports[`zod parse > 'object' 1`] = `"z.object({"firstName": z.string().min(2),"address": z.string().describe("Your address").nullable()})"`;

packages/plugin-zod/src/parser/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
263263
? current.args.additionalProperties
264264
.map((schema) => parse(current, schema, options))
265265
.filter(Boolean)
266-
.at(0)
266+
.join('')
267267
: undefined
268268

269269
const text = [

0 commit comments

Comments
 (0)