Skip to content

Commit 44e0b04

Browse files
authored
JSONSchema: add missing options for target JSON Schema version in make function, closes #5883 (#5885)
1 parent 64b4dc4 commit 44e0b04

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

.changeset/heavy-walls-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
feat(JSONSchema): add missing options for target JSON Schema version in make function, closes #5883

packages/effect/src/JSONSchema.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,34 @@ export type JsonSchema7Root = JsonSchema7 & {
246246
}
247247

248248
/**
249+
* Generates a JSON Schema from a schema.
250+
*
251+
* **Options**
252+
*
253+
* - `target`: The target JSON Schema version. Possible values are:
254+
* - `"jsonSchema7"`: JSON Schema draft-07 (default behavior).
255+
* - `"jsonSchema2019-09"`: JSON Schema draft-2019-09.
256+
* - `"jsonSchema2020-12"`: JSON Schema draft-2020-12.
257+
* - `"openApi3.1"`: OpenAPI 3.1.
258+
*
249259
* @category encoding
250260
* @since 3.10.0
251261
*/
252-
export const make = <A, I, R>(schema: Schema.Schema<A, I, R>): JsonSchema7Root => {
262+
export const make = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: {
263+
readonly target?: Target | undefined
264+
}): JsonSchema7Root => {
253265
const definitions: Record<string, any> = {}
266+
const target = options?.target ?? "jsonSchema7"
254267
const ast = AST.isTransformation(schema.ast) && isParseJsonTransformation(schema.ast.from)
255268
// Special case top level `parseJson` transformations
256269
? schema.ast.to
257270
: schema.ast
258271
const jsonSchema = fromAST(ast, {
259-
definitions
272+
definitions,
273+
target
260274
})
261275
const out: JsonSchema7Root = {
262-
$schema: getMetaSchemaUri("jsonSchema7"),
276+
$schema: getMetaSchemaUri(target),
263277
$defs: {},
264278
...jsonSchema
265279
}

0 commit comments

Comments
 (0)