Repository navigation
fix(types): support fluent-json-schema #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,11 @@ interface DotenvOptions { | |
|
|
||
| type EnvSchema = typeof envSchema | ||
|
|
||
| type FluentSchema = { | ||
| isFluentSchema: boolean; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @salluexez, thanks for your PR. I'm happy to let you review your pr to add these tests if you'd like. |
||
| isFluentJSONSchema: boolean; | ||
| } | ||
|
|
||
| declare namespace envSchema { | ||
| export type { JSONSchemaType } | ||
|
|
||
|
|
@@ -25,7 +30,7 @@ declare namespace envSchema { | |
| } | ||
|
|
||
| export type EnvSchemaOpt<T = EnvSchemaData> = { | ||
| schema?: JSONSchemaType<T> | AnySchema; | ||
| schema?: JSONSchemaType<T> | AnySchema | FluentSchema; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| data?: [EnvSchemaData, ...EnvSchemaData[]] | EnvSchemaData; | ||
| env?: boolean; | ||
| dotenv?: boolean | DotenvOptions; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import envSchema, { | |||||||||||||||||
| default as envSchemaDefault, | ||||||||||||||||||
| } from '.' | ||||||||||||||||||
| import Ajv, { KeywordDefinition, JSONSchemaType } from 'ajv' | ||||||||||||||||||
| import S from 'fluent-json-schema' | ||||||||||||||||||
| import { Static, Type } from 'typebox' | ||||||||||||||||||
|
|
||||||||||||||||||
| interface EnvData { | ||||||||||||||||||
|
|
@@ -46,6 +47,11 @@ const optWithSchemaTypebox: EnvSchemaOpt = { | |||||||||||||||||
| } | ||||||||||||||||||
| expect(optWithSchemaTypebox).type.toBe<EnvSchemaOpt>() | ||||||||||||||||||
|
|
||||||||||||||||||
| const optWithFluentSchema: EnvSchemaOpt = { | ||||||||||||||||||
| schema: S.object().prop('PORT', S.number().default(3000).required()), | ||||||||||||||||||
| } | ||||||||||||||||||
| expect(optWithFluentSchema).type.toBe<EnvSchemaOpt>() | ||||||||||||||||||
|
Comment on lines
+50
to
+53
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| const optWithSchemaWithType: EnvSchemaOpt<EnvData> = { | ||||||||||||||||||
| schema: schemaWithType, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -113,5 +119,13 @@ expect(envSchemaWithType).type.toBe<EnvData>() | |||||||||||||||||
| const envSchemaTypebox = envSchema<SchemaTypebox>({ schema: schemaTypebox }) | ||||||||||||||||||
| expect(envSchemaTypebox).type.toBe<SchemaTypebox>() | ||||||||||||||||||
|
|
||||||||||||||||||
| const envSchemaFluent = envSchema<EnvData>({ | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||
| schema: S.object<EnvData>().prop( | ||||||||||||||||||
| 'PORT', | ||||||||||||||||||
| S.number().default(3000).required() | ||||||||||||||||||
| ), | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| }) | ||||||||||||||||||
| expect(envSchemaFluent).type.toBe<EnvData>() | ||||||||||||||||||
|
|
||||||||||||||||||
| expect(keywords.separator).type.toBe<KeywordDefinition>() | ||||||||||||||||||
| expect(envSchema.keywords.separator).type.toBe<KeywordDefinition>() | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fluent-json-schema's own README documentsisFluentSchemaas the public detection flag;isFluentJSONSchemais also set on everyBaseSchema<T>but is not the documented public contract. The two-field structural type is broader than what the upstream docs promise to set.isFluentSchema: booleanis a fluent schema per the upstream README, and the second field does not add coverage the documented contract guarantees.