@redocly/openapi-core 1.9.0 → 1.10.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 (67) hide show
  1. package/CHANGELOG.md +12 -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.js +2 -2
  7. package/lib/decorators/common/registry-dependencies.js +2 -2
  8. package/lib/index.d.ts +3 -2
  9. package/lib/index.js +17 -2
  10. package/lib/lint.d.ts +1 -0
  11. package/lib/lint.js +1 -1
  12. package/lib/oas-types.d.ts +1 -1
  13. package/lib/redocly/domains.d.ts +14 -0
  14. package/lib/redocly/domains.js +41 -0
  15. package/lib/redocly/index.d.ts +1 -2
  16. package/lib/redocly/index.js +14 -24
  17. package/lib/redocly/registry-api.d.ts +2 -2
  18. package/lib/redocly/registry-api.js +9 -9
  19. package/lib/ref-utils.js +2 -2
  20. package/lib/resolve.js +9 -1
  21. package/lib/types/index.d.ts +7 -7
  22. package/lib/types/json-schema-adapter.d.ts +3 -0
  23. package/lib/types/json-schema-adapter.js +173 -0
  24. package/lib/types/oas2.d.ts +3 -2
  25. package/lib/types/oas3.d.ts +3 -2
  26. package/lib/types/oas3_1.d.ts +3 -2
  27. package/lib/types/portal-config-schema.d.ts +5261 -52
  28. package/lib/types/portal-config-schema.js +71 -55
  29. package/lib/types/redocly-yaml.d.ts +13 -1
  30. package/lib/types/redocly-yaml.js +101 -39
  31. package/lib/types/theme-config.d.ts +819 -36
  32. package/lib/types/theme-config.js +67 -29
  33. package/lib/utils.d.ts +4 -2
  34. package/lib/utils.js +7 -1
  35. package/lib/visitors.js +1 -1
  36. package/lib/walk.js +7 -1
  37. package/package.json +2 -1
  38. package/src/__tests__/lint.test.ts +1218 -36
  39. package/src/__tests__/ref-utils.test.ts +22 -0
  40. package/src/bundle.ts +1 -1
  41. package/src/config/__tests__/load.test.ts +13 -13
  42. package/src/config/config.ts +1 -23
  43. package/src/config/load.ts +2 -1
  44. package/src/decorators/common/registry-dependencies.ts +1 -1
  45. package/src/decorators/oas2/remove-unused-components.ts +3 -2
  46. package/src/decorators/oas3/remove-unused-components.ts +3 -2
  47. package/src/index.ts +11 -2
  48. package/src/lint.ts +2 -1
  49. package/src/redocly/__tests__/domains.test.ts +52 -0
  50. package/src/redocly/__tests__/redocly-client.test.ts +5 -3
  51. package/src/redocly/domains.ts +48 -0
  52. package/src/redocly/index.ts +14 -24
  53. package/src/redocly/registry-api.ts +25 -31
  54. package/src/ref-utils.ts +2 -2
  55. package/src/resolve.ts +13 -1
  56. package/src/types/index.ts +7 -12
  57. package/src/types/json-schema-adapter.ts +217 -0
  58. package/src/types/oas2.ts +5 -2
  59. package/src/types/oas3.ts +6 -2
  60. package/src/types/oas3_1.ts +5 -2
  61. package/src/types/portal-config-schema.ts +111 -61
  62. package/src/types/redocly-yaml.ts +118 -43
  63. package/src/types/theme-config.ts +125 -27
  64. package/src/utils.ts +9 -3
  65. package/src/visitors.ts +1 -1
  66. package/src/walk.ts +7 -1
  67. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @redocly/openapi-core
2
2
 
3
+ ## 1.10.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.9.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Fixed a bug with resolving $refs to file names that contain the hash symbol.
14
+
3
15
  ## 1.9.0
4
16
 
5
17
  ### 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): "responses" | "parameters" | "examples" | "headers" | "schemas" | "requestBodies" | "securitySchemes" | "links" | "callbacks" | "definitions" | null;
50
+ export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "parameters" | "examples" | "headers" | "schemas" | "responses" | "requestBodies" | "securitySchemes" | "links" | "callbacks" | "definitions" | 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;
@@ -15,10 +15,10 @@ 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");
21
+ const domains_1 = require("../redocly/domains");
22
22
  function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files, region, }) {
23
23
  var _a;
24
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -36,7 +36,7 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files
36
36
  rawConfig.resolve.http = {};
37
37
  rawConfig.resolve.http.headers = [...((_a = rawConfig.resolve.http.headers) !== null && _a !== void 0 ? _a : [])];
38
38
  for (const item of tokens) {
39
- const domain = config_1.DOMAINS[item.region];
39
+ const domain = domains_1.DOMAINS[item.region];
40
40
  rawConfig.resolve.http.headers.push({
41
41
  matches: `https://api.${domain}/registry/**`,
42
42
  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 } from './utils';
1
+ export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy, getProxyAgent, } 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.lintConfig = 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.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
17
+ exports.lintConfig = 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.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
4
18
  exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = 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
  var oas3_1_1 = require("./types/oas3_1");
11
26
  Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
12
27
  var oas3_1 = require("./types/oas3");
@@ -34,7 +49,7 @@ Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: fun
34
49
  Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
35
50
  var redocly_1 = require("./redocly");
36
51
  Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
37
- Object.defineProperty(exports, "isRedoclyRegistryURL", { enumerable: true, get: function () { return redocly_1.isRedoclyRegistryURL; } });
52
+ __exportStar(require("./redocly/domains"), exports);
38
53
  var resolve_1 = require("./resolve");
39
54
  Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return resolve_1.Source; } });
40
55
  Object.defineProperty(exports, "BaseResolver", { enumerable: true, get: function () { return resolve_1.BaseResolver; } });
package/lib/lint.d.ts CHANGED
@@ -25,4 +25,5 @@ export declare function lintConfig(opts: {
25
25
  resolvedRefMap?: ResolvedRefMap;
26
26
  severity?: ProblemSeverity;
27
27
  externalRefResolver?: BaseResolver;
28
+ externalConfigTypes?: Record<string, NodeType>;
28
29
  }): Promise<import("./walk").NormalizedProblem[]>;
package/lib/lint.js CHANGED
@@ -96,7 +96,7 @@ function lintConfig(opts) {
96
96
  plugins,
97
97
  rules: { spec: 'error' },
98
98
  });
99
- const types = (0, types_1.normalizeTypes)(redocly_yaml_1.ConfigTypes, config);
99
+ const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || redocly_yaml_1.ConfigTypes, config);
100
100
  const rules = [
101
101
  {
102
102
  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>;
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
  }
package/lib/ref-utils.js CHANGED
@@ -39,9 +39,9 @@ function escapePointer(fragment) {
39
39
  }
40
40
  exports.escapePointer = escapePointer;
41
41
  function parseRef(ref) {
42
- const [uri, pointer = ''] = ref.split('#');
42
+ const [uri, pointer = ''] = ref.split('#/');
43
43
  return {
44
- uri: uri || null,
44
+ uri: (uri.endsWith('#') ? uri.slice(0, -1) : uri) || null,
45
45
  pointer: parsePointer(pointer),
46
46
  };
47
47
  }
package/lib/resolve.js CHANGED
@@ -211,8 +211,16 @@ function resolveDocument(opts) {
211
211
  if (itemsType === undefined && type !== unknownType && type !== types_1.SpecExtension) {
212
212
  return;
213
213
  }
214
+ const isTypeAFunction = typeof itemsType === 'function';
214
215
  for (let i = 0; i < node.length; i++) {
215
- walk(node[i], itemsType || unknownType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i));
216
+ const itemType = isTypeAFunction
217
+ ? itemsType(node[i], (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i))
218
+ : itemsType;
219
+ // we continue resolving unknown types, but stop early on known scalars
220
+ if (itemType === undefined && type !== unknownType && type !== types_1.SpecExtension) {
221
+ continue;
222
+ }
223
+ walk(node[i], (0, types_1.isNamedType)(itemType) ? itemType : unknownType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i));
216
224
  }
217
225
  return;
218
226
  }
@@ -19,26 +19,26 @@ export type NormalizedScalarSchema = {
19
19
  export type NodeType = {
20
20
  properties: Record<string, PropType | ResolveTypeFn>;
21
21
  additionalProperties?: PropType | ResolveTypeFn;
22
- items?: string;
22
+ items?: PropType | ResolveTypeFn;
23
23
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
24
24
  requiredOneOf?: string[];
25
25
  allowed?: (value: any) => string[] | undefined;
26
26
  extensionsPrefix?: string;
27
27
  };
28
- type PropType = string | NodeType | ScalarSchema | undefined | null;
29
- type ResolveTypeFn = (value: any, key: string) => string | PropType;
28
+ export type PropType = string | NodeType | ScalarSchema | undefined | null;
29
+ export type ResolveTypeFn = (value: any, key: string) => string | PropType;
30
30
  export type NormalizedNodeType = {
31
31
  name: string;
32
32
  properties: Record<string, NormalizedPropType | NormalizedResolveTypeFn>;
33
33
  additionalProperties?: NormalizedPropType | NormalizedResolveTypeFn;
34
- items?: NormalizedNodeType;
34
+ items?: NormalizedPropType | NormalizedResolveTypeFn;
35
35
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
36
36
  requiredOneOf?: string[];
37
37
  allowed?: (value: any) => string[] | undefined;
38
38
  extensionsPrefix?: string;
39
39
  };
40
- type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;
41
- type NormalizedResolveTypeFn = (value: any, key: string) => NormalizedNodeType | NormalizedScalarSchema | undefined | null;
40
+ type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | null | undefined;
41
+ type NormalizedResolveTypeFn = (value: any, key: string) => NormalizedPropType;
42
42
  export declare function listOf(typeName: string): {
43
43
  name: string;
44
44
  properties: {};
@@ -53,5 +53,5 @@ export declare const SpecExtension: NormalizedNodeType;
53
53
  export declare function normalizeTypes(types: Record<string, NodeType>, options?: {
54
54
  doNotResolveExamples?: boolean;
55
55
  }): Record<string, NormalizedNodeType>;
56
- export declare function isNamedType(t: NormalizedNodeType | NormalizedScalarSchema | null | undefined): t is NormalizedNodeType;
56
+ export declare function isNamedType(t: NormalizedPropType): t is NormalizedNodeType;
57
57
  export {};
@@ -0,0 +1,3 @@
1
+ import type { NodeType } from '.';
2
+ import type { JSONSchema } from 'json-schema-to-ts';
3
+ export declare function getNodeTypesFromJSONSchema(schemaName: string, entrySchema: JSONSchema): Record<string, NodeType>;