@redocly/openapi-core 1.0.0-beta.98 → 1.0.0-beta.99
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/lib/bundle.d.ts +2 -0
- package/lib/bundle.js +6 -3
- package/lib/config/all.js +1 -0
- package/lib/ref-utils.js +1 -0
- package/lib/rules/common/response-contains-header.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +41 -0
- package/lib/rules/oas2/index.d.ts +3 -0
- package/lib/rules/oas2/index.js +6 -0
- package/lib/rules/oas2/response-contains-property.d.ts +2 -0
- package/lib/rules/oas2/response-contains-property.js +38 -0
- package/lib/rules/oas3/index.js +6 -0
- package/lib/rules/oas3/response-contains-property.d.ts +2 -0
- package/lib/rules/oas3/response-contains-property.js +40 -0
- package/lib/types/oas3.js +17 -6
- package/lib/types/oas3_1.js +9 -7
- package/lib/types/redocly-yaml.js +10 -0
- package/lib/typings/openapi.d.ts +3 -2
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +3 -1
- package/package.json +1 -1
- package/{__tests__ → src/__tests__}/__snapshots__/bundle.test.ts.snap +26 -0
- package/{__tests__ → src/__tests__}/bundle.test.ts +30 -6
- package/{__tests__ → src/__tests__}/codeframes.test.ts +3 -3
- package/{__tests__ → src/__tests__}/fixtures/extension.js +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/definitions.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/examples.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/external-request-body.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/externalref.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/hosted.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/openapi-with-external-refs.yaml +0 -0
- package/src/__tests__/fixtures/refs/openapi-with-url-refs.yaml +18 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/param-b.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/param-c.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/rename.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/requestBody.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/schema-a.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/simple.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/vendor.schema.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/External.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/External2.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/description.md +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/externalInfo.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/externalLicense.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/openapi-with-back.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/openapi-with-md-description.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/openapi.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/schemas/type-a.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/schemas/type-b.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/transitive/a.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/transitive/components.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/transitive/schemas.yaml +0 -0
- package/src/__tests__/lint.test.ts +13 -0
- package/{__tests__ → src/__tests__}/login.test.ts +1 -1
- package/{__tests__ → src/__tests__}/normalizeVisitors.test.ts +4 -4
- package/{__tests__ → src/__tests__}/ref-utils.test.ts +5 -5
- package/{__tests__ → src/__tests__}/resolve-http.test.ts +4 -4
- package/{__tests__ → src/__tests__}/resolve.test.ts +4 -4
- package/src/__tests__/utils.test.ts +12 -1
- package/{__tests__ → src/__tests__}/walk.test.ts +5 -5
- package/src/bundle.ts +18 -3
- package/src/config/__tests__/config-resolvers.test.ts +1 -1
- package/src/config/all.ts +1 -0
- package/src/ref-utils.ts +1 -0
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +207 -0
- package/src/rules/common/response-contains-header.ts +30 -0
- package/src/rules/common/scalar-property-missing-example.ts +55 -0
- package/src/rules/oas2/__tests__/response-contains-header.test.ts +174 -0
- package/src/rules/oas2/__tests__/response-contains-property.test.ts +155 -0
- package/src/rules/oas2/index.ts +6 -0
- package/src/rules/oas2/response-contains-property.ts +36 -0
- package/src/rules/oas3/__tests__/response-contains-header.test.ts +273 -0
- package/src/rules/oas3/__tests__/response-contains-property.test.ts +403 -0
- package/src/rules/oas3/index.ts +6 -0
- package/src/rules/oas3/response-contains-property.ts +38 -0
- package/src/types/oas3.ts +15 -6
- package/src/types/oas3_1.ts +9 -7
- package/src/types/redocly-yaml.ts +10 -0
- package/src/typings/openapi.ts +2 -1
- package/src/utils.ts +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/__tests__/lint.test.ts +0 -17
package/lib/bundle.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare function bundle(opts: {
|
|
|
18
18
|
base?: string;
|
|
19
19
|
skipRedoclyRegistryRefs?: boolean;
|
|
20
20
|
removeUnusedComponents?: boolean;
|
|
21
|
+
keepUrlRefs?: boolean;
|
|
21
22
|
}): Promise<{
|
|
22
23
|
bundle: Document;
|
|
23
24
|
problems: import("./walk").NormalizedProblem[];
|
|
@@ -34,6 +35,7 @@ export declare function bundleDocument(opts: {
|
|
|
34
35
|
dereference?: boolean;
|
|
35
36
|
skipRedoclyRegistryRefs?: boolean;
|
|
36
37
|
removeUnusedComponents?: boolean;
|
|
38
|
+
keepUrlRefs?: boolean;
|
|
37
39
|
}): Promise<{
|
|
38
40
|
bundle: Document;
|
|
39
41
|
problems: import("./walk").NormalizedProblem[];
|
package/lib/bundle.js
CHANGED
|
@@ -48,7 +48,7 @@ function bundle(opts) {
|
|
|
48
48
|
exports.bundle = bundle;
|
|
49
49
|
function bundleDocument(opts) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const { document, config, customTypes, externalRefResolver, dereference = false, skipRedoclyRegistryRefs = false, removeUnusedComponents = false, } = opts;
|
|
51
|
+
const { document, config, customTypes, externalRefResolver, dereference = false, skipRedoclyRegistryRefs = false, removeUnusedComponents = false, keepUrlRefs = false, } = opts;
|
|
52
52
|
const oasVersion = oas_types_1.detectOpenAPI(document.parsed);
|
|
53
53
|
const oasMajorVersion = oas_types_1.openAPIMajor(oasVersion);
|
|
54
54
|
const rules = config.getRulesForOasVersion(oasMajorVersion);
|
|
@@ -84,7 +84,7 @@ function bundleDocument(opts) {
|
|
|
84
84
|
{
|
|
85
85
|
severity: 'error',
|
|
86
86
|
ruleId: 'bundler',
|
|
87
|
-
visitor: makeBundleVisitor(oasMajorVersion, dereference, skipRedoclyRegistryRefs, document, resolvedRefMap),
|
|
87
|
+
visitor: makeBundleVisitor(oasMajorVersion, dereference, skipRedoclyRegistryRefs, document, resolvedRefMap, keepUrlRefs),
|
|
88
88
|
},
|
|
89
89
|
...decorators,
|
|
90
90
|
], types);
|
|
@@ -146,7 +146,7 @@ function mapTypeToComponent(typeName, version) {
|
|
|
146
146
|
}
|
|
147
147
|
exports.mapTypeToComponent = mapTypeToComponent;
|
|
148
148
|
// function oas3Move
|
|
149
|
-
function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDocument, resolvedRefMap) {
|
|
149
|
+
function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDocument, resolvedRefMap, keepUrlRefs) {
|
|
150
150
|
let components;
|
|
151
151
|
const visitor = {
|
|
152
152
|
ref: {
|
|
@@ -165,6 +165,9 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
165
165
|
if (skipRedoclyRegistryRefs && redocly_1.isRedoclyRegistryURL(node.$ref)) {
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
|
+
if (keepUrlRefs && ref_utils_1.isAbsoluteUrl(node.$ref)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
168
171
|
const componentType = mapTypeToComponent(ctx.type.name, version);
|
|
169
172
|
if (!componentType) {
|
|
170
173
|
replaceRef(node, resolved, ctx);
|
package/lib/config/all.js
CHANGED
package/lib/ref-utils.js
CHANGED
|
@@ -67,6 +67,7 @@ function isMappingRef(mapping) {
|
|
|
67
67
|
// TODO: proper detection of mapping refs
|
|
68
68
|
return (mapping.startsWith('#') ||
|
|
69
69
|
mapping.startsWith('https://') ||
|
|
70
|
+
mapping.startsWith('http://') ||
|
|
70
71
|
mapping.startsWith('./') ||
|
|
71
72
|
mapping.startsWith('../') ||
|
|
72
73
|
mapping.indexOf('/') > -1);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseContainsHeader = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const ResponseContainsHeader = (options) => {
|
|
6
|
+
const names = options.names || {};
|
|
7
|
+
return {
|
|
8
|
+
Operation: {
|
|
9
|
+
Response: {
|
|
10
|
+
enter: (response, { report, location, key }) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const expectedHeaders = names[key] ||
|
|
13
|
+
names[utils_1.getMatchingStatusCodeRange(key)] ||
|
|
14
|
+
names[utils_1.getMatchingStatusCodeRange(key).toLowerCase()] ||
|
|
15
|
+
[];
|
|
16
|
+
for (const expectedHeader of expectedHeaders) {
|
|
17
|
+
if (!((_a = response.headers) === null || _a === void 0 ? void 0 : _a[expectedHeader])) {
|
|
18
|
+
report({
|
|
19
|
+
message: `Response object must contain a "${expectedHeader}" header.`,
|
|
20
|
+
location: location.child('headers').key(),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.ResponseContainsHeader = ResponseContainsHeader;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScalarPropertyMissingExample = void 0;
|
|
4
|
+
const oas_types_1 = require("../../oas-types");
|
|
5
|
+
const SCALAR_TYPES = ['string', 'integer', 'number', 'boolean', 'null'];
|
|
6
|
+
const ScalarPropertyMissingExample = () => {
|
|
7
|
+
return {
|
|
8
|
+
SchemaProperties(properties, { report, location, oasVersion, resolve }) {
|
|
9
|
+
for (const propName of Object.keys(properties)) {
|
|
10
|
+
const propSchema = resolve(properties[propName]).node;
|
|
11
|
+
if (!propSchema || !isScalarSchema(propSchema)) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (!propSchema.example && !propSchema.examples) {
|
|
15
|
+
report({
|
|
16
|
+
message: `Scalar property should have "example"${oasVersion === oas_types_1.OasVersion.Version3_1 ? ' or "examples"' : ''} defined.`,
|
|
17
|
+
location: location.child(propName).key(),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.ScalarPropertyMissingExample = ScalarPropertyMissingExample;
|
|
25
|
+
function isScalarSchema(schema) {
|
|
26
|
+
if (!schema.type) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (schema.allOf || schema.anyOf || schema.oneOf) {
|
|
30
|
+
// Skip allOf/oneOf/anyOf as it's complicated to validate it right now.
|
|
31
|
+
// We need core support for checking contrstrains through those keywords.
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (schema.format === 'binary') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(schema.type)) {
|
|
38
|
+
return schema.type.every((t) => SCALAR_TYPES.includes(t));
|
|
39
|
+
}
|
|
40
|
+
return SCALAR_TYPES.includes(schema.type);
|
|
41
|
+
}
|
|
@@ -39,5 +39,8 @@ export declare const rules: {
|
|
|
39
39
|
'request-mime-type': Oas2Rule;
|
|
40
40
|
'response-mime-type': Oas2Rule;
|
|
41
41
|
'path-segment-plural': Oas2Rule;
|
|
42
|
+
'response-contains-header': Oas2Rule;
|
|
43
|
+
'response-contains-property': Oas2Rule;
|
|
44
|
+
'scalar-property-missing-example': import("../../visitors").Oas3Rule | Oas2Rule;
|
|
42
45
|
};
|
|
43
46
|
export declare const preprocessors: {};
|
package/lib/rules/oas2/index.js
CHANGED
|
@@ -39,6 +39,9 @@ const path_excludes_patterns_1 = require("../common/path-excludes-patterns");
|
|
|
39
39
|
const request_mime_type_1 = require("./request-mime-type");
|
|
40
40
|
const response_mime_type_1 = require("./response-mime-type");
|
|
41
41
|
const path_segment_plural_1 = require("../common/path-segment-plural");
|
|
42
|
+
const response_contains_header_1 = require("../common/response-contains-header");
|
|
43
|
+
const response_contains_property_1 = require("./response-contains-property");
|
|
44
|
+
const scalar_property_missing_example_1 = require("../common/scalar-property-missing-example");
|
|
42
45
|
exports.rules = {
|
|
43
46
|
spec: spec_1.OasSpec,
|
|
44
47
|
'no-invalid-schema-examples': no_invalid_schema_examples_1.NoInvalidSchemaExamples,
|
|
@@ -79,5 +82,8 @@ exports.rules = {
|
|
|
79
82
|
'request-mime-type': request_mime_type_1.RequestMimeType,
|
|
80
83
|
'response-mime-type': response_mime_type_1.ResponseMimeType,
|
|
81
84
|
'path-segment-plural': path_segment_plural_1.PathSegmentPlural,
|
|
85
|
+
'response-contains-header': response_contains_header_1.ResponseContainsHeader,
|
|
86
|
+
'response-contains-property': response_contains_property_1.ResponseContainsProperty,
|
|
87
|
+
'scalar-property-missing-example': scalar_property_missing_example_1.ScalarPropertyMissingExample,
|
|
82
88
|
};
|
|
83
89
|
exports.preprocessors = {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseContainsProperty = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const ResponseContainsProperty = (options) => {
|
|
6
|
+
const names = options.names || {};
|
|
7
|
+
let key;
|
|
8
|
+
return {
|
|
9
|
+
Operation: {
|
|
10
|
+
Response: {
|
|
11
|
+
skip: (_response, key) => {
|
|
12
|
+
return `${key}` === '204';
|
|
13
|
+
},
|
|
14
|
+
enter: (_response, ctx) => {
|
|
15
|
+
key = ctx.key;
|
|
16
|
+
},
|
|
17
|
+
Schema(schema, { report, location }) {
|
|
18
|
+
var _a;
|
|
19
|
+
if (schema.type !== 'object')
|
|
20
|
+
return;
|
|
21
|
+
const expectedProperties = names[key] ||
|
|
22
|
+
names[utils_1.getMatchingStatusCodeRange(key)] ||
|
|
23
|
+
names[utils_1.getMatchingStatusCodeRange(key).toLowerCase()] ||
|
|
24
|
+
[];
|
|
25
|
+
for (const expectedProperty of expectedProperties) {
|
|
26
|
+
if (!((_a = schema.properties) === null || _a === void 0 ? void 0 : _a[expectedProperty])) {
|
|
27
|
+
report({
|
|
28
|
+
message: `Response object must contain a top-level "${expectedProperty}" property.`,
|
|
29
|
+
location: location.child('properties').key(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.ResponseContainsProperty = ResponseContainsProperty;
|
package/lib/rules/oas3/index.js
CHANGED
|
@@ -47,6 +47,9 @@ const path_segment_plural_1 = require("../common/path-segment-plural");
|
|
|
47
47
|
const path_excludes_patterns_1 = require("../common/path-excludes-patterns");
|
|
48
48
|
const no_invalid_schema_examples_1 = require("../common/no-invalid-schema-examples");
|
|
49
49
|
const no_invalid_parameter_examples_1 = require("../common/no-invalid-parameter-examples");
|
|
50
|
+
const response_contains_header_1 = require("../common/response-contains-header");
|
|
51
|
+
const response_contains_property_1 = require("./response-contains-property");
|
|
52
|
+
const scalar_property_missing_example_1 = require("../common/scalar-property-missing-example");
|
|
50
53
|
exports.rules = {
|
|
51
54
|
spec: spec_1.OasSpec,
|
|
52
55
|
'info-description': info_description_1.InfoDescription,
|
|
@@ -95,5 +98,8 @@ exports.rules = {
|
|
|
95
98
|
'path-segment-plural': path_segment_plural_1.PathSegmentPlural,
|
|
96
99
|
'no-invalid-schema-examples': no_invalid_schema_examples_1.NoInvalidSchemaExamples,
|
|
97
100
|
'no-invalid-parameter-examples': no_invalid_parameter_examples_1.NoInvalidParameterExamples,
|
|
101
|
+
'response-contains-header': response_contains_header_1.ResponseContainsHeader,
|
|
102
|
+
'response-contains-property': response_contains_property_1.ResponseContainsProperty,
|
|
103
|
+
'scalar-property-missing-example': scalar_property_missing_example_1.ScalarPropertyMissingExample,
|
|
98
104
|
};
|
|
99
105
|
exports.preprocessors = {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseContainsProperty = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const ResponseContainsProperty = (options) => {
|
|
6
|
+
const names = options.names || {};
|
|
7
|
+
let key;
|
|
8
|
+
return {
|
|
9
|
+
Operation: {
|
|
10
|
+
Response: {
|
|
11
|
+
skip: (_response, key) => {
|
|
12
|
+
return `${key}` === '204';
|
|
13
|
+
},
|
|
14
|
+
enter: (_response, ctx) => {
|
|
15
|
+
key = ctx.key;
|
|
16
|
+
},
|
|
17
|
+
MediaType: {
|
|
18
|
+
Schema(schema, { report, location }) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (schema.type !== 'object')
|
|
21
|
+
return;
|
|
22
|
+
const expectedProperties = names[key] ||
|
|
23
|
+
names[utils_1.getMatchingStatusCodeRange(key)] ||
|
|
24
|
+
names[utils_1.getMatchingStatusCodeRange(key).toLowerCase()] ||
|
|
25
|
+
[];
|
|
26
|
+
for (const expectedProperty of expectedProperties) {
|
|
27
|
+
if (!((_a = schema.properties) === null || _a === void 0 ? void 0 : _a[expectedProperty])) {
|
|
28
|
+
report({
|
|
29
|
+
message: `Response object must contain a top-level "${expectedProperty}" property.`,
|
|
30
|
+
location: location.child('properties').key(),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.ResponseContainsProperty = ResponseContainsProperty;
|
package/lib/types/oas3.js
CHANGED
|
@@ -250,14 +250,14 @@ const Schema = {
|
|
|
250
250
|
minimum: { type: 'number' },
|
|
251
251
|
exclusiveMaximum: { type: 'boolean' },
|
|
252
252
|
exclusiveMinimum: { type: 'boolean' },
|
|
253
|
-
maxLength: { type: '
|
|
254
|
-
minLength: { type: '
|
|
253
|
+
maxLength: { type: 'integer', minimum: 0 },
|
|
254
|
+
minLength: { type: 'integer', minimum: 0 },
|
|
255
255
|
pattern: { type: 'string' },
|
|
256
|
-
maxItems: { type: '
|
|
257
|
-
minItems: { type: '
|
|
256
|
+
maxItems: { type: 'integer', minimum: 0 },
|
|
257
|
+
minItems: { type: 'integer', minimum: 0 },
|
|
258
258
|
uniqueItems: { type: 'boolean' },
|
|
259
|
-
maxProperties: { type: '
|
|
260
|
-
minProperties: { type: '
|
|
259
|
+
maxProperties: { type: 'integer', minimum: 0 },
|
|
260
|
+
minProperties: { type: 'integer', minimum: 0 },
|
|
261
261
|
required: { type: 'array', items: { type: 'string' } },
|
|
262
262
|
enum: { type: 'array' },
|
|
263
263
|
type: {
|
|
@@ -276,6 +276,17 @@ const Schema = {
|
|
|
276
276
|
return 'Schema';
|
|
277
277
|
}
|
|
278
278
|
},
|
|
279
|
+
additionalItems: (value) => {
|
|
280
|
+
if (typeof value === 'boolean') {
|
|
281
|
+
return { type: 'boolean' };
|
|
282
|
+
}
|
|
283
|
+
else if (Array.isArray(value)) {
|
|
284
|
+
return _1.listOf('Schema');
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
return 'Schema';
|
|
288
|
+
}
|
|
289
|
+
},
|
|
279
290
|
additionalProperties: (value) => {
|
|
280
291
|
if (typeof value === 'boolean') {
|
|
281
292
|
return { type: 'boolean' };
|
package/lib/types/oas3_1.js
CHANGED
|
@@ -87,19 +87,19 @@ const Schema = {
|
|
|
87
87
|
discriminator: 'Discriminator',
|
|
88
88
|
myArbitraryKeyword: { type: 'boolean' },
|
|
89
89
|
title: { type: 'string' },
|
|
90
|
-
multipleOf: { type: 'number' },
|
|
90
|
+
multipleOf: { type: 'number', minimum: 0 },
|
|
91
91
|
maximum: { type: 'number' },
|
|
92
92
|
minimum: { type: 'number' },
|
|
93
93
|
exclusiveMaximum: { type: 'number' },
|
|
94
94
|
exclusiveMinimum: { type: 'number' },
|
|
95
|
-
maxLength: { type: '
|
|
96
|
-
minLength: { type: '
|
|
95
|
+
maxLength: { type: 'integer', minimum: 0 },
|
|
96
|
+
minLength: { type: 'integer', minimum: 0 },
|
|
97
97
|
pattern: { type: 'string' },
|
|
98
|
-
maxItems: { type: '
|
|
99
|
-
minItems: { type: '
|
|
98
|
+
maxItems: { type: 'integer', minimum: 0 },
|
|
99
|
+
minItems: { type: 'integer', minimum: 0 },
|
|
100
100
|
uniqueItems: { type: 'boolean' },
|
|
101
|
-
maxProperties: { type: '
|
|
102
|
-
minProperties: { type: '
|
|
101
|
+
maxProperties: { type: 'integer', minimum: 0 },
|
|
102
|
+
minProperties: { type: 'integer', minimum: 0 },
|
|
103
103
|
required: { type: 'array', items: { type: 'string' } },
|
|
104
104
|
enum: { type: 'array' },
|
|
105
105
|
type: (value) => {
|
|
@@ -125,6 +125,8 @@ const Schema = {
|
|
|
125
125
|
dependentSchemas: _1.listOf('Schema'),
|
|
126
126
|
prefixItems: _1.listOf('Schema'),
|
|
127
127
|
contains: 'Schema',
|
|
128
|
+
minContains: { type: 'integer', minimum: 0 },
|
|
129
|
+
maxContains: { type: 'integer', minimum: 0 },
|
|
128
130
|
patternProperties: { type: 'object' },
|
|
129
131
|
propertyNames: 'Schema',
|
|
130
132
|
unevaluatedItems: 'Schema',
|
|
@@ -311,6 +311,7 @@ const LinksConfig = {
|
|
|
311
311
|
color: { type: 'string' },
|
|
312
312
|
hover: { type: 'string' },
|
|
313
313
|
textDecoration: { type: 'string' },
|
|
314
|
+
hoverTextDecoration: { type: 'string' },
|
|
314
315
|
visited: { type: 'string' },
|
|
315
316
|
},
|
|
316
317
|
};
|
|
@@ -401,6 +402,9 @@ const ConfigReferenceDocs = {
|
|
|
401
402
|
disableSidebar: { type: 'boolean' },
|
|
402
403
|
downloadDefinitionUrl: { type: 'string' },
|
|
403
404
|
expandDefaultServerVariables: { type: 'boolean' },
|
|
405
|
+
enumSkipQuotes: { type: 'boolean' },
|
|
406
|
+
expandDefaultRequest: { type: 'boolean' },
|
|
407
|
+
expandDefaultResponse: { type: 'boolean' },
|
|
404
408
|
expandResponses: { type: 'string' },
|
|
405
409
|
expandSingleSchemaField: { type: 'boolean' },
|
|
406
410
|
generateCodeSamples: 'GenerateCodeSamples',
|
|
@@ -415,6 +419,8 @@ const ConfigReferenceDocs = {
|
|
|
415
419
|
hideSchemaTitles: { type: 'boolean' },
|
|
416
420
|
hideSingleRequestSampleTab: { type: 'boolean' },
|
|
417
421
|
hideTryItPanel: { type: 'boolean' },
|
|
422
|
+
hideFab: { type: 'boolean' },
|
|
423
|
+
hideOneOfDescription: { type: 'boolean' },
|
|
418
424
|
htmlTemplate: { type: 'string' },
|
|
419
425
|
jsonSampleExpandLevel: { type: 'string' },
|
|
420
426
|
labels: 'ConfigLabels',
|
|
@@ -435,6 +441,8 @@ const ConfigReferenceDocs = {
|
|
|
435
441
|
samplesTabsMaxCount: { type: 'number' },
|
|
436
442
|
schemaExpansionLevel: { type: 'string' },
|
|
437
443
|
schemaDefinitionsTagName: { type: 'string' },
|
|
444
|
+
minCharacterLengthToInitSearch: { type: 'number' },
|
|
445
|
+
maxResponseHeadersToShowInTryIt: { type: 'number' },
|
|
438
446
|
scrollYOffset: { type: 'string' },
|
|
439
447
|
searchAutoExpand: { type: 'boolean' },
|
|
440
448
|
searchFieldLevelBoost: { type: 'number' },
|
|
@@ -446,6 +454,8 @@ const ConfigReferenceDocs = {
|
|
|
446
454
|
showExtensions: { type: 'boolean' },
|
|
447
455
|
showNextButton: { type: 'boolean' },
|
|
448
456
|
showRightPanelToggle: { type: 'boolean' },
|
|
457
|
+
showWebhookVerb: { type: 'boolean' },
|
|
458
|
+
showObjectSchemaExamples: { type: 'boolean' },
|
|
449
459
|
sidebarLinks: 'ConfigSidebarLinks',
|
|
450
460
|
sideNavStyle: { type: 'string' },
|
|
451
461
|
simpleOneOfTypeLabel: { type: 'boolean' },
|
package/lib/typings/openapi.d.ts
CHANGED
|
@@ -147,9 +147,10 @@ export interface Oas3Schema {
|
|
|
147
147
|
xml?: Oas3Xml;
|
|
148
148
|
'x-tags'?: string[];
|
|
149
149
|
}
|
|
150
|
-
export
|
|
150
|
+
export declare type Oas3_1Schema = Oas3Schema & {
|
|
151
|
+
type?: string | string[];
|
|
151
152
|
examples?: any[];
|
|
152
|
-
}
|
|
153
|
+
};
|
|
153
154
|
export interface Oas3_1Definition extends Oas3Definition {
|
|
154
155
|
webhooks?: Oas3_1Webhooks;
|
|
155
156
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -38,3 +38,4 @@ export declare function isNotEmptyObject(obj: any): boolean;
|
|
|
38
38
|
export declare function isString(value: unknown): value is string;
|
|
39
39
|
export declare function isNotString<T>(value: string | T): value is T;
|
|
40
40
|
export declare function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>): void;
|
|
41
|
+
export declare const getMatchingStatusCodeRange: (code: number | string) => string;
|
package/lib/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
12
|
+
exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
13
13
|
const fs = require("fs");
|
|
14
14
|
const minimatch = require("minimatch");
|
|
15
15
|
const node_fetch_1 = require("node-fetch");
|
|
@@ -173,3 +173,5 @@ function assignExisting(target, obj) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
exports.assignExisting = assignExisting;
|
|
176
|
+
const getMatchingStatusCodeRange = (code) => `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
|
|
177
|
+
exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
|
package/package.json
CHANGED
|
@@ -100,6 +100,32 @@ components:
|
|
|
100
100
|
|
|
101
101
|
`;
|
|
102
102
|
|
|
103
|
+
exports[`bundle should not bundle url refs if used with keepUrlRefs 1`] = `
|
|
104
|
+
openapi: 3.0.0
|
|
105
|
+
paths:
|
|
106
|
+
/pet:
|
|
107
|
+
parameters:
|
|
108
|
+
- $ref: '#/components/parameters/path-param'
|
|
109
|
+
put:
|
|
110
|
+
parameters:
|
|
111
|
+
- $ref: https://someexternal.schema
|
|
112
|
+
- $ref: '#/components/parameters/param-b'
|
|
113
|
+
- name: test
|
|
114
|
+
get:
|
|
115
|
+
parameters:
|
|
116
|
+
- $ref: http://someexternal.schema
|
|
117
|
+
- $ref: '#/components/parameters/param-c'
|
|
118
|
+
components:
|
|
119
|
+
parameters:
|
|
120
|
+
path-param:
|
|
121
|
+
name: path_param
|
|
122
|
+
param-c:
|
|
123
|
+
name: param_c
|
|
124
|
+
param-b:
|
|
125
|
+
name: param_b
|
|
126
|
+
|
|
127
|
+
`;
|
|
128
|
+
|
|
103
129
|
exports[`bundle should not place referened schema inline when component in question is not of type "schemas" 1`] = `
|
|
104
130
|
openapi: 3.0.0
|
|
105
131
|
paths:
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import outdent from 'outdent';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
|
|
4
|
-
import { bundleDocument, bundle } from '../
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { BaseResolver } from '../src/resolve';
|
|
4
|
+
import { bundleDocument, bundle } from '../bundle';
|
|
5
|
+
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils';
|
|
6
|
+
import { LintConfig, Config, ResolvedConfig } from '../config';
|
|
7
|
+
import { BaseResolver } from '../resolve';
|
|
9
8
|
|
|
10
9
|
describe('bundle', () => {
|
|
11
10
|
expect.addSnapshotSerializer(yamlSerializer);
|
|
@@ -128,5 +127,30 @@ describe('bundle', () => {
|
|
|
128
127
|
}
|
|
129
128
|
);
|
|
130
129
|
expect(res.parsed).toMatchSnapshot();
|
|
131
|
-
})
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should not bundle url refs if used with keepUrlRefs', async () => {
|
|
133
|
+
const fetchMock = jest.fn(() =>
|
|
134
|
+
Promise.resolve({
|
|
135
|
+
ok: true,
|
|
136
|
+
text: () => 'External schema content',
|
|
137
|
+
headers: {
|
|
138
|
+
get: () => '',
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
const { bundle: res, problems } = await bundle({
|
|
143
|
+
config: new Config({} as ResolvedConfig),
|
|
144
|
+
externalRefResolver: new BaseResolver({
|
|
145
|
+
http: {
|
|
146
|
+
customFetch: fetchMock,
|
|
147
|
+
headers: [],
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
ref: path.join(__dirname, 'fixtures/refs/openapi-with-url-refs.yaml'),
|
|
151
|
+
keepUrlRefs: true,
|
|
152
|
+
});
|
|
153
|
+
expect(problems).toHaveLength(0);
|
|
154
|
+
expect(res.parsed).toMatchSnapshot();
|
|
155
|
+
});
|
|
132
156
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { outdent } from 'outdent';
|
|
2
2
|
|
|
3
|
-
import { getLineColLocation, getCodeframe } from '../
|
|
4
|
-
import { LocationObject } from '../
|
|
5
|
-
import { Source } from '../
|
|
3
|
+
import { getLineColLocation, getCodeframe } from '../format/codeframes';
|
|
4
|
+
import { LocationObject } from '../walk';
|
|
5
|
+
import { Source } from '../resolve';
|
|
6
6
|
|
|
7
7
|
describe('Location', () => {
|
|
8
8
|
it('should correctly calculate location for key', () => {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{__tests__ → src/__tests__}/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
openapi: 3.0.0
|
|
2
|
+
paths:
|
|
3
|
+
/pet:
|
|
4
|
+
parameters:
|
|
5
|
+
- $ref: '#/components/parameters/path-param'
|
|
6
|
+
put:
|
|
7
|
+
parameters:
|
|
8
|
+
- $ref: 'https://someexternal.schema'
|
|
9
|
+
- $ref: ./param-b.yaml
|
|
10
|
+
- name: test
|
|
11
|
+
get:
|
|
12
|
+
parameters:
|
|
13
|
+
- $ref: 'http://someexternal.schema'
|
|
14
|
+
- $ref: ./param-c.yaml
|
|
15
|
+
components:
|
|
16
|
+
parameters:
|
|
17
|
+
path-param:
|
|
18
|
+
name: path_param
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|