-
-
Notifications
You must be signed in to change notification settings - Fork 546
JSONSchema.make does not have same behaviour as JSONSchema.to => erasing properties & not working for some Schema types #3283
Copy link
Copy link
Closed
Labels
Description
What version of Effect is running?
3.5.1
What steps can reproduce the bug?
Hello,
I am trying to use JSONSchema.make and I have 2 issues according to my expectations:
- Json schema properties erased:
const schema = Schema.Struct({
firstName: Schema.String.annotations({
title: 'First name',
}),
lastName: Schema.Trim.pipe(Schema.nonEmpty()),
description: Schema.Trim.pipe(Schema.nonEmpty()).annotations({
jsonSchema: { title: 'Description' },
}),
});
const jsonSchema = JSONSchema.make(schema);
console.log(jsonSchema);
The output is:
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
required: [ 'firstName', 'lastName', 'description' ],
properties: {
firstName: { type: 'string', description: 'a string', title: 'First name' }, // ✅ Great
lastName: { minLength: 1 }, // ❌ I would expect more information, see below in expected behaviour section
description: { title: 'Description' } // ❌ I would expect more information, see below in expected behaviour section
},
additionalProperties: false
}
- Json schema not working for some Schema types
What I do:
// a. Schema.NullishOf
const schema = Schema.Struct({
numberOfElements: Schema.NullishOr(Schema.Number),
});
const jsonSchema = JSONSchema.make(schema);
console.log(jsonSchema);
OR
// b. Schema.DateFromSelf
const schema = Schema.Struct({
startDate: Schema.DateFromSelf
});
const jsonSchema = JSONSchema.make(schema);
console.log(jsonSchema);
The output is:
// a. Schema.NullishOf
Missing annotation
at path: ["numberOfElements"]
details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation
schema (UndefinedKeyword): undefined
OR
// b. Schema.DateFromSelf
Missing annotation
at path: ["startDate"]
details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation
schema (Declaration): DateFromSelf
What is the expected behavior?
- Json schema properties erased:
According to the documentation here, here is the output I would expect:
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
required: [ 'firstName', 'lastName', 'description' ],
properties: {
firstName: { type: 'string', description: 'a string', title: 'First name' },
lastName: { **type: 'string'**, minLength: 1 },
description: { **type: 'string', title: 'Description'**, minLength: 1, }
},
additionalProperties: false
}
- Json schema not working for some Schema types
I would expect:
// a. Schema.NullishOf
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
required: [], // empty
properties: {
numberOfElements: { type: 'number' },
},
additionalProperties: false
}
// b. Schema.DateFromSelf
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
required: ['startDate'],
properties: {
startDate: { type: 'date' },
},
additionalProperties: false
}
What do you see instead?
// Already answered above
Additional information
I would like to know why:
- JSON schema properties are erased, whereas it was not the case before with
JSONSchema.to=> the previous behaviour would be very beneficial for my need - It is not working with some schema types
Thanks a lot for your time!
Reactions are currently unavailable