Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
JSONSchema: rename JsonSchema7Top to JsonSchema7Root, closes #634 (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Dec 7, 2023
1 parent b2f0287 commit 30802d5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-boats-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": minor
---

JSONSchema: rename `JsonSchema7Top` to `JsonSchema7Root`
28 changes: 14 additions & 14 deletions docs/modules/JSONSchema.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Added in v1.0.0
- [JsonSchema7Object (interface)](#jsonschema7object-interface)
- [JsonSchema7OneOf (interface)](#jsonschema7oneof-interface)
- [JsonSchema7Ref (interface)](#jsonschema7ref-interface)
- [JsonSchema7Root (type alias)](#jsonschema7root-type-alias)
- [JsonSchema7String (interface)](#jsonschema7string-interface)
- [JsonSchema7Top (type alias)](#jsonschema7top-type-alias)
- [JsonSchema7Unknown (interface)](#jsonschema7unknown-interface)
- [JsonSchema7empty (interface)](#jsonschema7empty-interface)
- [JsonSchema7object (interface)](#jsonschema7object-interface-1)
Expand All @@ -45,7 +45,7 @@ Added in v1.0.0
**Signature**

```ts
export declare const from: <I, A>(schema: Schema.Schema<I, A>) => JsonSchema7Top
export declare const from: <I, A>(schema: Schema.Schema<I, A>) => JsonSchema7Root
```
Added in v1.0.0
Expand All @@ -55,7 +55,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const to: <I, A>(schema: Schema.Schema<I, A>) => JsonSchema7Top
export declare const to: <I, A>(schema: Schema.Schema<I, A>) => JsonSchema7Root
```
Added in v1.0.0
Expand Down Expand Up @@ -259,30 +259,30 @@ export interface JsonSchema7Ref {

Added in v1.0.0

## JsonSchema7String (interface)
## JsonSchema7Root (type alias)

**Signature**

```ts
export interface JsonSchema7String {
type: "string"
minLength?: number
maxLength?: number
pattern?: string
description?: string
export type JsonSchema7Root = JsonSchema7 & {
$schema?: string
$defs?: Record<string, JsonSchema7>
}
```
Added in v1.0.0
## JsonSchema7Top (type alias)
## JsonSchema7String (interface)
**Signature**
```ts
export type JsonSchema7Top = JsonSchema7 & {
$schema?: string
$defs?: Record<string, JsonSchema7>
export interface JsonSchema7String {
type: "string"
minLength?: number
maxLength?: number
pattern?: string
description?: string
}
```

Expand Down
12 changes: 6 additions & 6 deletions src/JSONSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export type JsonSchema7 =
* @category model
* @since 1.0.0
*/
export type JsonSchema7Top = JsonSchema7 & {
export type JsonSchema7Root = JsonSchema7 & {
$schema?: string
$defs?: Record<string, JsonSchema7>
}
Expand All @@ -208,14 +208,14 @@ export type JsonSchema7Top = JsonSchema7 & {
* @category encoding
* @since 1.0.0
*/
export const to = <I, A>(schema: Schema.Schema<I, A>): JsonSchema7Top => goTop(AST.to(schema.ast))
export const to = <I, A>(schema: Schema.Schema<I, A>): JsonSchema7Root => goRoot(AST.to(schema.ast))

/**
* @category encoding
* @since 1.0.0
*/
export const from = <I, A>(schema: Schema.Schema<I, A>): JsonSchema7Top =>
goTop(AST.from(schema.ast))
export const from = <I, A>(schema: Schema.Schema<I, A>): JsonSchema7Root =>
goRoot(AST.from(schema.ast))

const anyJsonSchema: JsonSchema7 = { $id: "/schemas/any" }

Expand All @@ -240,10 +240,10 @@ const emptyJsonSchema: JsonSchema7 = {
const $schema = "http://json-schema.org/draft-07/schema#"

/** @internal */
export const goTop = (ast: AST.AST): JsonSchema7Top => {
export const goRoot = (ast: AST.AST): JsonSchema7Root => {
const $defs = {}
const jsonSchema = goWithMetaData(ast, $defs)
const out: JsonSchema7Top = {
const out: JsonSchema7Root = {
$schema,
...jsonSchema
}
Expand Down
8 changes: 4 additions & 4 deletions test/JSONSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ describe("JSONSchema", () => {
})

it("Transform should raise an error", () => {
expect(() => JSONSchema.goTop(Schema.NumberFromString.ast)).toThrow(
expect(() => JSONSchema.goRoot(Schema.NumberFromString.ast)).toThrow(
new Error("cannot build a JSON Schema for transformations")
)
})
Expand Down Expand Up @@ -1316,7 +1316,7 @@ describe("JSONSchema", () => {
})

describe("identifier annotations support", () => {
it("on top level schema", () => {
it("on root level schema", () => {
const schema = Schema.string.pipe(Schema.identifier("Name"))
const jsonSchema = JSONSchema.to(schema)
expect(jsonSchema).toEqual({
Expand Down Expand Up @@ -1375,14 +1375,14 @@ describe("JSONSchema", () => {
})
})

export const decode = <A>(schema: JSONSchema.JsonSchema7Top): Schema.Schema<A> =>
export const decode = <A>(schema: JSONSchema.JsonSchema7Root): Schema.Schema<A> =>
Schema.make(decodeAST(schema, schema.$defs))

const emptyTypeLiteralAST = AST.createTypeLiteral([], [])

const decodeAST = (
schema: JSONSchema.JsonSchema7,
$defs: JSONSchema.JsonSchema7Top["$defs"]
$defs: JSONSchema.JsonSchema7Root["$defs"]
): AST.AST => {
if ("$id" in schema) {
switch (schema.$id) {
Expand Down

0 comments on commit 30802d5

Please sign in to comment.