Skip to content

Commit 07357f6

Browse files
committed
change: rename templateDefaultOptions to getDataDefaultOptions
1 parent 2c4f679 commit 07357f6

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type CompileOptions = {
5757
// if format-validations should create errors. Defaults to true
5858
formatAssertion: boolean | "meta-schema";
5959
// default options for all calls to node.getData()
60-
templateDefaultOptions?: TemplateOptions;
60+
getDataDefaultOptions?: TemplateOptions;
6161
};
6262
```
6363

@@ -77,11 +77,11 @@ compileSchema(mySchema, { remote: anotherSchemaNode });
7777
compileSchema(mySchema, { formatAssertion: false });
7878

7979
// for all calls to getData, `addOptionalProps` is `true` per default
80-
compileSchema(mySchema, { templateDefaultOptions: { addOptionalProps: true } });
80+
compileSchema(mySchema, { getDataDefaultOptions: { addOptionalProps: true } });
8181
```
8282

8383
Details on _drafts_ are documented in [draft customization](#draft-customization).
84-
Details on `templateDefaultOptions` are documented in [getData](#getData).
84+
Details on `getDataDefaultOptions` are documented in [getData](#getData).
8585

8686
### SchemaNode
8787

@@ -1157,17 +1157,21 @@ The new implementation revolves around compiling schemas into a **SchemaNode** t
11571157
- `draft.addRemoteSchema(schema)``node.addRemote(schema)`
11581158
- `draft.createSchemaOf(schema)``node.createSchema(schema)`
11591159

1160+
- **Renamed Properties**:
1161+
1162+
- `templateDefaultOptions``getDataDefaultOptions`
1163+
11601164
- **Draft Customization**: Customizing drafts has changed completely. The previous methods of extending drafts are no longer valid, and draft handling is now centered around `SchemaNode`.
11611165

1162-
- **Remove Property**:
1166+
- **Removed Error Property `name`**:
11631167
Error property `name` has been removed from `JsonError` in favor of `code`.
11641168

11651169
- **Removed Configuration Option**:
11661170
The `templateDefaultOptions` property has been removed from the global settings object. You should now configure it using the `compileSchema` options:
11671171

11681172
```ts
11691173
compileSchema(schema, {
1170-
templateDefaultOptions: {
1174+
getDataDefaultOptions: {
11711175
addOptionalProps: false,
11721176
removeInvalidData: false,
11731177
extendDefaults: true

src/SchemaNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export type Context = {
6161
/** draft formats & validators */
6262
formats: Draft["formats"];
6363
/** [SHARED USING ADD REMOTE] getData default options */
64-
templateDefaultOptions?: TemplateOptions;
64+
getDataDefaultOptions?: TemplateOptions;
6565
};
6666

6767
export interface SchemaNode extends SchemaNodeMethodsType {
@@ -316,7 +316,7 @@ export const SchemaNodeMethods = {
316316
const node = this as SchemaNode;
317317
const opts = {
318318
recursionLimit: 1,
319-
...node.context.templateDefaultOptions,
319+
...node.context.getDataDefaultOptions,
320320
cache: {},
321321
...(options ?? {})
322322
};

src/compileSchema.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ describe("compileSchema vocabulary", () => {
5353
});
5454
});
5555

56-
describe("compileSchema templateDefaultOptions", () => {
57-
it("should apply `templateDefaultOptions.addOptionalProps` to getData", () => {
56+
describe("compileSchema getDataDefaultOptions", () => {
57+
it("should apply `getDataDefaultOptions.addOptionalProps` to getData", () => {
5858
const schema = {
5959
properties: {
6060
type: { const: "node" },
@@ -65,14 +65,14 @@ describe("compileSchema templateDefaultOptions", () => {
6565
let data = compileSchema(schema).getData();
6666
assert.deepEqual(data, {});
6767

68-
data = compileSchema(schema, { templateDefaultOptions: { addOptionalProps: true } }).getData();
68+
data = compileSchema(schema, { getDataDefaultOptions: { addOptionalProps: true } }).getData();
6969
assert.deepEqual(data, {
7070
type: "node",
7171
nodes: []
7272
});
7373
});
7474

75-
it("should apply `templateDefaultOptions.recursiveLimit` to getData", () => {
75+
it("should apply `getDataDefaultOptions.recursiveLimit` to getData", () => {
7676
const schema = {
7777
required: ["type", "nodes"],
7878
properties: {
@@ -92,7 +92,7 @@ describe("compileSchema templateDefaultOptions", () => {
9292
]
9393
});
9494

95-
data = compileSchema(schema, { templateDefaultOptions: { recursionLimit: 2 } }).getData();
95+
data = compileSchema(schema, { getDataDefaultOptions: { recursionLimit: 2 } }).getData();
9696
assert.deepEqual(data, {
9797
type: "node",
9898
nodes: [

src/compileSchema.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type CompileOptions = {
1414
drafts: Draft[];
1515
remote: SchemaNode;
1616
formatAssertion: boolean | "meta-schema";
17-
templateDefaultOptions?: TemplateOptions;
17+
getDataDefaultOptions?: TemplateOptions;
1818
};
1919

2020
const defaultDrafts: Draft[] = [draft04, draft06, draft07, draft2019, draft2020];
@@ -51,7 +51,7 @@ export function compileSchema(schema: JsonSchema, options: Partial<CompileOption
5151
anchors: {},
5252
refs: {},
5353
...copy(pick(draft, "methods", "keywords", "version", "formats", "errors")),
54-
templateDefaultOptions: options.templateDefaultOptions,
54+
getDataDefaultOptions: options.getDataDefaultOptions,
5555
drafts
5656
},
5757
...SchemaNodeMethods

src/draft2019-09/methods/getData.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ describe("getData (2019)", () => {
16691669
additionalProperties: false
16701670
},
16711671
{
1672-
templateDefaultOptions: { removeInvalidData: true }
1672+
getDataDefaultOptions: { removeInvalidData: true }
16731673
}
16741674
);
16751675
const res = node.getData({ valid: "stays", invalid: "removes" });
@@ -1683,7 +1683,7 @@ describe("getData (2019)", () => {
16831683
additionalProperties: false
16841684
},
16851685
{
1686-
templateDefaultOptions: { removeInvalidData: true }
1686+
getDataDefaultOptions: { removeInvalidData: true }
16871687
}
16881688
);
16891689
const res = node.getData({ valid: "stays", invalid: "not removed" }, { removeInvalidData: false });

src/methods/getData.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ describe("getData", () => {
15871587
additionalProperties: false
15881588
},
15891589
{
1590-
templateDefaultOptions: { removeInvalidData: true }
1590+
getDataDefaultOptions: { removeInvalidData: true }
15911591
}
15921592
);
15931593
const res = node.getData({ valid: "stays", invalid: "removes" });
@@ -1602,7 +1602,7 @@ describe("getData", () => {
16021602
additionalProperties: false
16031603
},
16041604
{
1605-
templateDefaultOptions: { removeInvalidData: true }
1605+
getDataDefaultOptions: { removeInvalidData: true }
16061606
}
16071607
);
16081608
const res = node.getData({ valid: "stays", invalid: "not removed" }, { removeInvalidData: false });

0 commit comments

Comments
 (0)