@e22m4u/js-openapi 0.0.5 → 0.0.7

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.
Files changed (70) hide show
  1. package/README.md +226 -146
  2. package/dist/cjs/index.cjs +2025 -2092
  3. package/package.json +10 -8
  4. package/schema/openapi-3-1/dialect/base.js +21 -0
  5. package/schema/openapi-3-1/meta/base.js +76 -0
  6. package/schema/openapi-3-1/schema-base.js +32 -0
  7. package/schema/openapi-3-1/schema.js +1403 -0
  8. package/src/ajv.js +32 -0
  9. package/src/errors/index.d.ts +1 -1
  10. package/src/errors/index.js +1 -1
  11. package/src/errors/oa-document-object-validation-error.d.ts +6 -0
  12. package/src/errors/oa-document-object-validation-error.js +6 -0
  13. package/src/errors/oa-document-object-validation-error.spec.js +10 -0
  14. package/src/index.d.ts +1 -3
  15. package/src/index.js +1 -3
  16. package/src/json-pointer/resolve-json-pointer.js +1 -1
  17. package/src/json-pointer/unescape-json-pointer.d.ts +1 -2
  18. package/src/oa-document-builder.d.ts +302 -111
  19. package/src/oa-document-builder.js +208 -142
  20. package/src/oa-document-builder.spec.js +1411 -0
  21. package/src/oa-document-object/index.d.ts +1 -1
  22. package/src/oa-document-object/index.js +1 -1
  23. package/src/oa-document-object/validate-oa-document-object.d.ts +18 -0
  24. package/src/oa-document-object/validate-oa-document-object.js +53 -0
  25. package/src/oa-document-object/validate-oa-document-object.spec.js +122 -0
  26. package/src/{oa-document-scope.d.ts → oa-operation-group.d.ts} +7 -7
  27. package/src/{oa-document-scope.js → oa-operation-group.js} +101 -46
  28. package/src/oa-operation-group.spec.js +544 -0
  29. package/src/oa-reference-object/is-oa-reference-object.js +1 -1
  30. package/src/oa-reference-object/is-oa-reference-object.spec.js +1 -1
  31. package/src/oa-reference-object/oa-ref.js +7 -0
  32. package/src/oa-reference-object/resolve-oa-reference-object.js +1 -11
  33. package/src/oa-reference-object/resolve-oa-reference-object.spec.js +0 -10
  34. package/src/oa-specification.d.ts +55 -66
  35. package/src/oa-specification.js +11 -22
  36. package/src/data-type/index.d.ts +0 -1
  37. package/src/data-type/index.js +0 -1
  38. package/src/data-type/infer-openapi-data-type.d.ts +0 -30
  39. package/src/data-type/infer-openapi-data-type.js +0 -38
  40. package/src/data-validation/data-format-validator-map.d.ts +0 -13
  41. package/src/data-validation/data-format-validator-map.js +0 -36
  42. package/src/data-validation/data-format-validator-map.spec.js +0 -39
  43. package/src/data-validation/data-format-validators.d.ts +0 -84
  44. package/src/data-validation/data-format-validators.js +0 -217
  45. package/src/data-validation/index.d.ts +0 -3
  46. package/src/data-validation/index.js +0 -3
  47. package/src/data-validation/validate-data-with-openapi-schema.d.ts +0 -46
  48. package/src/data-validation/validate-data-with-openapi-schema.js +0 -1913
  49. package/src/data-validation/validate-data-with-openapi-schema.spec.js +0 -6953
  50. package/src/errors/oa-data-validation-error.d.ts +0 -6
  51. package/src/errors/oa-data-validation-error.js +0 -6
  52. package/src/errors/oa-data-validation-error.spec.js +0 -17
  53. package/src/oa-document-object/validate-shallow-oa-document.d.ts +0 -10
  54. package/src/oa-document-object/validate-shallow-oa-document.js +0 -209
  55. package/src/oa-document-object/validate-shallow-oa-document.spec.js +0 -362
  56. package/src/utils/count-unicode.d.ts +0 -11
  57. package/src/utils/count-unicode.js +0 -15
  58. package/src/utils/index.d.ts +0 -5
  59. package/src/utils/index.js +0 -5
  60. package/src/utils/join-path.d.ts +0 -6
  61. package/src/utils/join-path.js +0 -36
  62. package/src/utils/join-path.spec.js +0 -104
  63. package/src/utils/normalize-path.d.ts +0 -12
  64. package/src/utils/normalize-path.js +0 -22
  65. package/src/utils/normalize-path.spec.js +0 -56
  66. package/src/utils/to-pascal-case.d.ts +0 -6
  67. package/src/utils/to-pascal-case.js +0 -26
  68. package/src/utils/to-pascal-case.spec.js +0 -15
  69. package/src/utils/to-spaced-json.d.ts +0 -17
  70. package/src/utils/to-spaced-json.js +0 -27
@@ -1,6 +0,0 @@
1
- import {Errorf} from '@e22m4u/js-format';
2
-
3
- /**
4
- * Data validation error.
5
- */
6
- export class OADataValidationError extends Errorf {}
@@ -1,6 +0,0 @@
1
- import {Errorf} from '@e22m4u/js-format';
2
-
3
- /**
4
- * Data validation error.
5
- */
6
- export class OADataValidationError extends Errorf {}
@@ -1,17 +0,0 @@
1
- import {expect} from 'chai';
2
- import {InvalidArgumentError} from '@e22m4u/js-format';
3
- import {OADataValidationError} from './oa-data-validation-error.js';
4
-
5
- describe('OADataValidationError', function () {
6
- describe('constructor', function () {
7
- it('should interpolate an error message with given arguments', function () {
8
- const res = new OADataValidationError('message %v %s', 'str', 10);
9
- expect(res.message).to.be.eql('message "str" 10');
10
- });
11
-
12
- it('should not extend the InvalidArgumentError class', function () {
13
- const res = new OADataValidationError('message');
14
- expect(res).to.be.not.instanceOf(InvalidArgumentError);
15
- });
16
- });
17
- });
@@ -1,10 +0,0 @@
1
- import {OADocumentObject} from '../oa-specification.js';
2
-
3
- /**
4
- * Validate shallow OADocumentObject.
5
- *
6
- * @param documentObject
7
- */
8
- export declare function validateShallowOADocument(
9
- documentObject: OADocumentObject,
10
- ): void;
@@ -1,209 +0,0 @@
1
- import {InvalidArgumentError} from '@e22m4u/js-format';
2
-
3
- /**
4
- * Validate shallow OADocumentObject.
5
- *
6
- * @param {object} documentObject
7
- */
8
- export function validateShallowOADocument(documentObject) {
9
- if (
10
- !documentObject ||
11
- typeof documentObject !== 'object' ||
12
- Array.isArray(documentObject)
13
- ) {
14
- throw new InvalidArgumentError(
15
- 'OpenAPI Document Object must be an Object, but %v was given.',
16
- documentObject,
17
- );
18
- }
19
- // openapi
20
- if (!documentObject.openapi || typeof documentObject.openapi !== 'string') {
21
- throw new InvalidArgumentError(
22
- 'Property "openapi" must be a non-empty String, but %v was given.',
23
- documentObject.openapi,
24
- );
25
- }
26
- // info
27
- if (
28
- !documentObject.info ||
29
- typeof documentObject.info !== 'object' ||
30
- Array.isArray(documentObject.info)
31
- ) {
32
- throw new InvalidArgumentError(
33
- 'Property "info" must be an Object, but %v was given.',
34
- documentObject.info,
35
- );
36
- }
37
- // info.title
38
- if (
39
- !documentObject.info.title ||
40
- typeof documentObject.info.title !== 'string'
41
- ) {
42
- throw new InvalidArgumentError(
43
- 'Property "info.title" must be a non-empty String, but %v was given.',
44
- documentObject.info.title,
45
- );
46
- }
47
- // info.version
48
- if (
49
- !documentObject.info.version ||
50
- typeof documentObject.info.version !== 'string'
51
- ) {
52
- throw new InvalidArgumentError(
53
- 'Property "info.version" must be a non-empty String, but %v was given.',
54
- documentObject.info.version,
55
- );
56
- }
57
- // jsonSchemaDialect
58
- if (documentObject.jsonSchemaDialect !== undefined) {
59
- if (
60
- !documentObject.jsonSchemaDialect ||
61
- typeof documentObject.jsonSchemaDialect !== 'string'
62
- ) {
63
- throw new InvalidArgumentError(
64
- 'Property "jsonSchemaDialect" must be a non-empty String, ' +
65
- 'but %v was given.',
66
- documentObject.jsonSchemaDialect,
67
- );
68
- }
69
- }
70
- // servers
71
- if (documentObject.servers !== undefined) {
72
- if (!Array.isArray(documentObject.servers)) {
73
- throw new InvalidArgumentError(
74
- 'Property "servers" must be an Array, but %v was given.',
75
- documentObject.servers,
76
- );
77
- }
78
- // servers[n]
79
- documentObject.servers.forEach((serverObject, index) => {
80
- if (
81
- !serverObject ||
82
- typeof serverObject !== 'object' ||
83
- Array.isArray(serverObject)
84
- ) {
85
- throw new InvalidArgumentError(
86
- 'Element "servers[%d]" must be an Object, but %v was given.',
87
- index,
88
- serverObject,
89
- );
90
- }
91
- // servers[n].url
92
- if (!serverObject.url || typeof serverObject.url !== 'string') {
93
- throw new InvalidArgumentError(
94
- 'Property "servers[%d].url" must be a non-empty String, ' +
95
- 'but %v was given.',
96
- index,
97
- serverObject.url,
98
- );
99
- }
100
- });
101
- }
102
- // paths
103
- if (documentObject.paths !== undefined) {
104
- if (
105
- !documentObject.paths ||
106
- typeof documentObject.paths !== 'object' ||
107
- Array.isArray(documentObject.paths)
108
- ) {
109
- throw new InvalidArgumentError(
110
- 'Property "paths" must be an Object, but %v was given.',
111
- documentObject.paths,
112
- );
113
- }
114
- }
115
- // webhooks
116
- if (documentObject.webhooks !== undefined) {
117
- if (
118
- !documentObject.webhooks ||
119
- typeof documentObject.webhooks !== 'object' ||
120
- Array.isArray(documentObject.webhooks)
121
- ) {
122
- throw new InvalidArgumentError(
123
- 'Property "webhooks" must be an Object, but %v was given.',
124
- documentObject.webhooks,
125
- );
126
- }
127
- }
128
- // components
129
- if (documentObject.components !== undefined) {
130
- if (
131
- !documentObject.components ||
132
- typeof documentObject.components !== 'object' ||
133
- Array.isArray(documentObject.components)
134
- ) {
135
- throw new InvalidArgumentError(
136
- 'Property "components" must be an Object, but %v was given.',
137
- documentObject.components,
138
- );
139
- }
140
- }
141
- // security
142
- if (documentObject.security !== undefined) {
143
- if (!Array.isArray(documentObject.security)) {
144
- throw new InvalidArgumentError(
145
- 'Property "security" must be an Array, but %v was given.',
146
- documentObject.security,
147
- );
148
- }
149
- // security[n]
150
- documentObject.security.forEach((securityRequirementObject, index) => {
151
- if (
152
- !securityRequirementObject ||
153
- typeof securityRequirementObject !== 'object' ||
154
- Array.isArray(securityRequirementObject)
155
- ) {
156
- throw new InvalidArgumentError(
157
- 'Element "security[%d]" must be an Object, but %v was given.',
158
- index,
159
- securityRequirementObject,
160
- );
161
- }
162
- });
163
- }
164
- // tags
165
- if (documentObject.tags !== undefined) {
166
- if (!Array.isArray(documentObject.tags)) {
167
- throw new InvalidArgumentError(
168
- 'Property "tags" must be an Array, but %v was given.',
169
- documentObject.tags,
170
- );
171
- }
172
- // tags[n]
173
- documentObject.tags.forEach((tagObject, index) => {
174
- if (
175
- !tagObject ||
176
- typeof tagObject !== 'object' ||
177
- Array.isArray(tagObject)
178
- ) {
179
- throw new InvalidArgumentError(
180
- 'Element "tags[%d]" must be an Object, but %v was given.',
181
- index,
182
- tagObject,
183
- );
184
- }
185
- // tags[n].name
186
- if (!tagObject.name || typeof tagObject.name !== 'string') {
187
- throw new InvalidArgumentError(
188
- 'Property "tags[%d].name" must be a non-empty String, ' +
189
- 'but %v was given.',
190
- index,
191
- tagObject.name,
192
- );
193
- }
194
- });
195
- }
196
- // externalDocs
197
- if (documentObject.externalDocs !== undefined) {
198
- if (
199
- !documentObject.externalDocs ||
200
- typeof documentObject.externalDocs !== 'object' ||
201
- Array.isArray(documentObject.externalDocs)
202
- ) {
203
- throw new InvalidArgumentError(
204
- 'Property "externalDocs" must be an Object, but %v was given.',
205
- documentObject.externalDocs,
206
- );
207
- }
208
- }
209
- }
@@ -1,362 +0,0 @@
1
- import {expect} from 'chai';
2
- import {format} from '@e22m4u/js-format';
3
- import {OPENAPI_VERSION} from '../oa-specification.js';
4
- import {validateShallowOADocument} from './validate-shallow-oa-document.js';
5
-
6
- const MINIMAL_DOCUMENT = {
7
- openapi: OPENAPI_VERSION,
8
- info: {title: 'API Documentation', version: '0.0.1'},
9
- };
10
-
11
- describe('validateShallowOADocument', function () {
12
- it('should require the first parameter to be an Object', function () {
13
- const throwable = v => () => validateShallowOADocument(v);
14
- const error = s =>
15
- format('OpenAPI Document Object must be an Object, but %s was given.', s);
16
- expect(throwable('str')).to.throw(error('"str"'));
17
- expect(throwable('')).to.throw(error('""'));
18
- expect(throwable(10)).to.throw(error('10'));
19
- expect(throwable(0)).to.throw(error('0'));
20
- expect(throwable(true)).to.throw(error('true'));
21
- expect(throwable(false)).to.throw(error('false'));
22
- expect(throwable([])).to.throw(error('Array'));
23
- expect(throwable(undefined)).to.throw(error('undefined'));
24
- expect(throwable(null)).to.throw(error('null'));
25
- throwable(MINIMAL_DOCUMENT)();
26
- });
27
-
28
- it('should require the "openapi" property to be a non-empty String', function () {
29
- const throwable = v => () =>
30
- validateShallowOADocument({
31
- ...MINIMAL_DOCUMENT,
32
- openapi: v,
33
- });
34
- const error = s =>
35
- format(
36
- 'Property "openapi" must be a non-empty String, but %s was given.',
37
- s,
38
- );
39
- expect(throwable('')).to.throw(error('""'));
40
- expect(throwable(10)).to.throw(error('10'));
41
- expect(throwable(0)).to.throw(error('0'));
42
- expect(throwable(true)).to.throw(error('true'));
43
- expect(throwable(false)).to.throw(error('false'));
44
- expect(throwable([])).to.throw(error('Array'));
45
- expect(throwable({})).to.throw(error('Object'));
46
- expect(throwable(undefined)).to.throw(error('undefined'));
47
- expect(throwable(null)).to.throw(error('null'));
48
- throwable('3.1.0')();
49
- });
50
-
51
- it('should require the "info" property to be an Object', function () {
52
- const throwable = v => () =>
53
- validateShallowOADocument({
54
- openapi: OPENAPI_VERSION,
55
- info: v,
56
- });
57
- const error = s =>
58
- format('Property "info" must be an Object, but %s was given.', s);
59
- expect(throwable('str')).to.throw(error('"str"'));
60
- expect(throwable('')).to.throw(error('""'));
61
- expect(throwable(10)).to.throw(error('10'));
62
- expect(throwable(0)).to.throw(error('0'));
63
- expect(throwable(true)).to.throw(error('true'));
64
- expect(throwable(false)).to.throw(error('false'));
65
- expect(throwable([])).to.throw(error('Array'));
66
- expect(throwable(undefined)).to.throw(error('undefined'));
67
- expect(throwable(null)).to.throw(error('null'));
68
- throwable({title: 'API Documentation', version: '0.0.1'})();
69
- });
70
-
71
- it('should require the "info.title" property to be a non-empty String', function () {
72
- const throwable = v => () =>
73
- validateShallowOADocument({
74
- openapi: OPENAPI_VERSION,
75
- info: {
76
- title: v,
77
- version: '0.0.1',
78
- },
79
- });
80
- const error = s =>
81
- format(
82
- 'Property "info.title" must be a non-empty String, but %s was given.',
83
- s,
84
- );
85
- expect(throwable('')).to.throw(error('""'));
86
- expect(throwable(10)).to.throw(error('10'));
87
- expect(throwable(0)).to.throw(error('0'));
88
- expect(throwable(true)).to.throw(error('true'));
89
- expect(throwable(false)).to.throw(error('false'));
90
- expect(throwable([])).to.throw(error('Array'));
91
- expect(throwable({})).to.throw(error('Object'));
92
- expect(throwable(undefined)).to.throw(error('undefined'));
93
- expect(throwable(null)).to.throw(error('null'));
94
- throwable('API Documentation')();
95
- });
96
-
97
- it('should require the "jsonSchemaDialect" property to be a non-empty String', function () {
98
- const throwable = v => () =>
99
- validateShallowOADocument({
100
- ...MINIMAL_DOCUMENT,
101
- jsonSchemaDialect: v,
102
- });
103
- const error = s =>
104
- format(
105
- 'Property "jsonSchemaDialect" must be a non-empty String, but %s was given.',
106
- s,
107
- );
108
- expect(throwable('')).to.throw(error('""'));
109
- expect(throwable(10)).to.throw(error('10'));
110
- expect(throwable(0)).to.throw(error('0'));
111
- expect(throwable(true)).to.throw(error('true'));
112
- expect(throwable(false)).to.throw(error('false'));
113
- expect(throwable([])).to.throw(error('Array'));
114
- expect(throwable({})).to.throw(error('Object'));
115
- expect(throwable(null)).to.throw(error('null'));
116
- throwable('https://json-schema.org/draft/2020-12/schema')();
117
- throwable(undefined)();
118
- });
119
-
120
- it('should require the "servers" property to be an Array', function () {
121
- const throwable = v => () =>
122
- validateShallowOADocument({
123
- ...MINIMAL_DOCUMENT,
124
- servers: v,
125
- });
126
- const error = s =>
127
- format('Property "servers" must be an Array, but %s was given.', s);
128
- expect(throwable('str')).to.throw(error('"str"'));
129
- expect(throwable('')).to.throw(error('""'));
130
- expect(throwable(10)).to.throw(error('10'));
131
- expect(throwable(0)).to.throw(error('0'));
132
- expect(throwable(true)).to.throw(error('true'));
133
- expect(throwable(false)).to.throw(error('false'));
134
- expect(throwable({})).to.throw(error('Object'));
135
- expect(throwable(null)).to.throw(error('null'));
136
- throwable([{url: 'http://localhost'}])();
137
- throwable([])();
138
- });
139
-
140
- it('should require elements of the "servers" property to be an Object', function () {
141
- const throwable = v => () =>
142
- validateShallowOADocument({
143
- ...MINIMAL_DOCUMENT,
144
- servers: [v],
145
- });
146
- const error = s =>
147
- format('Element "servers[0]" must be an Object, but %s was given.', s);
148
- expect(throwable('str')).to.throw(error('"str"'));
149
- expect(throwable('')).to.throw(error('""'));
150
- expect(throwable(10)).to.throw(error('10'));
151
- expect(throwable(0)).to.throw(error('0'));
152
- expect(throwable(true)).to.throw(error('true'));
153
- expect(throwable(false)).to.throw(error('false'));
154
- expect(throwable([])).to.throw(error('Array'));
155
- expect(throwable(null)).to.throw(error('null'));
156
- throwable({url: 'http://localhost'})();
157
- });
158
-
159
- it('should require the "servers[n].url" property to be a non-empty String', function () {
160
- const throwable = v => () =>
161
- validateShallowOADocument({
162
- ...MINIMAL_DOCUMENT,
163
- servers: [{url: v}],
164
- });
165
- const error = s =>
166
- format(
167
- 'Property "servers[0].url" must be a non-empty String, ' +
168
- 'but %s was given.',
169
- s,
170
- );
171
- expect(throwable('')).to.throw(error('""'));
172
- expect(throwable(10)).to.throw(error('10'));
173
- expect(throwable(0)).to.throw(error('0'));
174
- expect(throwable(true)).to.throw(error('true'));
175
- expect(throwable(false)).to.throw(error('false'));
176
- expect(throwable([])).to.throw(error('Array'));
177
- expect(throwable({})).to.throw(error('Object'));
178
- expect(throwable(undefined)).to.throw(error('undefined'));
179
- expect(throwable(null)).to.throw(error('null'));
180
- throwable('http://localhost')();
181
- });
182
-
183
- it('should require the "paths" property to be an Object', function () {
184
- const throwable = v => () =>
185
- validateShallowOADocument({
186
- ...MINIMAL_DOCUMENT,
187
- paths: v,
188
- });
189
- const error = s =>
190
- format('Property "paths" must be an Object, but %s was given.', s);
191
- expect(throwable('str')).to.throw(error('"str"'));
192
- expect(throwable('')).to.throw(error('""'));
193
- expect(throwable(10)).to.throw(error('10'));
194
- expect(throwable(0)).to.throw(error('0'));
195
- expect(throwable(true)).to.throw(error('true'));
196
- expect(throwable(false)).to.throw(error('false'));
197
- expect(throwable([])).to.throw(error('Array'));
198
- expect(throwable(null)).to.throw(error('null'));
199
- throwable({})();
200
- });
201
-
202
- it('should require the "webhooks" property to be an Object', function () {
203
- const throwable = v => () =>
204
- validateShallowOADocument({
205
- ...MINIMAL_DOCUMENT,
206
- webhooks: v,
207
- });
208
- const error = s =>
209
- format('Property "webhooks" must be an Object, but %s was given.', s);
210
- expect(throwable('str')).to.throw(error('"str"'));
211
- expect(throwable('')).to.throw(error('""'));
212
- expect(throwable(10)).to.throw(error('10'));
213
- expect(throwable(0)).to.throw(error('0'));
214
- expect(throwable(true)).to.throw(error('true'));
215
- expect(throwable(false)).to.throw(error('false'));
216
- expect(throwable([])).to.throw(error('Array'));
217
- expect(throwable(null)).to.throw(error('null'));
218
- throwable({})();
219
- });
220
-
221
- it('should require the "components" property to be an Object', function () {
222
- const throwable = v => () =>
223
- validateShallowOADocument({
224
- ...MINIMAL_DOCUMENT,
225
- components: v,
226
- });
227
- const error = s =>
228
- format('Property "components" must be an Object, but %s was given.', s);
229
- expect(throwable('str')).to.throw(error('"str"'));
230
- expect(throwable('')).to.throw(error('""'));
231
- expect(throwable(10)).to.throw(error('10'));
232
- expect(throwable(0)).to.throw(error('0'));
233
- expect(throwable(true)).to.throw(error('true'));
234
- expect(throwable(false)).to.throw(error('false'));
235
- expect(throwable([])).to.throw(error('Array'));
236
- expect(throwable(null)).to.throw(error('null'));
237
- throwable({})();
238
- });
239
-
240
- it('should require the "security" property to be an Array', function () {
241
- const throwable = v => () =>
242
- validateShallowOADocument({
243
- ...MINIMAL_DOCUMENT,
244
- security: v,
245
- });
246
- const error = s =>
247
- format('Property "security" must be an Array, but %s was given.', s);
248
- expect(throwable('str')).to.throw(error('"str"'));
249
- expect(throwable('')).to.throw(error('""'));
250
- expect(throwable(10)).to.throw(error('10'));
251
- expect(throwable(0)).to.throw(error('0'));
252
- expect(throwable(true)).to.throw(error('true'));
253
- expect(throwable(false)).to.throw(error('false'));
254
- expect(throwable({})).to.throw(error('Object'));
255
- expect(throwable(null)).to.throw(error('null'));
256
- throwable([{}])();
257
- throwable([])();
258
- });
259
-
260
- it('should require elements of the "security" property to be an Object', function () {
261
- const throwable = v => () =>
262
- validateShallowOADocument({
263
- ...MINIMAL_DOCUMENT,
264
- security: [v],
265
- });
266
- const error = s =>
267
- format('Element "security[0]" must be an Object, but %s was given.', s);
268
- expect(throwable('str')).to.throw(error('"str"'));
269
- expect(throwable('')).to.throw(error('""'));
270
- expect(throwable(10)).to.throw(error('10'));
271
- expect(throwable(0)).to.throw(error('0'));
272
- expect(throwable(true)).to.throw(error('true'));
273
- expect(throwable(false)).to.throw(error('false'));
274
- expect(throwable([])).to.throw(error('Array'));
275
- expect(throwable(null)).to.throw(error('null'));
276
- throwable({apiKey: []})();
277
- throwable({})();
278
- });
279
-
280
- it('should require the "tags" property to be an Array', function () {
281
- const throwable = v => () =>
282
- validateShallowOADocument({
283
- ...MINIMAL_DOCUMENT,
284
- tags: v,
285
- });
286
- const error = s =>
287
- format('Property "tags" must be an Array, but %s was given.', s);
288
- expect(throwable('str')).to.throw(error('"str"'));
289
- expect(throwable('')).to.throw(error('""'));
290
- expect(throwable(10)).to.throw(error('10'));
291
- expect(throwable(0)).to.throw(error('0'));
292
- expect(throwable(true)).to.throw(error('true'));
293
- expect(throwable(false)).to.throw(error('false'));
294
- expect(throwable({})).to.throw(error('Object'));
295
- expect(throwable(null)).to.throw(error('null'));
296
- throwable([{name: 'tag'}])();
297
- throwable([])();
298
- });
299
-
300
- it('should require elements of the "tags" property to be an Object', function () {
301
- const throwable = v => () =>
302
- validateShallowOADocument({
303
- ...MINIMAL_DOCUMENT,
304
- tags: [v],
305
- });
306
- const error = s =>
307
- format('Element "tags[0]" must be an Object, but %s was given.', s);
308
- expect(throwable('str')).to.throw(error('"str"'));
309
- expect(throwable('')).to.throw(error('""'));
310
- expect(throwable(10)).to.throw(error('10'));
311
- expect(throwable(0)).to.throw(error('0'));
312
- expect(throwable(true)).to.throw(error('true'));
313
- expect(throwable(false)).to.throw(error('false'));
314
- expect(throwable([])).to.throw(error('Array'));
315
- expect(throwable(null)).to.throw(error('null'));
316
- throwable({name: 'tag'})();
317
- });
318
-
319
- it('should require the "tags[n].name" property to be a non-empty String', function () {
320
- const throwable = v => () =>
321
- validateShallowOADocument({
322
- ...MINIMAL_DOCUMENT,
323
- tags: [{name: v}],
324
- });
325
- const error = s =>
326
- format(
327
- 'Property "tags[0].name" must be a non-empty String, ' +
328
- 'but %s was given.',
329
- s,
330
- );
331
- expect(throwable('')).to.throw(error('""'));
332
- expect(throwable(10)).to.throw(error('10'));
333
- expect(throwable(0)).to.throw(error('0'));
334
- expect(throwable(true)).to.throw(error('true'));
335
- expect(throwable(false)).to.throw(error('false'));
336
- expect(throwable([])).to.throw(error('Array'));
337
- expect(throwable({})).to.throw(error('Object'));
338
- expect(throwable(undefined)).to.throw(error('undefined'));
339
- expect(throwable(null)).to.throw(error('null'));
340
- throwable('tag')();
341
- });
342
-
343
- it('should require the "externalDocs" property to be an Object', function () {
344
- const throwable = v => () =>
345
- validateShallowOADocument({
346
- ...MINIMAL_DOCUMENT,
347
- externalDocs: v,
348
- });
349
- const error = s =>
350
- format('Property "externalDocs" must be an Object, but %s was given.', s);
351
- expect(throwable('str')).to.throw(error('"str"'));
352
- expect(throwable('')).to.throw(error('""'));
353
- expect(throwable(10)).to.throw(error('10'));
354
- expect(throwable(0)).to.throw(error('0'));
355
- expect(throwable(true)).to.throw(error('true'));
356
- expect(throwable(false)).to.throw(error('false'));
357
- expect(throwable([])).to.throw(error('Array'));
358
- expect(throwable(null)).to.throw(error('null'));
359
- throwable({url: 'https://example.com'})();
360
- throwable(undefined)();
361
- });
362
- });
@@ -1,11 +0,0 @@
1
- /**
2
- * Count unicode.
3
- *
4
- * Подсчет длины строки выполняется с учетом символов, выходящих
5
- * за пределы BMP (Basic Multilingual Plane) например, эмодзи
6
- * или некоторые иероглифы в JS имеют `.length === 2`,
7
- * но должны считаться за один символ.
8
- *
9
- * @param data
10
- */
11
- export function countUnicode(data: string): number;
@@ -1,15 +0,0 @@
1
- /**
2
- * Count unicode.
3
- *
4
- * Подсчет длины строки выполняется с учетом символов, выходящих
5
- * за пределы BMP (Basic Multilingual Plane) например, эмодзи
6
- * или некоторые иероглифы в JS имеют `.length === 2`,
7
- * но должны считаться за один символ.
8
- *
9
- * @param {string} data
10
- * @returns {number}
11
- */
12
- export function countUnicode(data) {
13
- const matchedChars = String(data).match(/[\s\S]/gu);
14
- return Array.isArray(matchedChars) ? matchedChars.length : 0;
15
- }
@@ -1,5 +0,0 @@
1
- export * from './join-path.js';
2
- export * from './count-unicode.js';
3
- export * from './normalize-path.js';
4
- export * from './to-spaced-json.js';
5
- export * from './to-pascal-case.js';
@@ -1,5 +0,0 @@
1
- export * from './join-path.js';
2
- export * from './count-unicode.js';
3
- export * from './normalize-path.js';
4
- export * from './to-spaced-json.js';
5
- export * from './to-pascal-case.js';
@@ -1,6 +0,0 @@
1
- /**
2
- * Joins URL paths.
3
- *
4
- * @param segments
5
- */
6
- export declare function joinPath(...segments: (string | number)[]): string;