@speclynx/apidom-ns-json-schema-draft-6 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +8 -9
- package/src/elements/JSONSchema.cjs +124 -0
- package/src/elements/JSONSchema.mjs +121 -0
- package/src/elements/JSONSchema.ts +158 -0
- package/src/elements/LinkDescription.cjs +60 -0
- package/src/elements/LinkDescription.mjs +56 -0
- package/src/elements/LinkDescription.ts +100 -0
- package/src/index.cjs +46 -0
- package/src/index.mjs +14 -0
- package/src/index.ts +85 -0
- package/src/media-types.cjs +34 -0
- package/src/media-types.mjs +30 -0
- package/src/media-types.ts +40 -0
- package/src/namespace.cjs +24 -0
- package/src/namespace.mjs +19 -0
- package/src/namespace.ts +23 -0
- package/src/predicates.cjs +30 -0
- package/src/predicates.mjs +21 -0
- package/src/predicates.ts +25 -0
- package/src/refractor/index.cjs +76 -0
- package/src/refractor/index.mjs +67 -0
- package/src/refractor/index.ts +90 -0
- package/src/refractor/inspect.cjs +47 -0
- package/src/refractor/inspect.mjs +39 -0
- package/src/refractor/inspect.ts +51 -0
- package/src/refractor/plugins/replace-empty-element.cjs +218 -0
- package/src/refractor/plugins/replace-empty-element.mjs +212 -0
- package/src/refractor/plugins/replace-empty-element.ts +243 -0
- package/src/refractor/specification.cjs +29 -0
- package/src/refractor/specification.mjs +24 -0
- package/src/refractor/specification.ts +58 -0
- package/src/refractor/toolbox.cjs +26 -0
- package/src/refractor/toolbox.mjs +19 -0
- package/src/refractor/toolbox.ts +23 -0
- package/src/refractor/visitors/json-schema/ExamplesVisitor.cjs +15 -0
- package/src/refractor/visitors/json-schema/ExamplesVisitor.mjs +11 -0
- package/src/refractor/visitors/json-schema/ExamplesVisitor.ts +19 -0
- package/src/refractor/visitors/json-schema/ItemsVisitor.cjs +15 -0
- package/src/refractor/visitors/json-schema/ItemsVisitor.mjs +11 -0
- package/src/refractor/visitors/json-schema/ItemsVisitor.ts +21 -0
- package/src/refractor/visitors/json-schema/index.cjs +29 -0
- package/src/refractor/visitors/json-schema/index.mjs +24 -0
- package/src/refractor/visitors/json-schema/index.ts +38 -0
- package/src/refractor/visitors/json-schema/link-description/index.cjs +19 -0
- package/src/refractor/visitors/json-schema/link-description/index.mjs +14 -0
- package/src/refractor/visitors/json-schema/link-description/index.ts +23 -0
package/src/index.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractLinkDescription = exports.refractJSONSchema = exports.refract = exports.mediaTypes = exports.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceLikeElement = exports.isJSONReferenceElement = exports.isBooleanJSONSchemaElement = exports.default = exports.Visitor = exports.SpecificationVisitor = exports.PatternedFieldsVisitor = exports.ParentSchemaAwareVisitor = exports.MediaElement = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchemaDraft6MediaTypes = exports.JSONReferenceElement = exports.ItemsVisitor = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.AlternatingVisitor = void 0;
|
|
7
|
+
var _mediaTypes = _interopRequireWildcard(require("./media-types.cjs"));
|
|
8
|
+
exports.mediaTypes = _mediaTypes.default;
|
|
9
|
+
exports.JSONSchemaDraft6MediaTypes = _mediaTypes.JSONSchemaDraft6MediaTypes;
|
|
10
|
+
var _namespace = _interopRequireDefault(require("./namespace.cjs"));
|
|
11
|
+
exports.default = _namespace.default;
|
|
12
|
+
var _replaceEmptyElement = _interopRequireDefault(require("./refractor/plugins/replace-empty-element.cjs"));
|
|
13
|
+
exports.refractorPluginReplaceEmptyElement = _replaceEmptyElement.default;
|
|
14
|
+
var _index = _interopRequireWildcard(require("./refractor/index.cjs"));
|
|
15
|
+
exports.refract = _index.default;
|
|
16
|
+
exports.refractJSONSchema = _index.refractJSONSchema;
|
|
17
|
+
exports.refractLinkDescription = _index.refractLinkDescription;
|
|
18
|
+
var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
|
|
19
|
+
exports.specificationObj = _specification.default;
|
|
20
|
+
var _predicates = require("./predicates.cjs");
|
|
21
|
+
exports.isBooleanJSONSchemaElement = _predicates.isBooleanJSONSchemaElement;
|
|
22
|
+
exports.isJSONReferenceElement = _predicates.isJSONReferenceElement;
|
|
23
|
+
exports.isJSONSchemaElement = _predicates.isJSONSchemaElement;
|
|
24
|
+
exports.isLinkDescriptionElement = _predicates.isLinkDescriptionElement;
|
|
25
|
+
exports.isMediaElement = _predicates.isMediaElement;
|
|
26
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
27
|
+
exports.isJSONReferenceLikeElement = _apidomNsJsonSchemaDraft.isJSONReferenceLikeElement;
|
|
28
|
+
exports.SpecificationVisitor = _apidomNsJsonSchemaDraft.SpecificationVisitor;
|
|
29
|
+
exports.FallbackVisitor = _apidomNsJsonSchemaDraft.FallbackVisitor;
|
|
30
|
+
exports.FixedFieldsVisitor = _apidomNsJsonSchemaDraft.FixedFieldsVisitor;
|
|
31
|
+
exports.PatternedFieldsVisitor = _apidomNsJsonSchemaDraft.PatternedFieldsVisitor;
|
|
32
|
+
exports.MapVisitor = _apidomNsJsonSchemaDraft.MapVisitor;
|
|
33
|
+
exports.AlternatingVisitor = _apidomNsJsonSchemaDraft.AlternatingVisitor;
|
|
34
|
+
exports.ParentSchemaAwareVisitor = _apidomNsJsonSchemaDraft.ParentSchemaAwareVisitor;
|
|
35
|
+
exports.Visitor = _apidomNsJsonSchemaDraft.Visitor;
|
|
36
|
+
var _index2 = _interopRequireDefault(require("./refractor/visitors/json-schema/link-description/index.cjs"));
|
|
37
|
+
exports.LinkDescriptionVisitor = _index2.default;
|
|
38
|
+
var _index3 = _interopRequireDefault(require("./refractor/visitors/json-schema/index.cjs"));
|
|
39
|
+
exports.JSONSchemaVisitor = _index3.default;
|
|
40
|
+
var _ItemsVisitor = _interopRequireDefault(require("./refractor/visitors/json-schema/ItemsVisitor.cjs"));
|
|
41
|
+
exports.ItemsVisitor = _ItemsVisitor.default;
|
|
42
|
+
var _inspect = require("./refractor/inspect.cjs");
|
|
43
|
+
exports.JSONSchemaElement = _inspect.JSONSchemaElement;
|
|
44
|
+
exports.JSONReferenceElement = _inspect.JSONReferenceElement;
|
|
45
|
+
exports.MediaElement = _inspect.MediaElement;
|
|
46
|
+
exports.LinkDescriptionElement = _inspect.LinkDescriptionElement;
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { default as mediaTypes, JSONSchemaDraft6MediaTypes } from "./media-types.mjs";
|
|
2
|
+
export { default } from "./namespace.mjs";
|
|
3
|
+
export { default as refractorPluginReplaceEmptyElement } from "./refractor/plugins/replace-empty-element.mjs";
|
|
4
|
+
export { default as refract, refractJSONSchema, refractLinkDescription } from "./refractor/index.mjs";
|
|
5
|
+
export { default as specificationObj } from "./refractor/specification.mjs";
|
|
6
|
+
export { isBooleanJSONSchemaElement, isJSONReferenceElement, isJSONSchemaElement, isLinkDescriptionElement, isMediaElement } from "./predicates.mjs";
|
|
7
|
+
export { isJSONReferenceLikeElement, SpecificationVisitor, FallbackVisitor, FixedFieldsVisitor, PatternedFieldsVisitor, MapVisitor, AlternatingVisitor, ParentSchemaAwareVisitor, Visitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
8
|
+
export { default as LinkDescriptionVisitor } from "./refractor/visitors/json-schema/link-description/index.mjs";
|
|
9
|
+
export { default as JSONSchemaVisitor } from "./refractor/visitors/json-schema/index.mjs";
|
|
10
|
+
export { default as ItemsVisitor } from "./refractor/visitors/json-schema/ItemsVisitor.mjs";
|
|
11
|
+
/**
|
|
12
|
+
* JSON Schema Draft 6 specification elements.
|
|
13
|
+
*/
|
|
14
|
+
export { JSONSchemaElement, JSONReferenceElement, MediaElement, LinkDescriptionElement } from "./refractor/inspect.mjs";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export { default as mediaTypes, JSONSchemaDraft6MediaTypes } from './media-types.ts';
|
|
2
|
+
export type { Format } from './media-types.ts';
|
|
3
|
+
|
|
4
|
+
export { default } from './namespace.ts';
|
|
5
|
+
|
|
6
|
+
export { default as refractorPluginReplaceEmptyElement } from './refractor/plugins/replace-empty-element.ts';
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
default as refract,
|
|
10
|
+
refractJSONSchema,
|
|
11
|
+
refractLinkDescription,
|
|
12
|
+
} from './refractor/index.ts';
|
|
13
|
+
export type { RefractorOptions, RefractorPlugin } from './refractor/index.ts';
|
|
14
|
+
export type { Toolbox } from './refractor/toolbox.ts';
|
|
15
|
+
export { default as specificationObj } from './refractor/specification.ts';
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
isBooleanJSONSchemaElement,
|
|
19
|
+
isJSONReferenceElement,
|
|
20
|
+
isJSONSchemaElement,
|
|
21
|
+
isLinkDescriptionElement,
|
|
22
|
+
isMediaElement,
|
|
23
|
+
} from './predicates.ts';
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
isJSONReferenceLikeElement,
|
|
27
|
+
SpecificationVisitor,
|
|
28
|
+
FallbackVisitor,
|
|
29
|
+
FixedFieldsVisitor,
|
|
30
|
+
PatternedFieldsVisitor,
|
|
31
|
+
MapVisitor,
|
|
32
|
+
AlternatingVisitor,
|
|
33
|
+
ParentSchemaAwareVisitor,
|
|
34
|
+
Visitor,
|
|
35
|
+
} from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
36
|
+
export type {
|
|
37
|
+
SpecificationVisitorOptions,
|
|
38
|
+
FallbackVisitorOptions,
|
|
39
|
+
FixedFieldsVisitorOptions,
|
|
40
|
+
PatternedFieldsVisitorOptions,
|
|
41
|
+
MapVisitorOptions,
|
|
42
|
+
AlternatingVisitorOptions,
|
|
43
|
+
ParentSchemaAwareVisitorOptions,
|
|
44
|
+
VisitorOptions,
|
|
45
|
+
AllOfVisitor,
|
|
46
|
+
AllOfVisitorOptions,
|
|
47
|
+
AnyOfVisitor,
|
|
48
|
+
AnyOfVisitorOptions,
|
|
49
|
+
DefinitionsVisitor,
|
|
50
|
+
DefinitionsVisitorOptions,
|
|
51
|
+
DependenciesVisitor,
|
|
52
|
+
DependenciesVisitorOptions,
|
|
53
|
+
OneOfVisitor,
|
|
54
|
+
OneOfVisitorOptions,
|
|
55
|
+
PatternPropertiesVisitor,
|
|
56
|
+
PatternPropertiesVisitorOptions,
|
|
57
|
+
PropertiesVisitor,
|
|
58
|
+
PropertiesVisitorOptions,
|
|
59
|
+
SchemaOrReferenceVisitor,
|
|
60
|
+
SchemaOrReferenceVisitorOptions,
|
|
61
|
+
SpecPath,
|
|
62
|
+
ItemsVisitor as JSONSchemaDraft4ItemsVisitor,
|
|
63
|
+
} from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
64
|
+
|
|
65
|
+
export { default as LinkDescriptionVisitor } from './refractor/visitors/json-schema/link-description/index.ts';
|
|
66
|
+
export type { LinkDescriptionVisitorOptions } from './refractor/visitors/json-schema/link-description/index.ts';
|
|
67
|
+
export { default as JSONSchemaVisitor } from './refractor/visitors/json-schema/index.ts';
|
|
68
|
+
export type { JSONSchemaVisitorOptions } from './refractor/visitors/json-schema/index.ts';
|
|
69
|
+
export type {
|
|
70
|
+
default as ExamplesVisitor,
|
|
71
|
+
ExamplesVisitorOptions,
|
|
72
|
+
} from './refractor/visitors/json-schema/ExamplesVisitor.ts';
|
|
73
|
+
export { default as ItemsVisitor } from './refractor/visitors/json-schema/ItemsVisitor.ts';
|
|
74
|
+
export type { ItemsVisitorOptions } from './refractor/visitors/json-schema/ItemsVisitor.ts';
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* JSON Schema Draft 6 specification elements.
|
|
78
|
+
*/
|
|
79
|
+
export {
|
|
80
|
+
JSONSchemaElement,
|
|
81
|
+
JSONReferenceElement,
|
|
82
|
+
MediaElement,
|
|
83
|
+
LinkDescriptionElement,
|
|
84
|
+
} from './refractor/inspect.ts';
|
|
85
|
+
export type { FixedField } from './refractor/inspect.ts';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = exports.JSONSchemaDraft6MediaTypes = void 0;
|
|
5
|
+
var _ramda = require("ramda");
|
|
6
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
class JSONSchemaDraft6MediaTypes extends _apidomCore.MediaTypes {
|
|
15
|
+
filterByFormat(format = 'generic') {
|
|
16
|
+
const effectiveFormat = format === 'generic' ? 'schema;version' : format;
|
|
17
|
+
return this.filter(mediaType => mediaType.includes(effectiveFormat));
|
|
18
|
+
}
|
|
19
|
+
findBy(version = 'draft-06', format = 'generic') {
|
|
20
|
+
const search = format === 'generic' ? `schema;version=${version}` : `schema+${format};version=${version}`;
|
|
21
|
+
const found = this.find(mediaType => mediaType.includes(search));
|
|
22
|
+
return found || this.unknownMediaType;
|
|
23
|
+
}
|
|
24
|
+
latest(format = 'generic') {
|
|
25
|
+
return (0, _ramda.last)(this.filterByFormat(format));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
exports.JSONSchemaDraft6MediaTypes = JSONSchemaDraft6MediaTypes;
|
|
33
|
+
const mediaTypes = new JSONSchemaDraft6MediaTypes('application/schema;version=draft-06', 'application/schema+json;version=draft-06', 'application/schema+yaml;version=draft-06');
|
|
34
|
+
var _default = exports.default = mediaTypes;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { last } from 'ramda';
|
|
2
|
+
import { MediaTypes } from '@speclynx/apidom-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export class JSONSchemaDraft6MediaTypes extends MediaTypes {
|
|
12
|
+
filterByFormat(format = 'generic') {
|
|
13
|
+
const effectiveFormat = format === 'generic' ? 'schema;version' : format;
|
|
14
|
+
return this.filter(mediaType => mediaType.includes(effectiveFormat));
|
|
15
|
+
}
|
|
16
|
+
findBy(version = 'draft-06', format = 'generic') {
|
|
17
|
+
const search = format === 'generic' ? `schema;version=${version}` : `schema+${format};version=${version}`;
|
|
18
|
+
const found = this.find(mediaType => mediaType.includes(search));
|
|
19
|
+
return found || this.unknownMediaType;
|
|
20
|
+
}
|
|
21
|
+
latest(format = 'generic') {
|
|
22
|
+
return last(this.filterByFormat(format));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
const mediaTypes = new JSONSchemaDraft6MediaTypes('application/schema;version=draft-06', 'application/schema+json;version=draft-06', 'application/schema+yaml;version=draft-06');
|
|
30
|
+
export default mediaTypes;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { last } from 'ramda';
|
|
2
|
+
import { MediaTypes } from '@speclynx/apidom-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type Format = 'generic' | 'json' | 'yaml';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export class JSONSchemaDraft6MediaTypes extends MediaTypes<string> {
|
|
13
|
+
filterByFormat(format: Format = 'generic') {
|
|
14
|
+
const effectiveFormat = format === 'generic' ? 'schema;version' : format;
|
|
15
|
+
return this.filter((mediaType) => mediaType.includes(effectiveFormat));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
findBy(version = 'draft-06', format: Format = 'generic') {
|
|
19
|
+
const search =
|
|
20
|
+
format === 'generic' ? `schema;version=${version}` : `schema+${format};version=${version}`;
|
|
21
|
+
const found = this.find((mediaType) => mediaType.includes(search));
|
|
22
|
+
|
|
23
|
+
return found || this.unknownMediaType;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
latest(format: Format = 'generic') {
|
|
27
|
+
return last(this.filterByFormat(format)) as string;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
const mediaTypes = new JSONSchemaDraft6MediaTypes(
|
|
35
|
+
'application/schema;version=draft-06',
|
|
36
|
+
'application/schema+json;version=draft-06',
|
|
37
|
+
'application/schema+yaml;version=draft-06',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export default mediaTypes;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
7
|
+
var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
|
|
8
|
+
var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
const jsonSchemaDraft6 = {
|
|
13
|
+
namespace: options => {
|
|
14
|
+
const {
|
|
15
|
+
base
|
|
16
|
+
} = options;
|
|
17
|
+
base.register('jSONSchemaDraft6', _JSONSchema.default);
|
|
18
|
+
base.register('jSONReference', _apidomNsJsonSchemaDraft.JSONReferenceElement);
|
|
19
|
+
base.register('media', _apidomNsJsonSchemaDraft.MediaElement);
|
|
20
|
+
base.register('linkDescription', _LinkDescription.default);
|
|
21
|
+
return base;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var _default = exports.default = jsonSchemaDraft6;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JSONReferenceElement, MediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
2
|
+
import JSONSchemaElement from "./elements/JSONSchema.mjs";
|
|
3
|
+
import LinkDescriptionElement from "./elements/LinkDescription.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
const jsonSchemaDraft6 = {
|
|
8
|
+
namespace: options => {
|
|
9
|
+
const {
|
|
10
|
+
base
|
|
11
|
+
} = options;
|
|
12
|
+
base.register('jSONSchemaDraft6', JSONSchemaElement);
|
|
13
|
+
base.register('jSONReference', JSONReferenceElement);
|
|
14
|
+
base.register('media', MediaElement);
|
|
15
|
+
base.register('linkDescription', LinkDescriptionElement);
|
|
16
|
+
return base;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export default jsonSchemaDraft6;
|
package/src/namespace.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NamespacePlugin } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { JSONReferenceElement, MediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
3
|
+
|
|
4
|
+
import JSONSchemaElement from './elements/JSONSchema.ts';
|
|
5
|
+
import LinkDescriptionElement from './elements/LinkDescription.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
const jsonSchemaDraft6: NamespacePlugin = {
|
|
11
|
+
namespace: (options) => {
|
|
12
|
+
const { base } = options;
|
|
13
|
+
|
|
14
|
+
base.register('jSONSchemaDraft6', JSONSchemaElement);
|
|
15
|
+
base.register('jSONReference', JSONReferenceElement);
|
|
16
|
+
base.register('media', MediaElement);
|
|
17
|
+
base.register('linkDescription', LinkDescriptionElement);
|
|
18
|
+
|
|
19
|
+
return base;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default jsonSchemaDraft6;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = exports.isBooleanJSONSchemaElement = void 0;
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
+
var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
|
|
8
|
+
var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
|
|
9
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
10
|
+
exports.isJSONReferenceElement = _apidomNsJsonSchemaDraft.isJSONReferenceElement;
|
|
11
|
+
exports.isMediaElement = _apidomNsJsonSchemaDraft.isMediaElement;
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
const isBooleanJSONSchemaElement = element => {
|
|
16
|
+
return (0, _apidomDatamodel.isBooleanElement)(element) && (0, _apidomDatamodel.includesClasses)(element, ['boolean-json-schema']);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
exports.isBooleanJSONSchemaElement = isBooleanJSONSchemaElement;
|
|
23
|
+
const isJSONSchemaElement = element => element instanceof _JSONSchema.default;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
exports.isJSONSchemaElement = isJSONSchemaElement;
|
|
29
|
+
const isLinkDescriptionElement = element => element instanceof _LinkDescription.default;
|
|
30
|
+
exports.isLinkDescriptionElement = isLinkDescriptionElement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isBooleanElement, includesClasses } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import JSONSchemaElement from "./elements/JSONSchema.mjs";
|
|
3
|
+
import LinkDescriptionElement from "./elements/LinkDescription.mjs";
|
|
4
|
+
export { isJSONReferenceElement, isMediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export const isBooleanJSONSchemaElement = element => {
|
|
10
|
+
return isBooleanElement(element) && includesClasses(element, ['boolean-json-schema']);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export const isJSONSchemaElement = element => element instanceof JSONSchemaElement;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export const isLinkDescriptionElement = element => element instanceof LinkDescriptionElement;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isBooleanElement, BooleanElement, includesClasses } from '@speclynx/apidom-datamodel';
|
|
2
|
+
|
|
3
|
+
import JSONSchemaElement from './elements/JSONSchema.ts';
|
|
4
|
+
import LinkDescriptionElement from './elements/LinkDescription.ts';
|
|
5
|
+
|
|
6
|
+
export { isJSONReferenceElement, isMediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export const isBooleanJSONSchemaElement = (element: unknown): element is BooleanElement => {
|
|
12
|
+
return isBooleanElement(element) && includesClasses(element, ['boolean-json-schema']);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export const isJSONSchemaElement = (element: unknown): element is JSONSchemaElement =>
|
|
19
|
+
element instanceof JSONSchemaElement;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const isLinkDescriptionElement = (element: unknown): element is LinkDescriptionElement =>
|
|
25
|
+
element instanceof LinkDescriptionElement;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.refractLinkDescription = exports.refractJSONSchema = exports.default = void 0;
|
|
6
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
8
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
9
|
+
var _ramda = require("ramda");
|
|
10
|
+
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
11
|
+
var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
const refract = (value, {
|
|
24
|
+
element = 'jSONSchemaDraft6',
|
|
25
|
+
plugins = [],
|
|
26
|
+
specificationObj = _specification.default,
|
|
27
|
+
consume = false
|
|
28
|
+
} = {}) => {
|
|
29
|
+
const genericElement = (0, _apidomDatamodel.refract)(value);
|
|
30
|
+
const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
|
|
31
|
+
const elementMap = resolvedSpec.elementMap;
|
|
32
|
+
const specPath = elementMap[element];
|
|
33
|
+
if (!specPath) {
|
|
34
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
39
|
+
* We don't allow consumers to hook into this translation.
|
|
40
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
41
|
+
*/
|
|
42
|
+
const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
|
|
43
|
+
const rootVisitor = new RootVisitorClass({
|
|
44
|
+
specObj: resolvedSpec,
|
|
45
|
+
consume
|
|
46
|
+
});
|
|
47
|
+
(0, _apidomTraverse.traverse)(genericElement, rootVisitor);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Running plugins visitors means extra single traversal === performance hit.
|
|
51
|
+
*/
|
|
52
|
+
return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
|
|
53
|
+
toolboxCreator: _toolbox.default
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Refracts a value into a JSONSchemaElement.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
const refractJSONSchema = (value, options = {}) => refract(value, {
|
|
62
|
+
...options,
|
|
63
|
+
element: 'jSONSchemaDraft6'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
exports.refractJSONSchema = refractJSONSchema;
|
|
71
|
+
const refractLinkDescription = (value, options = {}) => refract(value, {
|
|
72
|
+
...options,
|
|
73
|
+
element: 'linkDescription'
|
|
74
|
+
});
|
|
75
|
+
exports.refractLinkDescription = refractLinkDescription;
|
|
76
|
+
var _default = exports.default = refract;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
2
|
+
import { traverse } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { refract as baseRefract } from '@speclynx/apidom-datamodel';
|
|
4
|
+
import { path } from 'ramda';
|
|
5
|
+
import specification from "./specification.mjs";
|
|
6
|
+
import createToolbox from "./toolbox.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
const refract = (value, {
|
|
17
|
+
element = 'jSONSchemaDraft6',
|
|
18
|
+
plugins = [],
|
|
19
|
+
specificationObj = specification,
|
|
20
|
+
consume = false
|
|
21
|
+
} = {}) => {
|
|
22
|
+
const genericElement = baseRefract(value);
|
|
23
|
+
const resolvedSpec = resolveSpecification(specificationObj);
|
|
24
|
+
const elementMap = resolvedSpec.elementMap;
|
|
25
|
+
const specPath = elementMap[element];
|
|
26
|
+
if (!specPath) {
|
|
27
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
32
|
+
* We don't allow consumers to hook into this translation.
|
|
33
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
34
|
+
*/
|
|
35
|
+
const RootVisitorClass = path(specPath, resolvedSpec);
|
|
36
|
+
const rootVisitor = new RootVisitorClass({
|
|
37
|
+
specObj: resolvedSpec,
|
|
38
|
+
consume
|
|
39
|
+
});
|
|
40
|
+
traverse(genericElement, rootVisitor);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Running plugins visitors means extra single traversal === performance hit.
|
|
44
|
+
*/
|
|
45
|
+
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
|
|
46
|
+
toolboxCreator: createToolbox
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Refracts a value into a JSONSchemaElement.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export const refractJSONSchema = (value, options = {}) => refract(value, {
|
|
55
|
+
...options,
|
|
56
|
+
element: 'jSONSchemaDraft6'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export const refractLinkDescription = (value, options = {}) => refract(value, {
|
|
64
|
+
...options,
|
|
65
|
+
element: 'linkDescription'
|
|
66
|
+
});
|
|
67
|
+
export default refract;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
2
|
+
import { traverse } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { Element, refract as baseRefract } from '@speclynx/apidom-datamodel';
|
|
4
|
+
import { path } from 'ramda';
|
|
5
|
+
import { Visitor as VisitorClass } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
6
|
+
|
|
7
|
+
import specification from './specification.ts';
|
|
8
|
+
import createToolbox, { type Toolbox } from './toolbox.ts';
|
|
9
|
+
import type JSONSchemaElement from '../elements/JSONSchema.ts';
|
|
10
|
+
import type LinkDescriptionElement from '../elements/LinkDescription.ts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export type RefractorPlugin = (toolbox: Toolbox) => {
|
|
16
|
+
visitor?: object;
|
|
17
|
+
pre?: () => void;
|
|
18
|
+
post?: () => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface RefractorOptions {
|
|
25
|
+
readonly element?: string;
|
|
26
|
+
readonly plugins?: RefractorPlugin[];
|
|
27
|
+
readonly specificationObj?: typeof specification;
|
|
28
|
+
readonly consume?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
const refract = <T extends Element>(
|
|
35
|
+
value: unknown,
|
|
36
|
+
{
|
|
37
|
+
element = 'jSONSchemaDraft6',
|
|
38
|
+
plugins = [],
|
|
39
|
+
specificationObj = specification,
|
|
40
|
+
consume = false,
|
|
41
|
+
}: RefractorOptions = {},
|
|
42
|
+
): T => {
|
|
43
|
+
const genericElement = baseRefract(value);
|
|
44
|
+
const resolvedSpec = resolveSpecification(specificationObj);
|
|
45
|
+
const elementMap = resolvedSpec.elementMap as Record<string, string[]>;
|
|
46
|
+
const specPath = elementMap[element];
|
|
47
|
+
|
|
48
|
+
if (!specPath) {
|
|
49
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
54
|
+
* We don't allow consumers to hook into this translation.
|
|
55
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
56
|
+
*/
|
|
57
|
+
const RootVisitorClass = path(specPath, resolvedSpec) as new (
|
|
58
|
+
options: Record<string, unknown>,
|
|
59
|
+
) => InstanceType<typeof VisitorClass>;
|
|
60
|
+
const rootVisitor = new RootVisitorClass({ specObj: resolvedSpec, consume });
|
|
61
|
+
|
|
62
|
+
traverse(genericElement, rootVisitor);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Running plugins visitors means extra single traversal === performance hit.
|
|
66
|
+
*/
|
|
67
|
+
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
|
|
68
|
+
toolboxCreator: createToolbox,
|
|
69
|
+
}) as T;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Refracts a value into a JSONSchemaElement.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export const refractJSONSchema = <T extends Element = JSONSchemaElement>(
|
|
77
|
+
value: unknown,
|
|
78
|
+
options: Omit<RefractorOptions, 'element'> = {},
|
|
79
|
+
): T => refract(value, { ...options, element: 'jSONSchemaDraft6' });
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export const refractLinkDescription = <T extends Element = LinkDescriptionElement>(
|
|
86
|
+
value: unknown,
|
|
87
|
+
options: Omit<RefractorOptions, 'element'> = {},
|
|
88
|
+
): T => refract(value, { ...options, element: 'linkDescription' });
|
|
89
|
+
|
|
90
|
+
export default refract;
|