Skip to content

Commit

Permalink
fix(core): make sure to add '| null' to enums with null in type array (
Browse files Browse the repository at this point in the history
  • Loading branch information
AllieJonsson authored Dec 9, 2024
1 parent b23257b commit b653320
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core/src/getters/scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const getScalar = ({
}): ScalarValue => {
// NOTE: Angular client does not support nullable types
const isAngularClient = context.output.client === OutputClient.ANGULAR;
const nullable = item.nullable && !isAngularClient ? ' | null' : '';
const typeIncludesNull =
Array.isArray(item.type) && item.type.includes('null');
const nullable =
(typeIncludesNull || item.nullable) && !isAngularClient ? ' | null' : '';

const enumItems = item.enum?.filter((enumItem) => enumItem !== null);

Expand Down
7 changes: 7 additions & 0 deletions tests/specifications/null-type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ components:
type:
- 'boolean'
- 'null'
NullStringEnum:
type:
- string
- 'null'
enum:
- foo
- bar
NullEnum:
nullable: true
enum:
Expand Down

0 comments on commit b653320

Please sign in to comment.