@redocly/openapi-core 1.0.0-beta.112 → 1.0.0-beta.114

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 (46) hide show
  1. package/lib/config/config-resolvers.js +3 -6
  2. package/lib/config/config.d.ts +4 -10
  3. package/lib/config/config.js +1 -1
  4. package/lib/config/load.js +6 -6
  5. package/lib/config/rules.d.ts +6 -3
  6. package/lib/config/rules.js +3 -2
  7. package/lib/config/types.d.ts +3 -0
  8. package/lib/ref-utils.d.ts +1 -0
  9. package/lib/ref-utils.js +5 -1
  10. package/lib/resolve.js +19 -0
  11. package/lib/rules/common/assertions/asserts.d.ts +1 -0
  12. package/lib/rules/common/assertions/asserts.js +16 -2
  13. package/lib/rules/common/spec.js +6 -0
  14. package/lib/rules/utils.js +3 -0
  15. package/lib/types/oas2.js +11 -7
  16. package/lib/types/oas3.js +15 -10
  17. package/lib/types/oas3_1.js +1 -0
  18. package/lib/types/redocly-yaml.js +6 -0
  19. package/lib/utils.d.ts +1 -0
  20. package/lib/utils.js +7 -1
  21. package/package.json +1 -1
  22. package/src/__tests__/bundle.test.ts +46 -0
  23. package/src/benchmark/benches/rebilly.yaml +36 -28
  24. package/src/config/__tests__/config-resolvers.test.ts +1 -2
  25. package/src/config/__tests__/fixtures/load-redocly.yaml +0 -2
  26. package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +0 -1
  27. package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +0 -1
  28. package/src/config/config-resolvers.ts +2 -12
  29. package/src/config/config.ts +6 -5
  30. package/src/config/load.ts +12 -5
  31. package/src/config/rules.ts +11 -3
  32. package/src/config/types.ts +2 -0
  33. package/src/ref-utils.ts +4 -0
  34. package/src/resolve.ts +25 -3
  35. package/src/rules/common/__tests__/spec.test.ts +170 -0
  36. package/src/rules/common/assertions/__tests__/asserts.test.ts +18 -0
  37. package/src/rules/common/assertions/asserts.ts +20 -2
  38. package/src/rules/common/spec.ts +7 -0
  39. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +32 -0
  40. package/src/rules/utils.ts +4 -0
  41. package/src/types/oas2.ts +11 -7
  42. package/src/types/oas3.ts +15 -10
  43. package/src/types/oas3_1.ts +1 -0
  44. package/src/types/redocly-yaml.ts +6 -0
  45. package/src/utils.ts +6 -0
  46. package/tsconfig.tsbuildinfo +1 -1
@@ -33,22 +33,19 @@ const config_1 = require("./config");
33
33
  const logger_1 = require("../logger");
34
34
  const asserts_1 = require("../rules/common/assertions/asserts");
35
35
  function resolveConfig(rawConfig, configPath) {
36
- var _a, _b, _c, _d, _e;
36
+ var _a, _b;
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  if ((_b = (_a = rawConfig.styleguide) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.some(utils_3.isNotString)) {
39
39
  throw new Error(`Error configuration format not detected in extends value must contain strings`);
40
40
  }
41
41
  const resolver = new resolve_1.BaseResolver(utils_2.getResolveConfig(rawConfig.resolve));
42
- const configExtends = (_d = (_c = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.styleguide) === null || _c === void 0 ? void 0 : _c.extends) !== null && _d !== void 0 ? _d : ['recommended'];
43
- const recommendedFallback = !((_e = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.styleguide) === null || _e === void 0 ? void 0 : _e.extends);
44
- const styleguideConfig = Object.assign(Object.assign({}, rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.styleguide), { extends: configExtends, recommendedFallback });
45
42
  const apis = yield resolveApis({
46
- rawConfig: Object.assign(Object.assign({}, rawConfig), { styleguide: styleguideConfig }),
43
+ rawConfig,
47
44
  configPath,
48
45
  resolver,
49
46
  });
50
47
  const styleguide = yield resolveStyleguideConfig({
51
- styleguideConfig,
48
+ styleguideConfig: rawConfig.styleguide,
52
49
  configPath,
53
50
  resolver,
54
51
  });
@@ -1,7 +1,7 @@
1
1
  import { NormalizedProblem } from '../walk';
2
2
  import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
3
3
  import type { NodeType } from '../types';
4
- import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig } from './types';
4
+ import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings } from './types';
5
5
  export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
6
6
  export declare const DEFAULT_REGION = "us";
7
7
  export declare const DOMAINS: {
@@ -29,15 +29,9 @@ export declare class StyleguideConfig {
29
29
  addIgnore(problem: NormalizedProblem): void;
30
30
  addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
31
31
  extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
32
- getRuleSettings(ruleId: string, oasVersion: OasVersion): {
33
- severity: string;
34
- };
35
- getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
36
- severity: string;
37
- };
38
- getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
39
- severity: string;
40
- };
32
+ getRuleSettings(ruleId: string, oasVersion: OasVersion): RuleSettings;
33
+ getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): RuleSettings;
34
+ getDecoratorSettings(ruleId: string, oasVersion: OasVersion): RuleSettings;
41
35
  getUnusedRules(): {
42
36
  rules: string[];
43
37
  preprocessors: string[];
@@ -34,7 +34,7 @@ function getIgnoreFilePath(configFile) {
34
34
  : path.join(configFile, exports.IGNORE_FILE);
35
35
  }
36
36
  else {
37
- return typeof process === 'undefined' ? undefined : path.join(process.cwd(), exports.IGNORE_FILE);
37
+ return env_1.isBrowser ? undefined : path.join(process.cwd(), exports.IGNORE_FILE);
38
38
  }
39
39
  }
40
40
  exports.DOMAINS = getDomains();
@@ -18,7 +18,7 @@ const js_yaml_1 = require("../js-yaml");
18
18
  const config_1 = require("./config");
19
19
  const utils_2 = require("./utils");
20
20
  const config_resolvers_1 = require("./config-resolvers");
21
- function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, }) {
21
+ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, files, region, }) {
22
22
  var _a;
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  if (customExtends !== undefined) {
@@ -26,8 +26,7 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, }) {
26
26
  rawConfig.styleguide.extends = customExtends;
27
27
  }
28
28
  else if (utils_1.isEmptyObject(rawConfig)) {
29
- // TODO: check if we can add recommended here. add message here?
30
- // rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
29
+ rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
31
30
  }
32
31
  if (tokens === null || tokens === void 0 ? void 0 : tokens.length) {
33
32
  if (!rawConfig.resolve)
@@ -56,14 +55,13 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, }) {
56
55
  : []));
57
56
  }
58
57
  }
59
- return config_resolvers_1.resolveConfig(rawConfig, configPath);
58
+ return config_resolvers_1.resolveConfig(Object.assign(Object.assign({}, rawConfig), { files: files !== null && files !== void 0 ? files : rawConfig.files, region: region !== null && region !== void 0 ? region : rawConfig.region }), configPath);
60
59
  });
61
60
  }
62
61
  function loadConfig(options = {}) {
63
62
  return __awaiter(this, void 0, void 0, function* () {
64
63
  const { configPath = findConfig(), customExtends, processRawConfig, files, region } = options;
65
- const config = yield getConfig(configPath, processRawConfig);
66
- const rawConfig = Object.assign(Object.assign({}, config), { files: files !== null && files !== void 0 ? files : config.files, region: region !== null && region !== void 0 ? region : config.region });
64
+ const rawConfig = yield getConfig(configPath, processRawConfig);
67
65
  const redoclyClient = new redocly_1.RedoclyClient();
68
66
  const tokens = yield redoclyClient.getTokens();
69
67
  return addConfigMetadata({
@@ -71,6 +69,8 @@ function loadConfig(options = {}) {
71
69
  customExtends,
72
70
  configPath,
73
71
  tokens,
72
+ files,
73
+ region,
74
74
  });
75
75
  });
76
76
  }
@@ -1,7 +1,10 @@
1
1
  import { RuleSet, OasVersion } from '../oas-types';
2
2
  import { StyleguideConfig } from './config';
3
- export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
4
- severity: string;
3
+ import type { ProblemSeverity } from '../walk';
4
+ declare type InitializedRule = {
5
+ severity: ProblemSeverity;
5
6
  ruleId: string;
6
7
  visitor: any;
7
- }[];
8
+ };
9
+ export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): InitializedRule[];
10
+ export {};
@@ -14,16 +14,17 @@ function initRules(rules, config, type, oasVersion) {
14
14
  if (ruleSettings.severity === 'off') {
15
15
  return undefined;
16
16
  }
17
+ const severity = ruleSettings.severity;
17
18
  const visitors = rule(ruleSettings);
18
19
  if (Array.isArray(visitors)) {
19
20
  return visitors.map((visitor) => ({
20
- severity: ruleSettings.severity,
21
+ severity,
21
22
  ruleId,
22
23
  visitor: visitor,
23
24
  }));
24
25
  }
25
26
  return {
26
- severity: ruleSettings.severity,
27
+ severity,
27
28
  ruleId,
28
29
  visitor: visitors, // note: actually it is only one visitor object
29
30
  };
@@ -3,6 +3,9 @@ import type { Oas3PreprocessorsSet, OasMajorVersion, Oas3DecoratorsSet, Oas2Rule
3
3
  import type { NodeType } from '../types';
4
4
  import { Location } from '../ref-utils';
5
5
  export declare type RuleSeverity = ProblemSeverity | 'off';
6
+ export declare type RuleSettings = {
7
+ severity: RuleSeverity;
8
+ };
6
9
  export declare type PreprocessorSeverity = RuleSeverity | 'on';
7
10
  export declare type RuleConfig = RuleSeverity | ({
8
11
  severity?: ProblemSeverity;
@@ -23,3 +23,4 @@ export declare function pointerBaseName(pointer: string): string;
23
23
  export declare function refBaseName(ref: string): string;
24
24
  export declare function isAbsoluteUrl(ref: string): boolean;
25
25
  export declare function isMappingRef(mapping: string): boolean;
26
+ export declare function isAnchor(ref: string): boolean;
package/lib/ref-utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMappingRef = exports.isAbsoluteUrl = exports.refBaseName = exports.pointerBaseName = exports.parsePointer = exports.parseRef = exports.escapePointer = exports.unescapePointer = exports.Location = exports.isRef = exports.joinPointer = void 0;
3
+ exports.isAnchor = exports.isMappingRef = exports.isAbsoluteUrl = exports.refBaseName = exports.pointerBaseName = exports.parsePointer = exports.parseRef = exports.escapePointer = exports.unescapePointer = exports.Location = exports.isRef = exports.joinPointer = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  function joinPointer(base, key) {
6
6
  if (base === '')
@@ -74,3 +74,7 @@ function isMappingRef(mapping) {
74
74
  mapping.indexOf('/') > -1);
75
75
  }
76
76
  exports.isMappingRef = isMappingRef;
77
+ function isAnchor(ref) {
78
+ return /^#[A-Za-z][A-Za-z0-9\-_:.]*$/.test(ref);
79
+ }
80
+ exports.isAnchor = isAnchor;
package/lib/resolve.js CHANGED
@@ -186,6 +186,7 @@ function resolveDocument(opts) {
186
186
  return resolvedRefMap;
187
187
  function resolveRefsInParallel(rootNode, rootNodeDocument, rootNodePointer, type) {
188
188
  const rootNodeDocAbsoluteRef = rootNodeDocument.source.absoluteRef;
189
+ const anchorRefsMap = new Map();
189
190
  walk(rootNode, type, rootNodeDocAbsoluteRef + rootNodePointer);
190
191
  function walk(node, type, nodeAbsoluteRef) {
191
192
  if (typeof node !== 'object' || node === null) {
@@ -196,6 +197,10 @@ function resolveDocument(opts) {
196
197
  return;
197
198
  }
198
199
  seedNodes.add(nodeId);
200
+ const [_, anchor] = Object.entries(node).find(([key]) => key === '$anchor') || [];
201
+ if (anchor) {
202
+ anchorRefsMap.set(`#${anchor}`, node);
203
+ }
199
204
  if (Array.isArray(node)) {
200
205
  const itemsType = type.items;
201
206
  // we continue resolving unknown types, but stop early on known scalars
@@ -245,6 +250,20 @@ function resolveDocument(opts) {
245
250
  if (hasRef(refStack.prev, ref)) {
246
251
  throw new Error('Self-referencing circular pointer');
247
252
  }
253
+ if (ref_utils_1.isAnchor(ref.$ref)) {
254
+ // Wait for all anchors in the document to be collected firstly.
255
+ yield utils_1.nextTick();
256
+ const resolvedRef = {
257
+ resolved: true,
258
+ isRemote: false,
259
+ node: anchorRefsMap.get(ref.$ref),
260
+ document,
261
+ nodePointer: ref.$ref,
262
+ };
263
+ const refId = makeRefId(document.source.absoluteRef, ref.$ref);
264
+ resolvedRefMap.set(refId, resolvedRef);
265
+ return resolvedRef;
266
+ }
248
267
  const { uri, pointer } = ref_utils_1.parseRef(ref.$ref);
249
268
  const isRemote = uri !== null;
250
269
  let targetDoc;
@@ -3,6 +3,7 @@ import { Location } from '../../../ref-utils';
3
3
  export declare type AssertionFn = (value: any, condition: any, baseLocation: Location, rawValue?: any) => AssertResult[];
4
4
  export declare type Asserts = {
5
5
  pattern: AssertionFn;
6
+ notPattern: AssertionFn;
6
7
  enum: AssertionFn;
7
8
  defined: AssertionFn;
8
9
  required: AssertionFn;
@@ -8,6 +8,7 @@ exports.runOnKeysSet = new Set([
8
8
  'mutuallyRequired',
9
9
  'enum',
10
10
  'pattern',
11
+ 'notPattern',
11
12
  'minLength',
12
13
  'maxLength',
13
14
  'casing',
@@ -21,6 +22,7 @@ exports.runOnKeysSet = new Set([
21
22
  ]);
22
23
  exports.runOnValuesSet = new Set([
23
24
  'pattern',
25
+ 'notPattern',
24
26
  'enum',
25
27
  'defined',
26
28
  'undefined',
@@ -37,14 +39,26 @@ exports.asserts = {
37
39
  if (typeof value === 'undefined')
38
40
  return []; // property doesn't exist, no need to lint it with this assert
39
41
  const values = utils_1.isString(value) ? [value] : value;
40
- const regx = utils_2.regexFromString(condition);
42
+ const regex = utils_2.regexFromString(condition);
41
43
  return values
42
- .map((_val) => !(regx === null || regx === void 0 ? void 0 : regx.test(_val)) && {
44
+ .map((_val) => !(regex === null || regex === void 0 ? void 0 : regex.test(_val)) && {
43
45
  message: `"${_val}" should match a regex ${condition}`,
44
46
  location: utils_1.isString(value) ? baseLocation : baseLocation.key(),
45
47
  })
46
48
  .filter(utils_1.isTruthy);
47
49
  },
50
+ notPattern: (value, condition, baseLocation) => {
51
+ if (typeof value === 'undefined')
52
+ return []; // property doesn't exist, no need to lint it with this assert
53
+ const values = utils_1.isString(value) ? [value] : value;
54
+ const regex = utils_2.regexFromString(condition);
55
+ return values
56
+ .map((_val) => (regex === null || regex === void 0 ? void 0 : regex.test(_val)) && {
57
+ message: `"${_val}" should not match a regex ${condition}`,
58
+ location: utils_1.isString(value) ? baseLocation : baseLocation.key(),
59
+ })
60
+ .filter(utils_1.isTruthy);
61
+ },
48
62
  enum: (value, condition, baseLocation) => {
49
63
  if (typeof value === 'undefined')
50
64
  return []; // property doesn't exist, no need to lint it with this assert
@@ -142,6 +142,12 @@ const OasSpec = () => {
142
142
  });
143
143
  }
144
144
  }
145
+ if (propName === 'nullable' && !node.type) {
146
+ report({
147
+ message: 'The `type` field must be defined when the `nullable` field is used.',
148
+ location: location.child([propName]),
149
+ });
150
+ }
145
151
  }
146
152
  },
147
153
  };
@@ -101,6 +101,9 @@ function validateExample(example, schema, dataLoc, { resolve, location, report }
101
101
  }
102
102
  }
103
103
  catch (e) {
104
+ if (e.message === 'discriminator: requires oneOf or anyOf composite keyword') {
105
+ return;
106
+ }
104
107
  report({
105
108
  message: `Example validation errored: ${e.message}.`,
106
109
  location: location.child('schema'),
package/lib/types/oas2.js CHANGED
@@ -17,8 +17,8 @@ const Root = {
17
17
  parameters: 'NamedParameters',
18
18
  responses: 'NamedResponses',
19
19
  securityDefinitions: 'NamedSecuritySchemes',
20
- security: _1.listOf('SecurityRequirement'),
21
- tags: _1.listOf('Tag'),
20
+ security: 'SecurityRequirementList',
21
+ tags: 'TagList',
22
22
  externalDocs: 'ExternalDocs',
23
23
  },
24
24
  required: ['swagger', 'paths', 'info'],
@@ -55,7 +55,7 @@ const Paths = {
55
55
  const PathItem = {
56
56
  properties: {
57
57
  $ref: { type: 'string' },
58
- parameters: _1.listOf('Parameter'),
58
+ parameters: 'ParameterList',
59
59
  get: 'Operation',
60
60
  put: 'Operation',
61
61
  post: 'Operation',
@@ -74,13 +74,13 @@ const Operation = {
74
74
  operationId: { type: 'string' },
75
75
  consumes: { type: 'array', items: { type: 'string' } },
76
76
  produces: { type: 'array', items: { type: 'string' } },
77
- parameters: _1.listOf('Parameter'),
77
+ parameters: 'ParameterList',
78
78
  responses: 'Responses',
79
79
  schemes: { type: 'array', items: { type: 'string' } },
80
80
  deprecated: { type: 'boolean' },
81
- security: _1.listOf('SecurityRequirement'),
82
- 'x-codeSamples': _1.listOf('XCodeSample'),
83
- 'x-code-samples': _1.listOf('XCodeSample'),
81
+ security: 'SecurityRequirementList',
82
+ 'x-codeSamples': 'XCodeSampleList',
83
+ 'x-code-samples': 'XCodeSampleList',
84
84
  'x-hideTryItPanel': { type: 'boolean' },
85
85
  },
86
86
  required: ['responses'],
@@ -354,8 +354,10 @@ const SecurityRequirement = {
354
354
  exports.Oas2Types = {
355
355
  Root,
356
356
  Tag,
357
+ TagList: _1.listOf('Tag'),
357
358
  ExternalDocs,
358
359
  SecurityRequirement,
360
+ SecurityRequirementList: _1.listOf('SecurityRequirement'),
359
361
  Info,
360
362
  Contact,
361
363
  License,
@@ -363,6 +365,7 @@ exports.Oas2Types = {
363
365
  PathItem,
364
366
  Parameter,
365
367
  ParameterItems,
368
+ ParameterList: _1.listOf('Parameter'),
366
369
  Operation,
367
370
  Examples,
368
371
  Header,
@@ -377,4 +380,5 @@ exports.Oas2Types = {
377
380
  NamedSecuritySchemes: _1.mapOf('SecurityScheme'),
378
381
  SecurityScheme,
379
382
  XCodeSample,
383
+ XCodeSampleList: _1.listOf('XCodeSample'),
380
384
  };
package/lib/types/oas3.js CHANGED
@@ -8,9 +8,9 @@ const Root = {
8
8
  properties: {
9
9
  openapi: null,
10
10
  info: 'Info',
11
- servers: _1.listOf('Server'),
12
- security: _1.listOf('SecurityRequirement'),
13
- tags: _1.listOf('Tag'),
11
+ servers: 'ServerList',
12
+ security: 'SecurityRequirementList',
13
+ tags: 'TagList',
14
14
  externalDocs: 'ExternalDocs',
15
15
  paths: 'Paths',
16
16
  components: 'Components',
@@ -92,8 +92,8 @@ const WebhooksMap = {
92
92
  const PathItem = {
93
93
  properties: {
94
94
  $ref: { type: 'string' },
95
- servers: _1.listOf('Server'),
96
- parameters: _1.listOf('Parameter'),
95
+ servers: 'ServerList',
96
+ parameters: 'ParameterList',
97
97
  summary: { type: 'string' },
98
98
  description: { type: 'string' },
99
99
  get: 'Operation',
@@ -137,15 +137,15 @@ const Operation = {
137
137
  description: { type: 'string' },
138
138
  externalDocs: 'ExternalDocs',
139
139
  operationId: { type: 'string' },
140
- parameters: _1.listOf('Parameter'),
141
- security: _1.listOf('SecurityRequirement'),
142
- servers: _1.listOf('Server'),
140
+ parameters: 'ParameterList',
141
+ security: 'SecurityRequirementList',
142
+ servers: 'ServerList',
143
143
  requestBody: 'RequestBody',
144
144
  responses: 'Responses',
145
145
  deprecated: { type: 'boolean' },
146
146
  callbacks: 'CallbacksMap',
147
- 'x-codeSamples': _1.listOf('XCodeSample'),
148
- 'x-code-samples': _1.listOf('XCodeSample'),
147
+ 'x-codeSamples': 'XCodeSampleList',
148
+ 'x-code-samples': 'XCodeSampleList',
149
149
  'x-hideTryItPanel': { type: 'boolean' },
150
150
  },
151
151
  required: ['responses'],
@@ -430,17 +430,21 @@ const SecurityScheme = {
430
430
  exports.Oas3Types = {
431
431
  Root,
432
432
  Tag,
433
+ TagList: _1.listOf('Tag'),
433
434
  ExternalDocs,
434
435
  Server,
436
+ ServerList: _1.listOf('Server'),
435
437
  ServerVariable,
436
438
  ServerVariablesMap: _1.mapOf('ServerVariable'),
437
439
  SecurityRequirement,
440
+ SecurityRequirementList: _1.listOf('SecurityRequirement'),
438
441
  Info,
439
442
  Contact,
440
443
  License,
441
444
  Paths,
442
445
  PathItem,
443
446
  Parameter,
447
+ ParameterList: _1.listOf('Parameter'),
444
448
  Operation,
445
449
  Callback: _1.mapOf('PathItem'),
446
450
  CallbacksMap: _1.mapOf('Callback'),
@@ -479,5 +483,6 @@ exports.Oas3Types = {
479
483
  OAuth2Flows,
480
484
  SecurityScheme,
481
485
  XCodeSample,
486
+ XCodeSampleList: _1.listOf('XCodeSample'),
482
487
  WebhooksMap,
483
488
  };
@@ -78,6 +78,7 @@ const Operation = {
78
78
  const Schema = {
79
79
  properties: {
80
80
  $id: { type: 'string' },
81
+ $anchor: { type: 'string' },
81
82
  id: { type: 'string' },
82
83
  $schema: { type: 'string' },
83
84
  definitions: 'NamedSchemas',
@@ -59,17 +59,21 @@ const builtInRulesList = [
59
59
  const nodeTypesList = [
60
60
  'Root',
61
61
  'Tag',
62
+ 'TagList',
62
63
  'ExternalDocs',
63
64
  'Server',
65
+ 'ServerList',
64
66
  'ServerVariable',
65
67
  'ServerVariablesMap',
66
68
  'SecurityRequirement',
69
+ 'SecurityRequirementList',
67
70
  'Info',
68
71
  'Contact',
69
72
  'License',
70
73
  'Paths',
71
74
  'PathItem',
72
75
  'Parameter',
76
+ 'ParameterList',
73
77
  'Operation',
74
78
  'Callback',
75
79
  'CallbacksMap',
@@ -108,6 +112,7 @@ const nodeTypesList = [
108
112
  'OAuth2Flows',
109
113
  'SecurityScheme',
110
114
  'XCodeSample',
115
+ 'XCodeSampleList',
111
116
  'WebhooksMap',
112
117
  ];
113
118
  const ConfigStyleguide = {
@@ -228,6 +233,7 @@ const AssertionDefinitionAssertions = {
228
233
  properties: {
229
234
  enum: { type: 'array', items: { type: 'string' } },
230
235
  pattern: { type: 'string' },
236
+ notPattern: { type: 'string' },
231
237
  casing: {
232
238
  enum: [
233
239
  'camelCase',
package/lib/utils.d.ts CHANGED
@@ -48,3 +48,4 @@ export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy
48
48
  export declare function identity<T>(value: T): T;
49
49
  export declare function keysOf<T>(obj: T): (keyof T)[];
50
50
  export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
51
+ export declare function nextTick(): void;
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.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.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.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.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");
@@ -223,3 +223,9 @@ function pickDefined(obj) {
223
223
  return res;
224
224
  }
225
225
  exports.pickDefined = pickDefined;
226
+ function nextTick() {
227
+ new Promise((resolve) => {
228
+ setTimeout(resolve);
229
+ });
230
+ }
231
+ exports.nextTick = nextTick;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.112",
3
+ "version": "1.0.0-beta.114",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -187,4 +187,50 @@ describe('bundle', () => {
187
187
  expect(problems).toHaveLength(0);
188
188
  expect(parsedMeta).toMatchSnapshot();
189
189
  });
190
+
191
+ it('should bundle refs using $anchors', async () => {
192
+ const testDocument = parseYamlToDocument(
193
+ outdent`
194
+ openapi: 3.1.0
195
+ components:
196
+ schemas:
197
+ User:
198
+ type: object
199
+ properties:
200
+ profile:
201
+ $ref: '#user-profile'
202
+ UserProfile:
203
+ $anchor: user-profile
204
+ type: string
205
+ `,
206
+ ''
207
+ );
208
+
209
+ const config = await makeConfig({});
210
+
211
+ const {
212
+ bundle: { parsed },
213
+ problems,
214
+ } = await bundleDocument({
215
+ document: testDocument,
216
+ config: config,
217
+ externalRefResolver: new BaseResolver(),
218
+ });
219
+
220
+ expect(problems).toHaveLength(0);
221
+ expect(parsed).toMatchInlineSnapshot(`
222
+ openapi: 3.1.0
223
+ components:
224
+ schemas:
225
+ User:
226
+ type: object
227
+ properties:
228
+ profile:
229
+ $ref: '#user-profile'
230
+ UserProfile:
231
+ $anchor: user-profile
232
+ type: string
233
+
234
+ `);
235
+ });
190
236
  });