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
2 changes: 1 addition & 1 deletion src/transformers/const-to-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function transformConstToEnum(def: JSONSchema4): JSONSchema4 {
* Type guard to check if the schema has a `const` property defined.
*/
function hasConst(def: JSONSchema4): boolean {
return 'const' in def && def.const !== undefined;
return typeof def === 'object' && 'const' in def && def.const !== undefined;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/const-to-enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,19 @@ describe('constToEnum', () => {
expect(result.oneOf?.[0].const).toBeUndefined();
expect(result.oneOf?.[1].enum).toEqual(['b', 'c']);
});

test('should handle required property with boolean true schema', () => {
const schema: JSONSchema4 = {
required: ['field'],
properties: {
field: true as any,
},
};

const result = constToEnum(schema);

expect(result.required).toEqual(['field']);
expect(result.properties?.field).toBe(true);
});
});
});
3 changes: 1 addition & 2 deletions test/prohibited-names.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fc from 'fast-check';
import { JSONSchema4 } from 'json-schema';
import { TypeGenerator } from '../src';

Expand Down Expand Up @@ -106,8 +107,6 @@ describe('prohibited member names', () => {
});


import * as fc from 'fast-check';

/**
* Property-based tests for prohibited name handling
* Feature: reserved-word-property-names
Expand Down