Skip to content

Commit

Permalink
fix: handle OpenAPI 3.1 nullability for mocks (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed May 16, 2024
1 parent bc3d277 commit efc4c35
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/mock/src/faker/getters/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ export const getMockObject = ({
});
}

if (Array.isArray(item.type)) {
return combineSchemasMock({
item: {
anyOf: item.type.map((type) => ({ type })),
name: item.name,
},
separator: 'anyOf',
mockOptions,
operationId,
tags,
combine,
context,
imports,
existingReferencedProperties,
});
}

if (item.properties) {
let value =
!combine ||
Expand Down
8 changes: 7 additions & 1 deletion packages/mock/src/faker/getters/scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ export const getMockScalar = ({
};
}

case 'object':
case 'null':
return {
value: 'null',
imports: [],
name: item.name,
};

default: {
return getMockObject({
item,
Expand Down
10 changes: 10 additions & 0 deletions tests/configs/mock.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ export default defineConfig({
target: '../specifications/petstore.yaml',
},
},
nullType: {
output: {
schemas: '../generated/mock/null-type/model',
target: '../generated/mock/null-type/endpoints.ts',
mock: true,
},
input: {
target: '../specifications/null-type.yaml',
},
},
});

0 comments on commit efc4c35

Please sign in to comment.