@redocly/openapi-core 1.15.0 → 1.17.0

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 (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/bundle.d.ts +1 -1
  3. package/lib/bundle.js +2 -2
  4. package/lib/config/config.d.ts +0 -6
  5. package/lib/config/config.js +1 -19
  6. package/lib/config/load.d.ts +12 -3
  7. package/lib/config/load.js +34 -14
  8. package/lib/config/utils.d.ts +1 -0
  9. package/lib/config/utils.js +5 -1
  10. package/lib/decorators/common/registry-dependencies.js +2 -2
  11. package/lib/index.d.ts +3 -2
  12. package/lib/index.js +17 -2
  13. package/lib/lint.d.ts +1 -0
  14. package/lib/lint.js +3 -7
  15. package/lib/oas-types.d.ts +1 -1
  16. package/lib/redocly/domains.d.ts +14 -0
  17. package/lib/redocly/domains.js +41 -0
  18. package/lib/redocly/index.d.ts +1 -2
  19. package/lib/redocly/index.js +14 -24
  20. package/lib/redocly/registry-api.d.ts +2 -2
  21. package/lib/redocly/registry-api.js +9 -9
  22. package/lib/types/oas3_1.js +1 -0
  23. package/lib/types/redocly-yaml.d.ts +3 -1
  24. package/lib/types/redocly-yaml.js +34 -36
  25. package/lib/utils.d.ts +2 -0
  26. package/lib/utils.js +7 -1
  27. package/package.json +4 -2
  28. package/src/__tests__/lint.test.ts +22 -12
  29. package/src/bundle.ts +1 -1
  30. package/src/config/__tests__/load.test.ts +86 -61
  31. package/src/config/config.ts +1 -23
  32. package/src/config/load.ts +51 -24
  33. package/src/config/utils.ts +4 -0
  34. package/src/decorators/common/registry-dependencies.ts +1 -1
  35. package/src/index.ts +4 -1
  36. package/src/lint.ts +10 -9
  37. package/src/redocly/__tests__/domains.test.ts +52 -0
  38. package/src/redocly/__tests__/redocly-client.test.ts +5 -3
  39. package/src/redocly/domains.ts +48 -0
  40. package/src/redocly/index.ts +14 -24
  41. package/src/redocly/registry-api.ts +25 -31
  42. package/src/types/oas3_1.ts +1 -0
  43. package/src/types/redocly-yaml.ts +32 -33
  44. package/src/utils.ts +7 -1
  45. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @redocly/openapi-core
2
2
 
3
+ ## 1.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Changed resolution process to include extendedTypes and plugins before linting.
8
+
9
+ ### Patch Changes
10
+
11
+ - Added support for the `contentSchema` keyword to parse as a schema instance.
12
+
13
+ ## 1.16.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Users can run the CLI tool behind a proxy by using `HTTP_PROXY` or `HTTPS_PROXY` environment variables to configure the proxy settings.
18
+
3
19
  ## 1.15.0
4
20
 
5
21
  ### Minor Changes
package/lib/bundle.d.ts CHANGED
@@ -47,4 +47,4 @@ export declare function bundleDocument(opts: {
47
47
  removeUnusedComponents?: boolean;
48
48
  keepUrlRefs?: boolean;
49
49
  }): Promise<BundleResult>;
50
- export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "definitions" | "examples" | "links" | "responses" | "parameters" | "headers" | "schemas" | "requestBodies" | "securitySchemes" | "callbacks" | null;
50
+ export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "definitions" | "examples" | "parameters" | "headers" | "schemas" | "responses" | "requestBodies" | "securitySchemes" | "links" | "callbacks" | null;
package/lib/bundle.js CHANGED
@@ -20,7 +20,7 @@ const ref_utils_1 = require("./ref-utils");
20
20
  const rules_1 = require("./config/rules");
21
21
  const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
22
22
  const utils_1 = require("./utils");
23
- const redocly_1 = require("./redocly");
23
+ const domains_1 = require("./redocly/domains");
24
24
  const remove_unused_components_1 = require("./decorators/oas2/remove-unused-components");
25
25
  const remove_unused_components_2 = require("./decorators/oas3/remove-unused-components");
26
26
  const redocly_yaml_1 = require("./types/redocly-yaml");
@@ -234,7 +234,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
234
234
  return;
235
235
  }
236
236
  // do not bundle registry URL before push, otherwise we can't record dependencies
237
- if (skipRedoclyRegistryRefs && (0, redocly_1.isRedoclyRegistryURL)(node.$ref)) {
237
+ if (skipRedoclyRegistryRefs && (0, domains_1.isRedoclyRegistryURL)(node.$ref)) {
238
238
  return;
239
239
  }
240
240
  if (keepUrlRefs && (0, ref_utils_1.isAbsoluteUrl)(node.$ref)) {
@@ -3,12 +3,6 @@ import { SpecVersion, SpecMajorVersion, Oas2RuleSet, Oas3RuleSet, Async2RuleSet
3
3
  import type { NodeType } from '../types';
4
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
- export declare const DEFAULT_REGION = "us";
7
- export declare const DOMAINS: {
8
- us: string;
9
- eu: string;
10
- };
11
- export declare const AVAILABLE_REGIONS: Region[];
12
6
  export declare class StyleguideConfig {
13
7
  rawConfig: ResolvedStyleguideConfig;
14
8
  configFile?: string | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Config = exports.StyleguideConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0;
3
+ exports.Config = exports.StyleguideConfig = exports.IGNORE_FILE = void 0;
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const js_yaml_1 = require("../js-yaml");
@@ -12,22 +12,6 @@ const ref_utils_1 = require("../ref-utils");
12
12
  exports.IGNORE_FILE = '.redocly.lint-ignore.yaml';
13
13
  const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
14
14
  `# See https://redoc.ly/docs/cli/ for more information.\n`;
15
- exports.DEFAULT_REGION = 'us';
16
- function getDomains() {
17
- const domains = {
18
- us: 'redocly.com',
19
- eu: 'eu.redocly.com',
20
- };
21
- // FIXME: temporary fix for our lab environments
22
- const domain = env_1.env.REDOCLY_DOMAIN;
23
- if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
24
- domains[domain.split('.')[0]] = domain;
25
- }
26
- if (domain === 'redoc.online') {
27
- domains[domain] = domain;
28
- }
29
- return domains;
30
- }
31
15
  function getIgnoreFilePath(configFile) {
32
16
  if (configFile) {
33
17
  return (0, utils_1.doesYamlFileExist)(configFile)
@@ -38,8 +22,6 @@ function getIgnoreFilePath(configFile) {
38
22
  return env_1.isBrowser ? undefined : path.join(process.cwd(), exports.IGNORE_FILE);
39
23
  }
40
24
  }
41
- exports.DOMAINS = getDomains();
42
- exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
43
25
  class StyleguideConfig {
44
26
  constructor(rawConfig, configFile) {
45
27
  this.rawConfig = rawConfig;
@@ -4,7 +4,12 @@ import type { Document } from '../resolve';
4
4
  import type { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
5
5
  import type { RawConfig, RawUniversalConfig, Region } from './types';
6
6
  import type { ResolvedRefMap } from '../resolve';
7
- export type RawConfigProcessor = (rawConfig: Document, resolvedRefMap: ResolvedRefMap) => void | Promise<void>;
7
+ export type RawConfigProcessor = (params: {
8
+ document: Document;
9
+ resolvedRefMap: ResolvedRefMap;
10
+ config: Config;
11
+ parsed: Document['parsed'];
12
+ }) => void | Promise<void>;
8
13
  export declare function loadConfig(options?: {
9
14
  configPath?: string;
10
15
  customExtends?: string[];
@@ -17,9 +22,13 @@ export declare const CONFIG_FILE_NAMES: string[];
17
22
  export declare function findConfig(dir?: string): string | undefined;
18
23
  export declare function getConfig(options?: {
19
24
  configPath?: string;
20
- processRawConfig?: RawConfigProcessor;
21
25
  externalRefResolver?: BaseResolver;
22
- }): Promise<RawConfig>;
26
+ }): Promise<{
27
+ rawConfig: RawConfig;
28
+ document?: Document;
29
+ parsed?: Document['parsed'];
30
+ resolvedRefMap?: ResolvedRefMap;
31
+ }>;
23
32
  type CreateConfigOptions = {
24
33
  extends?: string[];
25
34
  tokens?: RegionalTokenWithValidity[];
@@ -15,12 +15,12 @@ const path = require("path");
15
15
  const redocly_1 = require("../redocly");
16
16
  const utils_1 = require("../utils");
17
17
  const js_yaml_1 = require("../js-yaml");
18
- const config_1 = require("./config");
19
18
  const utils_2 = require("./utils");
20
19
  const config_resolvers_1 = require("./config-resolvers");
21
20
  const bundle_1 = require("../bundle");
22
21
  const resolve_1 = require("../resolve");
23
22
  const env_1 = require("../env");
23
+ const domains_1 = require("../redocly/domains");
24
24
  function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files, region, externalRefResolver, }) {
25
25
  var _a;
26
26
  return __awaiter(this, void 0, void 0, function* () {
@@ -38,7 +38,7 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files
38
38
  rawConfig.resolve.http = {};
39
39
  rawConfig.resolve.http.headers = [...((_a = rawConfig.resolve.http.headers) !== null && _a !== void 0 ? _a : [])];
40
40
  for (const item of tokens) {
41
- const domain = config_1.DOMAINS[item.region];
41
+ const domain = domains_1.DOMAINS[item.region];
42
42
  rawConfig.resolve.http.headers.push({
43
43
  matches: `https://api.${domain}/registry/**`,
44
44
  name: 'Authorization',
@@ -68,10 +68,13 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files
68
68
  function loadConfig(options = {}) {
69
69
  return __awaiter(this, void 0, void 0, function* () {
70
70
  const { configPath = findConfig(), customExtends, processRawConfig, files, region, externalRefResolver, } = options;
71
- const rawConfig = yield getConfig({ configPath, processRawConfig, externalRefResolver });
71
+ const { rawConfig, document, parsed, resolvedRefMap } = yield getConfig({
72
+ configPath,
73
+ externalRefResolver,
74
+ });
72
75
  const redoclyClient = env_1.isBrowser ? undefined : new redocly_1.RedoclyClient();
73
76
  const tokens = redoclyClient && redoclyClient.hasTokens() ? redoclyClient.getAllTokens() : [];
74
- return addConfigMetadata({
77
+ const config = yield addConfigMetadata({
75
78
  rawConfig,
76
79
  customExtends,
77
80
  configPath,
@@ -80,6 +83,23 @@ function loadConfig(options = {}) {
80
83
  region,
81
84
  externalRefResolver,
82
85
  });
86
+ if (document && parsed && resolvedRefMap && typeof processRawConfig === 'function') {
87
+ try {
88
+ yield processRawConfig({
89
+ document,
90
+ resolvedRefMap,
91
+ config,
92
+ parsed,
93
+ });
94
+ }
95
+ catch (e) {
96
+ if (e instanceof utils_2.ConfigValidationError) {
97
+ throw e;
98
+ }
99
+ throw new Error(`Error parsing config file at '${configPath}': ${e.message}`);
100
+ }
101
+ }
102
+ return config;
83
103
  });
84
104
  }
85
105
  exports.loadConfig = loadConfig;
@@ -101,24 +121,24 @@ function findConfig(dir) {
101
121
  exports.findConfig = findConfig;
102
122
  function getConfig(options = {}) {
103
123
  return __awaiter(this, void 0, void 0, function* () {
104
- const { configPath = findConfig(), processRawConfig, externalRefResolver = new resolve_1.BaseResolver(), } = options;
124
+ const { configPath = findConfig(), externalRefResolver = new resolve_1.BaseResolver() } = options;
105
125
  if (!configPath)
106
- return {};
126
+ return { rawConfig: {} };
107
127
  try {
108
128
  const { document, resolvedRefMap } = yield (0, config_resolvers_1.resolveConfigFileAndRefs)({
109
129
  configPath,
110
130
  externalRefResolver,
111
131
  });
112
- if (typeof processRawConfig === 'function') {
113
- yield processRawConfig(document, resolvedRefMap);
114
- }
115
- const bundledConfig = yield (0, bundle_1.bundleConfig)(document, resolvedRefMap);
116
- return (0, utils_2.transformConfig)(bundledConfig);
132
+ const bundledRefMap = (0, utils_2.deepCloneMapWithJSON)(resolvedRefMap);
133
+ const parsed = yield (0, bundle_1.bundleConfig)(JSON.parse(JSON.stringify(document)), bundledRefMap);
134
+ return {
135
+ rawConfig: (0, utils_2.transformConfig)(parsed),
136
+ document,
137
+ parsed,
138
+ resolvedRefMap,
139
+ };
117
140
  }
118
141
  catch (e) {
119
- if (e instanceof utils_2.ConfigValidationError) {
120
- throw e;
121
- }
122
142
  throw new Error(`Error parsing config file at '${configPath}': ${e.message}`);
123
143
  }
124
144
  });
@@ -14,3 +14,4 @@ export declare function getResolveConfig(resolve?: RawResolveConfig): ResolveCon
14
14
  export declare function getUniquePlugins(plugins: Plugin[]): Plugin[];
15
15
  export declare class ConfigValidationError extends Error {
16
16
  }
17
+ export declare function deepCloneMapWithJSON<K, V>(originalMap: Map<K, V>): Map<K, V>;
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.ConfigValidationError = exports.getUniquePlugins = exports.getResolveConfig = exports.transformConfig = exports.checkForDeprecatedFields = exports.getMergedConfig = exports.mergeExtends = exports.prefixRules = exports.transformApiDefinitionsToApis = exports.parsePresetName = void 0;
14
+ exports.deepCloneMapWithJSON = exports.ConfigValidationError = exports.getUniquePlugins = exports.getResolveConfig = exports.transformConfig = exports.checkForDeprecatedFields = exports.getMergedConfig = exports.mergeExtends = exports.prefixRules = exports.transformApiDefinitionsToApis = exports.parsePresetName = void 0;
15
15
  const utils_1 = require("../utils");
16
16
  const config_1 = require("./config");
17
17
  const logger_1 = require("../logger");
@@ -251,3 +251,7 @@ exports.getUniquePlugins = getUniquePlugins;
251
251
  class ConfigValidationError extends Error {
252
252
  }
253
253
  exports.ConfigValidationError = ConfigValidationError;
254
+ function deepCloneMapWithJSON(originalMap) {
255
+ return new Map(JSON.parse(JSON.stringify([...originalMap])));
256
+ }
257
+ exports.deepCloneMapWithJSON = deepCloneMapWithJSON;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RegistryDependencies = void 0;
4
- const redocly_1 = require("../../redocly");
4
+ const domains_1 = require("../../redocly/domains");
5
5
  const RegistryDependencies = () => {
6
6
  const registryDependencies = new Set();
7
7
  return {
@@ -14,7 +14,7 @@ const RegistryDependencies = () => {
14
14
  ref(node) {
15
15
  if (node.$ref) {
16
16
  const link = node.$ref.split('#/')[0];
17
- if ((0, redocly_1.isRedoclyRegistryURL)(link)) {
17
+ if ((0, domains_1.isRedoclyRegistryURL)(link)) {
18
18
  registryDependencies.add(link);
19
19
  }
20
20
  }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy, pause, } from './utils';
1
+ export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy, getProxyAgent, pause, } from './utils';
2
2
  export { Oas3_1Types } from './types/oas3_1';
3
3
  export { Oas3Types } from './types/oas3';
4
4
  export { Oas2Types } from './types/oas2';
@@ -10,7 +10,8 @@ export type { StatsAccumulator, StatsName } from './typings/common';
10
10
  export { normalizeTypes } from './types';
11
11
  export { Stats } from './rules/other/stats';
12
12
  export { Config, StyleguideConfig, RawConfig, RawUniversalConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, ResolvedApi, } from './config';
13
- export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
13
+ export { RedoclyClient } from './redocly';
14
+ export * from './redocly/domains';
14
15
  export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
15
16
  export { parseYaml, stringifyYaml } from './js-yaml';
16
17
  export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
package/lib/index.js CHANGED
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.pause = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
17
+ exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.pause = exports.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
4
18
  exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = void 0;
5
19
  var utils_1 = require("./utils");
6
20
  Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
7
21
  Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
8
22
  Object.defineProperty(exports, "doesYamlFileExist", { enumerable: true, get: function () { return utils_1.doesYamlFileExist; } });
9
23
  Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return utils_1.isTruthy; } });
24
+ Object.defineProperty(exports, "getProxyAgent", { enumerable: true, get: function () { return utils_1.getProxyAgent; } });
10
25
  Object.defineProperty(exports, "pause", { enumerable: true, get: function () { return utils_1.pause; } });
11
26
  var oas3_1_1 = require("./types/oas3_1");
12
27
  Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
@@ -35,7 +50,7 @@ Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: fun
35
50
  Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
36
51
  var redocly_1 = require("./redocly");
37
52
  Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
38
- Object.defineProperty(exports, "isRedoclyRegistryURL", { enumerable: true, get: function () { return redocly_1.isRedoclyRegistryURL; } });
53
+ __exportStar(require("./redocly/domains"), exports);
39
54
  var resolve_1 = require("./resolve");
40
55
  Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return resolve_1.Source; } });
41
56
  Object.defineProperty(exports, "BaseResolver", { enumerable: true, get: function () { return resolve_1.BaseResolver; } });
package/lib/lint.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare function lintDocument(opts: {
22
22
  }): Promise<import("./walk").NormalizedProblem[]>;
23
23
  export declare function lintConfig(opts: {
24
24
  document: Document;
25
+ config: Config;
25
26
  resolvedRefMap?: ResolvedRefMap;
26
27
  severity?: ProblemSeverity;
27
28
  externalRefResolver?: BaseResolver;
package/lib/lint.js CHANGED
@@ -20,6 +20,7 @@ const oas_types_1 = require("./oas-types");
20
20
  const redocly_yaml_1 = require("./types/redocly-yaml");
21
21
  const spec_1 = require("./rules/common/spec");
22
22
  const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
23
+ const config_2 = require("@redocly/config");
23
24
  function lint(opts) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
26
  const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
@@ -85,18 +86,13 @@ function lintDocument(opts) {
85
86
  exports.lintDocument = lintDocument;
86
87
  function lintConfig(opts) {
87
88
  return __awaiter(this, void 0, void 0, function* () {
88
- const { document, severity, externalRefResolver = new resolve_1.BaseResolver() } = opts;
89
+ const { document, severity, externalRefResolver = new resolve_1.BaseResolver(), config } = opts;
89
90
  const ctx = {
90
91
  problems: [],
91
92
  oasVersion: oas_types_1.SpecVersion.OAS3_0,
92
93
  visitorsData: {},
93
94
  };
94
- const plugins = (0, config_1.resolvePlugins)([config_1.defaultPlugin]);
95
- const config = new config_1.StyleguideConfig({
96
- plugins,
97
- rules: { spec: 'error' },
98
- });
99
- const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || redocly_yaml_1.ConfigTypes, config);
95
+ const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || (0, redocly_yaml_1.createConfigTypes)(config_2.rootRedoclyConfigSchema, config), { doNotResolveExamples: config.styleguide.doNotResolveExamples });
100
96
  const rules = [
101
97
  {
102
98
  severity: severity || 'error',
@@ -24,4 +24,4 @@ export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
24
24
  export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
25
25
  export declare function detectSpec(root: any): SpecVersion;
26
26
  export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
27
- export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "Operation" | "Example" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "Examples" | "ExamplesMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "ParameterItems" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "Server" | "ServerVariable" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Callback" | "CallbacksMap" | "Parameter" | "Operation" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Example" | "Encoding" | "Header" | "Responses" | "Response" | "Link" | "Schema" | "Xml" | "SchemaProperties" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedSecuritySchemes" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "SecurityScheme" | "ServerVariablesMap" | "ExamplesMap" | "EncodingMap" | "HeadersMap" | "LinksMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "ServerList" | "XUsePkce" | "WebhooksMap", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "Components" | "SecurityScheme" | "NamedPathItems", import("./types").NodeType>;
27
+ export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "Operation" | "Example" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "Examples" | "ExamplesMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "ParameterItems" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "Server" | "ServerVariable" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Callback" | "CallbacksMap" | "Parameter" | "Operation" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Example" | "Encoding" | "Header" | "Responses" | "Response" | "Link" | "Schema" | "Xml" | "SchemaProperties" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedSecuritySchemes" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "SecurityScheme" | "ServerVariablesMap" | "ExamplesMap" | "EncodingMap" | "HeadersMap" | "LinksMap" | "WebhooksMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "ServerList" | "XUsePkce", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "Components" | "SecurityScheme" | "NamedPathItems", import("./types").NodeType>;
@@ -0,0 +1,14 @@
1
+ import { Region } from '../config/types';
2
+ export declare const DEFAULT_REGION = "us";
3
+ export declare const DOMAINS: {
4
+ us: string;
5
+ eu: string;
6
+ };
7
+ export declare const AVAILABLE_REGIONS: Region[];
8
+ export declare function getDomains(): {
9
+ us: string;
10
+ eu: string;
11
+ };
12
+ export declare function setRedoclyDomain(domain: string): void;
13
+ export declare function getRedoclyDomain(): string;
14
+ export declare function isRedoclyRegistryURL(link: string): boolean;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRedoclyRegistryURL = exports.getRedoclyDomain = exports.setRedoclyDomain = exports.getDomains = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = void 0;
4
+ let redoclyDomain = 'redocly.com';
5
+ exports.DEFAULT_REGION = 'us';
6
+ exports.DOMAINS = getDomains();
7
+ exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
8
+ function getDomains() {
9
+ const domains = {
10
+ us: 'redocly.com',
11
+ eu: 'eu.redocly.com',
12
+ };
13
+ // FIXME: temporary fix for our lab environments
14
+ const domain = redoclyDomain;
15
+ if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
16
+ domains[domain.split('.')[0]] = domain;
17
+ }
18
+ if (domain === 'redoc.online') {
19
+ domains[domain] = domain;
20
+ }
21
+ return domains;
22
+ }
23
+ exports.getDomains = getDomains;
24
+ function setRedoclyDomain(domain) {
25
+ redoclyDomain = domain;
26
+ }
27
+ exports.setRedoclyDomain = setRedoclyDomain;
28
+ function getRedoclyDomain() {
29
+ return redoclyDomain;
30
+ }
31
+ exports.getRedoclyDomain = getRedoclyDomain;
32
+ function isRedoclyRegistryURL(link) {
33
+ const domain = getRedoclyDomain() || exports.DOMAINS[exports.DEFAULT_REGION];
34
+ const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
35
+ if (!link.startsWith(`https://api.${domain}/registry/`) &&
36
+ !link.startsWith(`https://api.${legacyDomain}/registry/`)) {
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+ exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
@@ -21,11 +21,10 @@ export declare class RedoclyClient {
21
21
  isAuthorizedWithRedoclyByRegion(): Promise<boolean>;
22
22
  isAuthorizedWithRedocly(): Promise<boolean>;
23
23
  readCredentialsFile(credentialsPath: string): any;
24
- verifyToken(accessToken: string, region: Region, verbose?: boolean): Promise<{
24
+ verifyToken(accessToken: string, verbose?: boolean): Promise<{
25
25
  viewerId: string;
26
26
  organizations: string[];
27
27
  }>;
28
28
  login(accessToken: string, verbose?: boolean): Promise<void>;
29
29
  logout(): void;
30
30
  }
31
- export declare function isRedoclyRegistryURL(link: string): boolean;
@@ -9,33 +9,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.TOKEN_FILENAME = void 0;
12
+ exports.RedoclyClient = exports.TOKEN_FILENAME = void 0;
13
13
  const fs_1 = require("fs");
14
14
  const path_1 = require("path");
15
15
  const os_1 = require("os");
16
16
  const registry_api_1 = require("./registry-api");
17
- const config_1 = require("../config/config");
18
17
  const env_1 = require("../env");
19
18
  const utils_1 = require("../utils");
20
19
  const logger_1 = require("../logger");
20
+ const domains_1 = require("./domains");
21
21
  exports.TOKEN_FILENAME = '.redocly-config.json';
22
22
  class RedoclyClient {
23
23
  constructor(region) {
24
24
  this.accessTokens = {};
25
25
  this.region = this.loadRegion(region);
26
26
  this.loadTokens();
27
- this.domain = region ? config_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
28
- env_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
27
+ this.domain = region ? domains_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || domains_1.DOMAINS[domains_1.DEFAULT_REGION];
28
+ (0, domains_1.setRedoclyDomain)(this.domain);
29
29
  this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region);
30
30
  }
31
31
  loadRegion(region) {
32
- if (region && !config_1.DOMAINS[region]) {
32
+ if (region && !domains_1.DOMAINS[region]) {
33
33
  throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
34
34
  }
35
- if (env_1.env.REDOCLY_DOMAIN) {
36
- return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === env_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION);
35
+ if ((0, domains_1.getRedoclyDomain)()) {
36
+ return (domains_1.AVAILABLE_REGIONS.find((region) => domains_1.DOMAINS[region] === (0, domains_1.getRedoclyDomain)()) || domains_1.DEFAULT_REGION);
37
37
  }
38
- return region || config_1.DEFAULT_REGION;
38
+ return region || domains_1.DEFAULT_REGION;
39
39
  }
40
40
  getRegion() {
41
41
  return this.region;
@@ -71,13 +71,13 @@ class RedoclyClient {
71
71
  }
72
72
  getAllTokens() {
73
73
  return Object.entries(this.accessTokens)
74
- .filter(([region]) => config_1.AVAILABLE_REGIONS.includes(region))
74
+ .filter(([region]) => domains_1.AVAILABLE_REGIONS.includes(region))
75
75
  .map(([region, token]) => ({ region, token }));
76
76
  }
77
77
  getValidTokens() {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
79
  const allTokens = this.getAllTokens();
80
- const verifiedTokens = yield Promise.allSettled(allTokens.map(({ token, region }) => this.verifyToken(token, region)));
80
+ const verifiedTokens = yield Promise.allSettled(allTokens.map(({ token }) => this.verifyToken(token)));
81
81
  return allTokens
82
82
  .filter((_, index) => verifiedTokens[index].status === 'fulfilled')
83
83
  .map(({ token, region }) => ({ token, region, valid: true }));
@@ -98,7 +98,7 @@ class RedoclyClient {
98
98
  return false;
99
99
  }
100
100
  try {
101
- yield this.verifyToken(accessToken, this.region);
101
+ yield this.verifyToken(accessToken);
102
102
  return true;
103
103
  }
104
104
  catch (err) {
@@ -114,16 +114,16 @@ class RedoclyClient {
114
114
  readCredentialsFile(credentialsPath) {
115
115
  return (0, fs_1.existsSync)(credentialsPath) ? JSON.parse((0, fs_1.readFileSync)(credentialsPath, 'utf-8')) : {};
116
116
  }
117
- verifyToken(accessToken, region, verbose = false) {
117
+ verifyToken(accessToken, verbose = false) {
118
118
  return __awaiter(this, void 0, void 0, function* () {
119
- return this.registryApi.authStatus(accessToken, region, verbose);
119
+ return this.registryApi.authStatus(accessToken, verbose);
120
120
  });
121
121
  }
122
122
  login(accessToken, verbose = false) {
123
123
  return __awaiter(this, void 0, void 0, function* () {
124
124
  const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), exports.TOKEN_FILENAME);
125
125
  try {
126
- yield this.verifyToken(accessToken, this.region, verbose);
126
+ yield this.verifyToken(accessToken, verbose);
127
127
  }
128
128
  catch (err) {
129
129
  throw new Error('Authorization failed. Please check if you entered a valid API key.');
@@ -142,13 +142,3 @@ class RedoclyClient {
142
142
  }
143
143
  }
144
144
  exports.RedoclyClient = RedoclyClient;
145
- function isRedoclyRegistryURL(link) {
146
- const domain = env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
147
- const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
148
- if (!link.startsWith(`https://api.${domain}/registry/`) &&
149
- !link.startsWith(`https://api.${legacyDomain}/registry/`)) {
150
- return false;
151
- }
152
- return true;
153
- }
154
- exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
@@ -5,10 +5,10 @@ export declare class RegistryApi {
5
5
  private region;
6
6
  constructor(accessTokens: AccessTokens, region: Region);
7
7
  get accessToken(): string | false | undefined;
8
- getBaseUrl(region?: Region): string;
8
+ getBaseUrl(): string;
9
9
  setAccessTokens(accessTokens: AccessTokens): this;
10
10
  private request;
11
- authStatus(accessToken: string, region: Region, verbose?: boolean): Promise<{
11
+ authStatus(accessToken: string, verbose?: boolean): Promise<{
12
12
  viewerId: string;
13
13
  organizations: string[];
14
14
  }>;
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RegistryApi = void 0;
13
13
  const node_fetch_1 = require("node-fetch");
14
- const config_1 = require("../config/config");
15
14
  const utils_1 = require("../utils");
15
+ const domains_1 = require("./domains");
16
16
  const version = require('../../package.json').version;
17
17
  class RegistryApi {
18
18
  constructor(accessTokens, region) {
@@ -22,14 +22,14 @@ class RegistryApi {
22
22
  get accessToken() {
23
23
  return (0, utils_1.isNotEmptyObject)(this.accessTokens) && this.accessTokens[this.region];
24
24
  }
25
- getBaseUrl(region = config_1.DEFAULT_REGION) {
26
- return `https://api.${config_1.DOMAINS[region]}/registry`;
25
+ getBaseUrl() {
26
+ return `https://api.${(0, domains_1.getRedoclyDomain)()}/registry`;
27
27
  }
28
28
  setAccessTokens(accessTokens) {
29
29
  this.accessTokens = accessTokens;
30
30
  return this;
31
31
  }
32
- request(path = '', options = {}, region) {
32
+ request(path = '', options = {}) {
33
33
  var _a, _b;
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  const currentCommand = typeof process !== 'undefined' ? ((_a = process.env) === null || _a === void 0 ? void 0 : _a.REDOCLY_CLI_COMMAND) || '' : '';
@@ -41,7 +41,7 @@ class RegistryApi {
41
41
  if (!headers.hasOwnProperty('authorization')) {
42
42
  throw new Error('Unauthorized');
43
43
  }
44
- const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl(region)}${path}`, Object.assign({}, options, { headers }));
44
+ const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl()}${path}`, Object.assign({}, options, { headers, agent: (0, utils_1.getProxyAgent)() }));
45
45
  if (response.status === 401) {
46
46
  throw new Error('Unauthorized');
47
47
  }
@@ -52,10 +52,10 @@ class RegistryApi {
52
52
  return response;
53
53
  });
54
54
  }
55
- authStatus(accessToken, region, verbose = false) {
55
+ authStatus(accessToken, verbose = false) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  try {
58
- const response = yield this.request('', { headers: { authorization: accessToken } }, region);
58
+ const response = yield this.request('', { headers: { authorization: accessToken } });
59
59
  return yield response.json();
60
60
  }
61
61
  catch (error) {
@@ -79,7 +79,7 @@ class RegistryApi {
79
79
  filename,
80
80
  isUpsert,
81
81
  }),
82
- }, this.region);
82
+ });
83
83
  if (response.ok) {
84
84
  return response.json();
85
85
  }
@@ -103,7 +103,7 @@ class RegistryApi {
103
103
  batchId,
104
104
  batchSize,
105
105
  }),
106
- }, this.region);
106
+ });
107
107
  if (response.ok) {
108
108
  return;
109
109
  }