@redocly/openapi-core 1.14.0 → 1.16.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 (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/bundle.js +2 -2
  3. package/lib/config/config.d.ts +0 -6
  4. package/lib/config/config.js +1 -19
  5. package/lib/config/load.js +2 -2
  6. package/lib/decorators/common/registry-dependencies.js +2 -2
  7. package/lib/index.d.ts +3 -2
  8. package/lib/index.js +17 -2
  9. package/lib/redocly/domains.d.ts +14 -0
  10. package/lib/redocly/domains.js +41 -0
  11. package/lib/redocly/index.d.ts +1 -2
  12. package/lib/redocly/index.js +14 -24
  13. package/lib/redocly/registry-api.d.ts +2 -2
  14. package/lib/redocly/registry-api.js +9 -9
  15. package/lib/rules/common/no-invalid-parameter-examples.js +1 -1
  16. package/lib/rules/common/no-invalid-schema-examples.js +1 -1
  17. package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -1
  18. package/lib/types/redocly-yaml.d.ts +0 -1
  19. package/lib/types/redocly-yaml.js +3 -7
  20. package/lib/utils.d.ts +2 -0
  21. package/lib/utils.js +7 -1
  22. package/package.json +5 -3
  23. package/src/__tests__/lint.test.ts +15 -36
  24. package/src/bundle.ts +1 -1
  25. package/src/config/__tests__/load.test.ts +13 -13
  26. package/src/config/config.ts +1 -23
  27. package/src/config/load.ts +2 -1
  28. package/src/decorators/common/registry-dependencies.ts +1 -1
  29. package/src/index.ts +4 -1
  30. package/src/redocly/__tests__/domains.test.ts +52 -0
  31. package/src/redocly/__tests__/redocly-client.test.ts +5 -3
  32. package/src/redocly/domains.ts +48 -0
  33. package/src/redocly/index.ts +14 -24
  34. package/src/redocly/registry-api.ts +25 -31
  35. package/src/rules/common/__tests__/no-invalid-parameter-examples.test.ts +53 -0
  36. package/src/rules/common/__tests__/no-invalid-schema-examples.test.ts +51 -0
  37. package/src/rules/common/no-invalid-parameter-examples.ts +1 -1
  38. package/src/rules/common/no-invalid-schema-examples.ts +1 -1
  39. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +52 -0
  40. package/src/rules/oas3/no-invalid-media-type-examples.ts +1 -1
  41. package/src/types/redocly-yaml.ts +3 -13
  42. package/src/utils.ts +7 -1
  43. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @redocly/openapi-core
2
2
 
3
+ ## 1.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Users can run the CLI tool behind a proxy by using `HTTP_PROXY` or `HTTPS_PROXY` environment variables to configure the proxy settings.
8
+
9
+ ## 1.15.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Made `redocly.yaml` validation consistent with the general Redocly config.
14
+
15
+ ### Patch Changes
16
+
17
+ - Fixed `no-invalid-media-type-examples`, `no-invalid-parameter-examples`, and `no-invalid-schema-examples` rules which allowed falsy example values to pass for any schema.
18
+
3
19
  ## 1.14.0
4
20
 
5
21
  ### Minor Changes
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;
@@ -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',
@@ -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; } });
@@ -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
  }
@@ -8,7 +8,7 @@ const NoInvalidParameterExamples = (opts) => {
8
8
  return {
9
9
  Parameter: {
10
10
  leave(parameter, ctx) {
11
- if (parameter.example) {
11
+ if (parameter.example !== undefined) {
12
12
  (0, utils_1.validateExample)(parameter.example, parameter.schema, ctx.location.child('example'), ctx, allowAdditionalProperties);
13
13
  }
14
14
  if (parameter.examples) {
@@ -13,7 +13,7 @@ const NoInvalidSchemaExamples = (opts) => {
13
13
  (0, utils_1.validateExample)(example, schema, ctx.location.child(['examples', schema.examples.indexOf(example)]), ctx, allowAdditionalProperties);
14
14
  }
15
15
  }
16
- if (schema.example) {
16
+ if (schema.example !== undefined) {
17
17
  (0, utils_1.validateExample)(schema.example, schema, ctx.location.child('example'), ctx, true);
18
18
  }
19
19
  },
@@ -12,7 +12,7 @@ const ValidContentExamples = (opts) => {
12
12
  const { location, resolve } = ctx;
13
13
  if (!mediaType.schema)
14
14
  return;
15
- if (mediaType.example) {
15
+ if (mediaType.example !== undefined) {
16
16
  resolveAndValidateExample(mediaType.example, location.child('example'));
17
17
  }
18
18
  else if (mediaType.examples) {
@@ -19,7 +19,6 @@ export type Oas3_1NodeType = typeof oas3_1NodeTypesList[number];
19
19
  export declare const createConfigTypes: (extraSchemas: JSONSchema) => {
20
20
  ConfigRoot: NodeType;
21
21
  ConfigApisProperties: NodeType;
22
- ConfigRootTheme: NodeType;
23
22
  };
24
23
  export declare const ConfigTypes: Record<string, NodeType>;
25
24
  export {};
@@ -220,7 +220,7 @@ const ConfigStyleguide = {
220
220
  async2Decorators: { type: 'object' },
221
221
  },
222
222
  };
223
- const createConfigRoot = (nodeTypes) => (Object.assign(Object.assign({}, nodeTypes.rootRedoclyConfigSchema), { properties: Object.assign(Object.assign(Object.assign({}, nodeTypes.rootRedoclyConfigSchema.properties), ConfigStyleguide.properties), { apis: 'ConfigApis', theme: 'ConfigRootTheme', 'features.openapi': 'ConfigReferenceDocs', 'features.mockServer': 'ConfigMockServer', organization: { type: 'string' }, region: { enum: ['us', 'eu'] }, telemetry: { enum: ['on', 'off'] }, resolve: {
223
+ const createConfigRoot = (nodeTypes) => (Object.assign(Object.assign({}, nodeTypes.rootRedoclyConfigSchema), { properties: Object.assign(Object.assign(Object.assign({}, nodeTypes.rootRedoclyConfigSchema.properties), ConfigStyleguide.properties), { apis: 'ConfigApis', 'features.openapi': 'ConfigReferenceDocs', 'features.mockServer': 'ConfigMockServer', organization: { type: 'string' }, region: { enum: ['us', 'eu'] }, telemetry: { enum: ['on', 'off'] }, resolve: {
224
224
  properties: {
225
225
  http: 'ConfigHTTP',
226
226
  doNotResolveExamples: { type: 'boolean' },
@@ -259,10 +259,6 @@ const ConfigHTTP = {
259
259
  },
260
260
  },
261
261
  };
262
- const createConfigRootTheme = (nodeTypes) => {
263
- var _a;
264
- return (Object.assign(Object.assign({}, nodeTypes['rootRedoclyConfigSchema.theme']), { properties: Object.assign(Object.assign({}, (_a = nodeTypes['rootRedoclyConfigSchema.theme']) === null || _a === void 0 ? void 0 : _a.properties), { openapi: 'ConfigReferenceDocs' }) }));
265
- };
266
262
  const Rules = {
267
263
  properties: {},
268
264
  additionalProperties: (value, key) => {
@@ -765,8 +761,8 @@ const GenerateCodeSamples = {
765
761
  },
766
762
  required: ['languages'],
767
763
  };
764
+ // TODO: deprecated
768
765
  const ConfigReferenceDocs = {
769
- // TODO: partially invalid @Viacheslav
770
766
  properties: {
771
767
  theme: 'ConfigTheme',
772
768
  corsProxyUrl: { type: 'string' },
@@ -904,7 +900,7 @@ const ConfigMockServer = {
904
900
  const createConfigTypes = (extraSchemas) => {
905
901
  // Create types based on external schemas
906
902
  const nodeTypes = (0, json_schema_adapter_1.getNodeTypesFromJSONSchema)('rootRedoclyConfigSchema', extraSchemas);
907
- return Object.assign(Object.assign(Object.assign({}, CoreConfigTypes), { ConfigRoot: createConfigRoot(nodeTypes), ConfigApisProperties: createConfigApisProperties(nodeTypes), ConfigRootTheme: createConfigRootTheme(nodeTypes) }), nodeTypes);
903
+ return Object.assign(Object.assign(Object.assign({}, CoreConfigTypes), { ConfigRoot: createConfigRoot(nodeTypes), ConfigApisProperties: createConfigApisProperties(nodeTypes) }), nodeTypes);
908
904
  };
909
905
  exports.createConfigTypes = createConfigTypes;
910
906
  const CoreConfigTypes = {
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { UserContext } from './walk';
2
2
  import { HttpResolveConfig } from './config';
3
+ import { HttpsProxyAgent } from 'https-proxy-agent';
3
4
  export { parseYaml, stringifyYaml } from './js-yaml';
4
5
  export type StackFrame<T> = {
5
6
  prev: StackFrame<T> | null;
@@ -51,3 +52,4 @@ export declare function keysOf<T>(obj: T): (keyof T)[];
51
52
  export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
52
53
  export declare function nextTick(): void;
53
54
  export declare function pause(ms: number): Promise<void>;
55
+ export declare function getProxyAgent(): HttpsProxyAgent<string> | undefined;
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.pause = exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
12
+ exports.getProxyAgent = exports.pause = exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
13
13
  const fs = require("fs");
14
14
  const path_1 = require("path");
15
15
  const minimatch = require("minimatch");
@@ -18,6 +18,7 @@ const pluralize = require("pluralize");
18
18
  const js_yaml_1 = require("./js-yaml");
19
19
  const env_1 = require("./env");
20
20
  const logger_1 = require("./logger");
21
+ const https_proxy_agent_1 = require("https-proxy-agent");
21
22
  var js_yaml_2 = require("./js-yaml");
22
23
  Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
23
24
  Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
@@ -246,3 +247,8 @@ exports.pause = pause;
246
247
  function getUpdatedFieldName(updatedField, updatedObject) {
247
248
  return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
248
249
  }
250
+ function getProxyAgent() {
251
+ const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
252
+ return proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
253
+ }
254
+ exports.getProxyAgent = getProxyAgent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -18,7 +18,8 @@
18
18
  "path": "path-browserify",
19
19
  "os": false,
20
20
  "node-fetch": false,
21
- "colorette": false
21
+ "colorette": false,
22
+ "https-proxy-agent": false
22
23
  },
23
24
  "homepage": "https://github.com/Redocly/redocly-cli",
24
25
  "keywords": [
@@ -35,8 +36,9 @@
35
36
  ],
36
37
  "dependencies": {
37
38
  "@redocly/ajv": "^8.11.0",
38
- "@redocly/config": "^0.5.0",
39
+ "@redocly/config": "^0.6.0",
39
40
  "colorette": "^1.2.0",
41
+ "https-proxy-agent": "^7.0.4",
40
42
  "js-levenshtein": "^1.1.6",
41
43
  "js-yaml": "^4.1.0",
42
44
  "lodash.isequal": "^4.5.0",