Skip to content

Commit a218512

Browse files
authored
update from draft6 to draft 7 (#1)
* update from draft6 to draft 7 * rename convert-schema-to-draft6
1 parent cc4fe38 commit a218512

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Combining inputs is useful if you have many unique forms and store each form's d
255255

256256
#### Compatibility modes
257257

258-
If you have previously used another JSON form creation library—Angular Schema Form (for AngularJS), React JSON Schema Form, or JSON Form (for jQuery)—in order to make the transition easier, Angular JSON Schema Form will recognize the input names and custom input objects used by those libraries. It should automatically work with JSON Schemas in [version 6](http://json-schema.org/draft-06/schema), [version 4](http://json-schema.org/draft-04/schema), [version 3](http://json-schema.org/draft-03/schema), or the [truncated version 3 format supported by JSON Form](https://github.com/joshfire/jsonform/wiki#schema-shortcut). So the following will all work:
258+
If you have previously used another JSON form creation library—Angular Schema Form (for AngularJS), React JSON Schema Form, or JSON Form (for jQuery)—in order to make the transition easier, Angular JSON Schema Form will recognize the input names and custom input objects used by those libraries. It should automatically work with JSON Schemas in [version 7](http://json-schema.org/draft-07/schema), [version 6](http://json-schema.org/draft-06/schema), [version 4](http://json-schema.org/draft-04/schema), [version 3](http://json-schema.org/draft-03/schema), or the [truncated version 3 format supported by JSON Form](https://github.com/joshfire/jsonform/wiki#schema-shortcut). So the following will all work:
259259

260260
Angular Schema Form (AngularJS) compatibility:
261261
```html

src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export {
1818
updateInputOptions, getTitleMapFromOneOf, getControlValidators,
1919
resolveSchemaReferences, getSubSchema, combineAllOf, fixRequiredArrayProperties
2020
} from './src/shared/json-schema.functions';
21-
export { convertSchemaToDraft6 } from './src/shared/convert-schema-to-draft6.function';
21+
export { convertSchemaToDraft7 } from './src/shared/convert-schema.function';
2222
export { mergeSchemas } from './src/shared/merge-schemas.function';
2323
export {
2424
buildFormGroupTemplate, buildFormGroup, formatFormData,

src/lib/src/json-schema-form.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as _ from 'lodash';
1010
import { FrameworkLibraryService } from './framework-library/framework-library.service';
1111
import { WidgetLibraryService } from './widget-library/widget-library.service';
1212
import { JsonSchemaFormService } from './json-schema-form.service';
13-
import { convertSchemaToDraft6 } from './shared/convert-schema-to-draft6.function';
13+
import { convertSchemaToDraft7 } from './shared/convert-schema.function';
1414
import { resolveSchemaReferences } from './shared/json-schema.functions';
1515
import {
1616
hasValue, inArray, isArray, isEmpty, isNumber, isObject
@@ -460,7 +460,7 @@ export class JsonSchemaFormComponent implements ControlValueAccessor, OnChanges,
460460

461461
// If needed, update JSON Schema to draft 6 format, including
462462
// draft 3 (JSON Form style) and draft 4 (Angular Schema Form style)
463-
this.jsf.schema = convertSchemaToDraft6(this.jsf.schema);
463+
this.jsf.schema = convertSchemaToDraft7(this.jsf.schema);
464464

465465
// Initialize ajv and compile schema
466466
this.jsf.compileAjvSchema();

src/lib/src/shared/convert-schema-to-draft6.function.ts renamed to src/lib/src/shared/convert-schema.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import * as _ from 'lodash';
22

33
/**
4-
* 'convertSchemaToDraft6' function
4+
* 'convertSchemaToDraft7' function
55
*
6-
* Converts a JSON Schema from draft 1 through 4 format to draft 6 format
6+
* Converts a JSON Schema from draft 1 through 4 format to draft 7 format
77
*
88
* Inspired by on geraintluff's JSON Schema 3 to 4 compatibility function:
99
* https://github.com/geraintluff/json-schema-compatibility
10-
* Also uses suggestions from AJV's JSON Schema 4 to 6 migration guide:
10+
* Also uses suggestions from AJV's JSON Schema 4 to 7 migration guide:
1111
* https://github.com/epoberezkin/ajv/releases/tag/5.0.0
1212
* And additional details from the official JSON Schema documentation:
1313
* http://json-schema.org
1414
*
15-
* @param { object } originalSchema - JSON schema (draft 1, 2, 3, 4, or 6)
15+
* @param { object } originalSchema - JSON schema (draft 1, 2, 3, 4, 6, or 7)
1616
* @param { OptionObject = {} } options - options: parent schema changed?, schema draft number?
17-
* @return { object } - JSON schema (draft 6)
17+
* @return { object } - JSON schema (draft 7)
1818
*/
1919
export interface OptionObject { changed?: boolean, draft?: number };
20-
export function convertSchemaToDraft6(schema, options: OptionObject = {}) {
20+
export function convertSchemaToDraft7(schema, options: OptionObject = {}) {
2121
let draft: number = options.draft || null;
2222
let changed: boolean = options.changed || false;
2323

2424
if (typeof schema !== 'object') { return schema; }
2525
if (typeof schema.map === 'function') {
26-
return [ ...schema.map(subSchema => convertSchemaToDraft6(subSchema, { changed, draft })) ];
26+
return [ ...schema.map(subSchema => convertSchemaToDraft7(subSchema, { changed, draft })) ];
2727
}
2828
let newSchema = { ...schema };
2929
const simpleTypes = ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'];
@@ -45,8 +45,8 @@ export function convertSchemaToDraft6(schema, options: OptionObject = {}) {
4545
// Convert v1-v3 'extends' to 'allOf'
4646
if (typeof newSchema.extends === 'object') {
4747
newSchema.allOf = typeof newSchema.extends.map === 'function' ?
48-
newSchema.extends.map(subSchema => convertSchemaToDraft6(subSchema, { changed, draft })) :
49-
[ convertSchemaToDraft6(newSchema.extends, { changed, draft }) ];
48+
newSchema.extends.map(subSchema => convertSchemaToDraft7(subSchema, { changed, draft })) :
49+
[ convertSchemaToDraft7(newSchema.extends, { changed, draft }) ];
5050
delete newSchema.extends;
5151
changed = true;
5252
}
@@ -204,7 +204,7 @@ export function convertSchemaToDraft6(schema, options: OptionObject = {}) {
204204
if (newSchema.id.slice(-1) === '#') {
205205
newSchema.id = newSchema.id.slice(0, -1);
206206
}
207-
newSchema.$id = newSchema.id + '-CONVERTED-TO-DRAFT-06#';
207+
newSchema.$id = newSchema.id + '-CONVERTED-TO-DRAFT-07#';
208208
delete newSchema.id;
209209
changed = true;
210210
}
@@ -221,10 +221,10 @@ export function convertSchemaToDraft6(schema, options: OptionObject = {}) {
221221
if (typeof newSchema.$schema === 'string' &&
222222
/http\:\/\/json\-schema\.org\/draft\-0[1-4]\/schema\#/.test(newSchema.$schema)
223223
) {
224-
newSchema.$schema = 'http://json-schema.org/draft-06/schema#';
224+
newSchema.$schema = 'http://json-schema.org/draft-07/schema#';
225225
changed = true;
226226
} else if (changed && typeof newSchema.$schema === 'string') {
227-
const addToDescription = 'Converted to draft 6 from ' + newSchema.$schema;
227+
const addToDescription = 'Converted to draft 7 from ' + newSchema.$schema;
228228
if (typeof newSchema.description === 'string' && newSchema.description.length) {
229229
newSchema.description += '\n' + addToDescription;
230230
} else {
@@ -304,14 +304,14 @@ export function convertSchemaToDraft6(schema, options: OptionObject = {}) {
304304
) {
305305
const newKey = {};
306306
Object.keys(newSchema[key]).forEach(subKey => newKey[subKey] =
307-
convertSchemaToDraft6(newSchema[key][subKey], { changed, draft })
307+
convertSchemaToDraft7(newSchema[key][subKey], { changed, draft })
308308
);
309309
newSchema[key] = newKey;
310310
} else if (
311311
[ 'items', 'additionalItems', 'additionalProperties',
312312
'allOf', 'anyOf', 'oneOf', 'not' ].includes(key)
313313
) {
314-
newSchema[key] = convertSchemaToDraft6(newSchema[key], { changed, draft });
314+
newSchema[key] = convertSchemaToDraft7(newSchema[key], { changed, draft });
315315
} else {
316316
newSchema[key] = _.cloneDeep(newSchema[key]);
317317
}

src/lib/src/shared/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export {
2626
resolveSchemaReferences, getSubSchema, combineAllOf, fixRequiredArrayProperties
2727
} from './json-schema.functions';
2828

29-
export { convertSchemaToDraft6 } from './convert-schema-to-draft6.function';
29+
export { convertSchemaToDraft7 } from './convert-schema.function';
3030

3131
export { mergeSchemas } from './merge-schemas.function';
3232

src/lib/src/shared/json-schema.functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function buildSchemaFromData(
9797
};
9898
const buildSubSchema = (value) =>
9999
buildSchemaFromData(value, requireAllFields, false);
100-
if (isRoot) { newSchema.$schema = 'http://json-schema.org/draft-06/schema#'; }
100+
if (isRoot) { newSchema.$schema = 'http://json-schema.org/draft-07/schema#'; }
101101
newSchema.type = getFieldType(data);
102102
if (newSchema.type === 'object') {
103103
newSchema.properties = {};

0 commit comments

Comments
 (0)