@redocly/openapi-core 1.0.0-beta.127 → 1.0.0-beta.129

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.js CHANGED
@@ -74,13 +74,27 @@ function bundleDocument(opts) {
74
74
  : remove_unused_components_2.RemoveUnusedComponents({}),
75
75
  });
76
76
  }
77
- const resolvedRefMap = yield resolve_1.resolveDocument({
77
+ let resolvedRefMap = yield resolve_1.resolveDocument({
78
78
  rootDocument: document,
79
79
  rootType: types.Root,
80
80
  externalRefResolver,
81
81
  });
82
+ if (preprocessors.length > 0) {
83
+ // Make additional pass to resolve refs defined in preprocessors.
84
+ walk_1.walkDocument({
85
+ document,
86
+ rootType: types.Root,
87
+ normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
88
+ resolvedRefMap,
89
+ ctx,
90
+ });
91
+ resolvedRefMap = yield resolve_1.resolveDocument({
92
+ rootDocument: document,
93
+ rootType: types.Root,
94
+ externalRefResolver,
95
+ });
96
+ }
82
97
  const bundleVisitor = visitors_1.normalizeVisitors([
83
- ...preprocessors,
84
98
  {
85
99
  severity: 'error',
86
100
  ruleId: 'bundler',
package/lib/config/all.js CHANGED
@@ -48,6 +48,7 @@ exports.default = {
48
48
  'no-invalid-schema-examples': 'error',
49
49
  'no-invalid-parameter-examples': 'error',
50
50
  'scalar-property-missing-example': 'error',
51
+ 'spec-strict-refs': 'error',
51
52
  },
52
53
  oas3_0Rules: {
53
54
  'no-invalid-media-type-examples': 'error',
@@ -75,6 +75,9 @@ function resolvePlugins(plugins, configPath = '') {
75
75
  : require(absoltePluginPath);
76
76
  }
77
77
  catch (e) {
78
+ if (e instanceof SyntaxError) {
79
+ throw e;
80
+ }
78
81
  throw new Error(`Failed to load plugin "${plugin}". Please provide a valid path`);
79
82
  }
80
83
  }
@@ -253,7 +256,10 @@ function groupStyleguideAssertionRules({ rules, plugins, }) {
253
256
  // Collect assertion rules
254
257
  const assertions = [];
255
258
  for (const [ruleKey, rule] of Object.entries(rules)) {
256
- if (ruleKey.startsWith('assert/') && typeof rule === 'object' && rule !== null) {
259
+ // keep the old assert/ syntax as an alias
260
+ if ((ruleKey.startsWith('rule/') || ruleKey.startsWith('assert/')) &&
261
+ typeof rule === 'object' &&
262
+ rule !== null) {
257
263
  const assertion = rule;
258
264
  if (plugins) {
259
265
  registerCustomAssertions(plugins, assertion);
@@ -262,7 +268,7 @@ function groupStyleguideAssertionRules({ rules, plugins, }) {
262
268
  registerCustomAssertions(plugins, context);
263
269
  }
264
270
  }
265
- assertions.push(Object.assign(Object.assign({}, assertion), { assertionId: ruleKey.replace('assert/', '') }));
271
+ assertions.push(Object.assign(Object.assign({}, assertion), { assertionId: ruleKey }));
266
272
  }
267
273
  else {
268
274
  // If it's not an assertion, keep it as is
@@ -1,7 +1,7 @@
1
1
  import { NormalizedProblem } from '../walk';
2
2
  import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
3
3
  import type { NodeType } from '../types';
4
- import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings, ThemeRawConfig } from './types';
4
+ import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings, Telemetry, ThemeRawConfig } from './types';
5
5
  export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
6
6
  export declare const DEFAULT_REGION = "us";
7
7
  export declare const DOMAINS: {
@@ -53,5 +53,6 @@ export declare class Config {
53
53
  theme: ThemeRawConfig;
54
54
  organization?: string;
55
55
  files: string[];
56
+ telemetry?: Telemetry;
56
57
  constructor(rawConfig: ResolvedConfig, configFile?: string | undefined);
57
58
  }
@@ -254,6 +254,7 @@ class Config {
254
254
  this.region = rawConfig.region;
255
255
  this.organization = rawConfig.organization;
256
256
  this.files = rawConfig.files || [];
257
+ this.telemetry = rawConfig.telemetry;
257
258
  }
258
259
  }
259
260
  exports.Config = Config;
@@ -31,6 +31,7 @@ exports.default = {
31
31
  'boolean-parameter-prefixes': 'off',
32
32
  'paths-kebab-case': 'off',
33
33
  spec: 'error',
34
+ 'spec-strict-refs': 'off',
34
35
  },
35
36
  oas3_0Rules: {
36
37
  'no-invalid-media-type-examples': {
@@ -31,6 +31,7 @@ exports.default = {
31
31
  'boolean-parameter-prefixes': 'off',
32
32
  'paths-kebab-case': 'off',
33
33
  spec: 'error',
34
+ 'spec-strict-refs': 'off',
34
35
  },
35
36
  oas3_0Rules: {
36
37
  'no-invalid-media-type-examples': {
@@ -2,7 +2,7 @@ import type { ProblemSeverity, UserContext } from '../walk';
2
2
  import type { Oas3PreprocessorsSet, OasMajorVersion, Oas3DecoratorsSet, Oas2RuleSet, Oas2PreprocessorsSet, Oas2DecoratorsSet, Oas3RuleSet, OasVersion } from '../oas-types';
3
3
  import type { NodeType } from '../types';
4
4
  import { Location } from '../ref-utils';
5
- import { SkipFunctionContext } from '../visitors';
5
+ import type { SkipFunctionContext } from '../visitors';
6
6
  export declare type RuleSeverity = ProblemSeverity | 'off';
7
7
  export declare type RuleSettings = {
8
8
  severity: RuleSeverity;
@@ -97,6 +97,7 @@ export declare type ResolveConfig = {
97
97
  http: HttpResolveConfig;
98
98
  };
99
99
  export declare type Region = 'us' | 'eu';
100
+ export declare type Telemetry = 'on' | 'off';
100
101
  export declare type AccessTokens = {
101
102
  [region in Region]?: string;
102
103
  };
@@ -125,6 +126,7 @@ export declare type RawConfig = {
125
126
  region?: Region;
126
127
  organization?: string;
127
128
  files?: string[];
129
+ telemetry?: Telemetry;
128
130
  } & ThemeConfig;
129
131
  export declare type FlatApi = Omit<Api, 'styleguide'> & Omit<ApiStyleguideRawConfig, 'doNotResolveExamples'>;
130
132
  export declare type FlatRawConfig = Omit<RawConfig, 'styleguide' | 'resolve' | 'apis'> & Omit<StyleguideRawConfig, 'doNotResolveExamples'> & {
@@ -147,4 +149,14 @@ export declare type ThemeRawConfig = {
147
149
  mockServer?: Record<string, any>;
148
150
  };
149
151
  export declare type RulesFields = 'rules' | 'oas2Rules' | 'oas3_0Rules' | 'oas3_1Rules' | 'preprocessors' | 'oas2Preprocessors' | 'oas3_0Preprocessors' | 'oas3_1Preprocessors' | 'decorators' | 'oas2Decorators' | 'oas3_0Decorators' | 'oas3_1Decorators';
152
+ export declare enum AuthProviderType {
153
+ OIDC = "OIDC",
154
+ SAML2 = "SAML2",
155
+ BASIC = "BASIC"
156
+ }
157
+ export declare enum ApigeeDevOnboardingIntegrationAuthType {
158
+ SERVICE_ACCOUNT = "SERVICE_ACCOUNT",
159
+ OAUTH2 = "OAUTH2"
160
+ }
161
+ export declare const DEFAULT_TEAM_CLAIM_NAME = "https://redocly.com/sso/teams";
150
162
  export {};
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TEAM_CLAIM_NAME = exports.ApigeeDevOnboardingIntegrationAuthType = exports.AuthProviderType = void 0;
4
+ var AuthProviderType;
5
+ (function (AuthProviderType) {
6
+ AuthProviderType["OIDC"] = "OIDC";
7
+ AuthProviderType["SAML2"] = "SAML2";
8
+ AuthProviderType["BASIC"] = "BASIC";
9
+ })(AuthProviderType = exports.AuthProviderType || (exports.AuthProviderType = {}));
10
+ var ApigeeDevOnboardingIntegrationAuthType;
11
+ (function (ApigeeDevOnboardingIntegrationAuthType) {
12
+ ApigeeDevOnboardingIntegrationAuthType["SERVICE_ACCOUNT"] = "SERVICE_ACCOUNT";
13
+ ApigeeDevOnboardingIntegrationAuthType["OAUTH2"] = "OAUTH2";
14
+ })(ApigeeDevOnboardingIntegrationAuthType = exports.ApigeeDevOnboardingIntegrationAuthType || (exports.ApigeeDevOnboardingIntegrationAuthType = {}));
15
+ exports.DEFAULT_TEAM_CLAIM_NAME = 'https://redocly.com/sso/teams';
@@ -191,12 +191,26 @@ function transformConfig(rawConfig) {
191
191
  }
192
192
  const { apis, apiDefinitions, referenceDocs, lint } = rawConfig, rest = __rest(rawConfig, ["apis", "apiDefinitions", "referenceDocs", "lint"]);
193
193
  const { styleguideConfig, rawConfigRest } = extractFlatConfig(rest);
194
- return Object.assign({ theme: {
194
+ const transformedConfig = Object.assign({ theme: {
195
195
  openapi: Object.assign(Object.assign(Object.assign({}, referenceDocs), rawConfig['features.openapi']), (_a = rawConfig.theme) === null || _a === void 0 ? void 0 : _a.openapi),
196
196
  mockServer: Object.assign(Object.assign({}, rawConfig['features.mockServer']), (_b = rawConfig.theme) === null || _b === void 0 ? void 0 : _b.mockServer),
197
197
  }, apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions), styleguide: styleguideConfig || lint }, rawConfigRest);
198
+ showDeprecationMessages(transformedConfig);
199
+ return transformedConfig;
198
200
  }
199
201
  exports.transformConfig = transformConfig;
202
+ function showDeprecationMessages(config) {
203
+ var _a, _b;
204
+ let allRules = Object.assign({}, (_a = config.styleguide) === null || _a === void 0 ? void 0 : _a.rules);
205
+ for (const api of Object.values(config.apis || {})) {
206
+ allRules = Object.assign(Object.assign({}, allRules), (_b = api === null || api === void 0 ? void 0 : api.styleguide) === null || _b === void 0 ? void 0 : _b.rules);
207
+ }
208
+ for (const ruleKey of Object.keys(allRules)) {
209
+ if (ruleKey.startsWith('assert/')) {
210
+ logger_1.logger.warn(`\nThe 'assert/' syntax in ${ruleKey} is deprecated. Update your configuration to use 'rule/' instead. Examples and more information: https://redocly.com/docs/cli/rules/configurable-rules/\n`);
211
+ }
212
+ }
213
+ }
200
214
  function getResolveConfig(resolve) {
201
215
  var _a, _b;
202
216
  return {
package/lib/lint.js CHANGED
@@ -57,12 +57,27 @@ function lintDocument(opts) {
57
57
  };
58
58
  const preprocessors = config_1.initRules(rules, config, 'preprocessors', oasVersion);
59
59
  const regularRules = config_1.initRules(rules, config, 'rules', oasVersion);
60
- const normalizedVisitors = visitors_1.normalizeVisitors([...preprocessors, ...regularRules], types);
61
- const resolvedRefMap = yield resolve_1.resolveDocument({
60
+ let resolvedRefMap = yield resolve_1.resolveDocument({
62
61
  rootDocument: document,
63
62
  rootType: types.Root,
64
63
  externalRefResolver,
65
64
  });
65
+ if (preprocessors.length > 0) {
66
+ // Make additional pass to resolve refs defined in preprocessors.
67
+ walk_1.walkDocument({
68
+ document,
69
+ rootType: types.Root,
70
+ normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
71
+ resolvedRefMap,
72
+ ctx,
73
+ });
74
+ resolvedRefMap = yield resolve_1.resolveDocument({
75
+ rootDocument: document,
76
+ rootType: types.Root,
77
+ externalRefResolver,
78
+ });
79
+ }
80
+ const normalizedVisitors = visitors_1.normalizeVisitors(regularRules, types);
66
81
  walk_1.walkDocument({
67
82
  document,
68
83
  rootType: types.Root,
@@ -11,12 +11,11 @@ const Assertions = (opts) => {
11
11
  // that is why we need to iterate through 'opts' values;
12
12
  // before - filter only object 'opts' values
13
13
  const assertions = Object.values(opts).filter((opt) => typeof opt === 'object' && opt !== null);
14
- for (const [index, assertion] of assertions.entries()) {
15
- const assertId = (assertion.assertionId && `${assertion.assertionId} assertion`) || `assertion #${index + 1}`;
14
+ for (const [_, assertion] of assertions.entries()) {
16
15
  if (!utils_2.isString(assertion.subject.type)) {
17
- throw new Error(`${assertId}: 'type' (String) is required`);
16
+ throw new Error(`${assertion.assertionId}: 'type' (String) is required`);
18
17
  }
19
- const subjectVisitor = utils_1.buildSubjectVisitor(assertId, assertion);
18
+ const subjectVisitor = utils_1.buildSubjectVisitor(assertion.assertionId, assertion);
20
19
  const visitorObject = utils_1.buildVisitorObject(assertion, subjectVisitor);
21
20
  visitors.push(visitorObject);
22
21
  }
@@ -0,0 +1,2 @@
1
+ import { Oas2Rule, Oas3Rule } from '../../visitors';
2
+ export declare const SpecStrictRefs: Oas3Rule | Oas2Rule;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecStrictRefs = void 0;
4
+ const ref_utils_1 = require("../../ref-utils");
5
+ const SpecStrictRefs = () => {
6
+ const nodesToSkip = [
7
+ 'Schema',
8
+ 'Response',
9
+ 'Parameter',
10
+ 'RequestBody',
11
+ 'Example',
12
+ 'Header',
13
+ 'SecurityScheme',
14
+ 'Link',
15
+ 'Callback',
16
+ 'PathItem',
17
+ ];
18
+ return {
19
+ any(_node, { report, rawNode, rawLocation, type }) {
20
+ const shouldCheck = !nodesToSkip.includes(type.name);
21
+ if (shouldCheck && ref_utils_1.isRef(rawNode)) {
22
+ report({
23
+ message: 'Field $ref is not expected here.',
24
+ location: rawLocation.child('$ref').key(),
25
+ });
26
+ }
27
+ },
28
+ };
29
+ };
30
+ exports.SpecStrictRefs = SpecStrictRefs;
@@ -42,5 +42,6 @@ export declare const rules: {
42
42
  'response-contains-property': Oas2Rule;
43
43
  'scalar-property-missing-example': import("../../visitors").Oas3Rule | Oas2Rule;
44
44
  'required-string-property-missing-min-length': import("../../visitors").Oas3Rule;
45
+ 'spec-strict-refs': import("../../visitors").Oas3Rule | Oas2Rule;
45
46
  };
46
47
  export declare const preprocessors: {};
@@ -42,6 +42,7 @@ const response_contains_header_1 = require("../common/response-contains-header")
42
42
  const response_contains_property_1 = require("./response-contains-property");
43
43
  const scalar_property_missing_example_1 = require("../common/scalar-property-missing-example");
44
44
  const required_string_property_missing_min_length_1 = require("../common/required-string-property-missing-min-length");
45
+ const spec_strict_refs_1 = require("../common/spec-strict-refs");
45
46
  exports.rules = {
46
47
  spec: spec_1.OasSpec,
47
48
  'no-invalid-schema-examples': no_invalid_schema_examples_1.NoInvalidSchemaExamples,
@@ -85,5 +86,6 @@ exports.rules = {
85
86
  'response-contains-property': response_contains_property_1.ResponseContainsProperty,
86
87
  'scalar-property-missing-example': scalar_property_missing_example_1.ScalarPropertyMissingExample,
87
88
  'required-string-property-missing-min-length': required_string_property_missing_min_length_1.RequiredStringPropertyMissingMinLength,
89
+ 'spec-strict-refs': spec_strict_refs_1.SpecStrictRefs,
88
90
  };
89
91
  exports.preprocessors = {};
@@ -52,6 +52,7 @@ const scalar_property_missing_example_1 = require("../common/scalar-property-mis
52
52
  const spec_components_invalid_map_name_1 = require("./spec-components-invalid-map-name");
53
53
  const operation_4xx_problem_details_rfc7807_1 = require("./operation-4xx-problem-details-rfc7807");
54
54
  const required_string_property_missing_min_length_1 = require("../common/required-string-property-missing-min-length");
55
+ const spec_strict_refs_1 = require("../common/spec-strict-refs");
55
56
  exports.rules = {
56
57
  spec: spec_1.OasSpec,
57
58
  'info-contact': info_contact_1.InfoContact,
@@ -105,5 +106,6 @@ exports.rules = {
105
106
  'scalar-property-missing-example': scalar_property_missing_example_1.ScalarPropertyMissingExample,
106
107
  'spec-components-invalid-map-name': spec_components_invalid_map_name_1.SpecComponentsInvalidMapName,
107
108
  'required-string-property-missing-min-length': required_string_property_missing_min_length_1.RequiredStringPropertyMissingMinLength,
109
+ 'spec-strict-refs': spec_strict_refs_1.SpecStrictRefs,
108
110
  };
109
111
  exports.preprocessors = {};
@@ -57,11 +57,6 @@ const SpecComponentsInvalidMapName = () => {
57
57
  validateKey(key, report, location, 'callbacks');
58
58
  },
59
59
  },
60
- ExampleMap: {
61
- Example(_node, { key, report, location }) {
62
- validateKey(key, report, location, 'examples');
63
- },
64
- },
65
60
  };
66
61
  };
67
62
  exports.SpecComponentsInvalidMapName = SpecComponentsInvalidMapName;