swagger-client 3.26.7 → 3.27.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.
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable camelcase */
2
- import { toValue, transclude, ParseResultElement } from '@swagger-api/apidom-core';
2
+ import { ParseResultElement, ObjectElement, toValue, transclude, cloneDeep } from '@swagger-api/apidom-core';
3
3
  import { compile as jsonPointerCompile, evaluate as jsonPointerEvaluate, EvaluationJsonPointerError, InvalidJsonPointerError } from '@swagger-api/apidom-json-pointer';
4
- import { OpenApi3_1Element, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1';
5
- import { dereferenceApiDOM, url, ReferenceSet, Reference } from '@swagger-api/apidom-reference/configuration/empty';
4
+ import { mediaTypes, OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1';
5
+ import { dereferenceApiDOM, url, ReferenceSet, Reference, options as referenceOptions } from '@swagger-api/apidom-reference/configuration/empty';
6
6
  import BinaryParser from '@swagger-api/apidom-reference/parse/parsers/binary';
7
7
  import OpenApi3_1ResolveStrategy from '@swagger-api/apidom-reference/resolve/strategies/openapi-3-1';
8
8
  import { DEFAULT_BASE_URL } from '../../../constants.js';
@@ -14,6 +14,18 @@ import YamlParser from '../../apidom/reference/parse/parsers/yaml-1-2/index.js';
14
14
  import OpenApiJson3_1Parser from '../../apidom/reference/parse/parsers/openapi-json-3-1/index.js';
15
15
  import OpenApiYaml3_1Parser from '../../apidom/reference/parse/parsers/openapi-yaml-3-1/index.js';
16
16
  import OpenApi3_1SwaggerClientDereferenceStrategy from '../../apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js';
17
+ export const circularReplacer = refElement => {
18
+ const $refBaseURI = toValue(refElement.meta.get('baseURI'));
19
+ const referencingElement = refElement.meta.get('referencingElement');
20
+
21
+ /**
22
+ * Removing semantics from the absolutified referencing element by
23
+ * using generic ObjectElement to represent the reference.
24
+ */
25
+ return new ObjectElement({
26
+ $ref: $refBaseURI
27
+ }, cloneDeep(referencingElement.meta), cloneDeep(referencingElement.attributes));
28
+ };
17
29
  const resolveOpenAPI31Strategy = async options => {
18
30
  const {
19
31
  spec,
@@ -122,7 +134,9 @@ const resolveOpenAPI31Strategy = async options => {
122
134
  dereferenceOpts: {
123
135
  errors
124
136
  },
125
- immutable: false
137
+ immutable: false,
138
+ circular: useCircularStructures ? 'ignore' : 'replace',
139
+ circularReplacer: useCircularStructures ? referenceOptions.dereference.circularReplacer : circularReplacer
126
140
  }
127
141
  });
128
142
  const transcluded = transclude(fragmentElement, dereferenced, openApiElement);
@@ -13,7 +13,16 @@ function serialize(value, mediaType) {
13
13
  // Assume the user has a JSON string
14
14
  return value;
15
15
  }
16
+ if (Array.isArray(value)) {
17
+ value = value.map(v => {
18
+ try {
19
+ return JSON.parse(v);
20
+ } catch (e) {
21
+ return v;
22
+ }
23
+ });
24
+ }
16
25
  return JSON.stringify(value);
17
26
  }
18
- return value.toString();
27
+ return String(value);
19
28
  }
@@ -18,7 +18,6 @@ const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')]
18
18
  const mergeAllVisitorsAsync = _apidomCore.mergeAllVisitors[Symbol.for('nodejs.util.promisify.custom')];
19
19
  const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
20
20
  props: {
21
- useCircularStructures: true,
22
21
  allowMetaPatches: false,
23
22
  parameterMacro: null,
24
23
  modelPropertyMacro: null,
@@ -26,7 +25,6 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
26
25
  ancestors: null
27
26
  },
28
27
  init({
29
- useCircularStructures = this.useCircularStructures,
30
28
  allowMetaPatches = this.allowMetaPatches,
31
29
  parameterMacro = this.parameterMacro,
32
30
  modelPropertyMacro = this.modelPropertyMacro,
@@ -34,7 +32,6 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
34
32
  ancestors = []
35
33
  } = {}) {
36
34
  this.name = 'openapi-3-1-swagger-client';
37
- this.useCircularStructures = useCircularStructures;
38
35
  this.allowMetaPatches = allowMetaPatches;
39
36
  this.parameterMacro = parameterMacro;
40
37
  this.modelPropertyMacro = modelPropertyMacro;
@@ -46,17 +43,32 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
46
43
  var _options$dereference$;
47
44
  const visitors = [];
48
45
  const namespace = (0, _apidomCore.createNamespace)(_apidomNsOpenapi.default);
49
- const refSet = (_options$dereference$ = options.dereference.refSet) != null ? _options$dereference$ : (0, _empty.ReferenceSet)();
46
+ const immutableRefSet = (_options$dereference$ = options.dereference.refSet) != null ? _options$dereference$ : (0, _empty.ReferenceSet)();
47
+ const mutableRefsSet = (0, _empty.ReferenceSet)();
48
+ let refSet = immutableRefSet;
50
49
  let reference;
51
- if (!refSet.has(file.uri)) {
50
+ if (!immutableRefSet.has(file.uri)) {
52
51
  reference = (0, _empty.Reference)({
53
52
  uri: file.uri,
54
53
  value: file.parseResult
55
54
  });
56
- refSet.add(reference);
55
+ immutableRefSet.add(reference);
57
56
  } else {
58
57
  // pre-computed refSet was provided as configuration option
59
- reference = refSet.find(ref => ref.uri === file.uri);
58
+ reference = immutableRefSet.find(ref => ref.uri === file.uri);
59
+ }
60
+
61
+ /**
62
+ * Clone refSet due the dereferencing process being mutable.
63
+ * We don't want to mutate the original refSet and the references.
64
+ */
65
+ if (options.dereference.immutable) {
66
+ immutableRefSet.refs.map(ref => (0, _empty.Reference)({
67
+ ...ref,
68
+ value: (0, _apidomCore.cloneDeep)(ref.value)
69
+ })).forEach(ref => mutableRefsSet.add(ref));
70
+ reference = mutableRefsSet.find(ref => ref.uri === file.uri);
71
+ refSet = mutableRefsSet;
60
72
  }
61
73
 
62
74
  // create main dereference visitor
@@ -64,7 +76,6 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
64
76
  reference,
65
77
  namespace,
66
78
  options,
67
- useCircularStructures: this.useCircularStructures,
68
79
  allowMetaPatches: this.allowMetaPatches,
69
80
  ancestors: this.ancestors
70
81
  });
@@ -106,12 +117,25 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
106
117
  });
107
118
 
108
119
  /**
109
- * Release all memory if this refSet was not provided as a configuration option.
120
+ * If immutable option is set, replay refs from the refSet.
121
+ */
122
+ if (options.dereference.immutable) {
123
+ mutableRefsSet.refs.filter(ref => ref.uri.startsWith('immutable://')).map(ref => (0, _empty.Reference)({
124
+ ...ref,
125
+ uri: ref.uri.replace(/^immutable:\/\//, '')
126
+ })).forEach(ref => immutableRefSet.add(ref));
127
+ reference = immutableRefSet.find(ref => ref.uri === file.uri);
128
+ refSet = immutableRefSet;
129
+ }
130
+
131
+ /**
132
+ * Release all memory if this refSet was not provided as an configuration option.
110
133
  * If provided as configuration option, then provider is responsible for cleanup.
111
134
  */
112
135
  if (options.dereference.refSet === null) {
113
- refSet.clean();
136
+ immutableRefSet.clean();
114
137
  }
138
+ mutableRefsSet.clean();
115
139
  return dereferencedElement;
116
140
  }
117
141
  }
@@ -31,7 +31,8 @@ const AllOfVisitor = (0, _compose.default)({
31
31
 
32
32
  // remove allOf keyword if empty
33
33
  if (schemaElement.allOf.isEmpty) {
34
- return new _apidomNsOpenapi.SchemaElement(schemaElement.content.filter(memberElement => (0, _apidomCore.toValue)(memberElement.key) !== 'allOf'), (0, _apidomCore.cloneDeep)(schemaElement.meta), (0, _apidomCore.cloneDeep)(schemaElement.attributes));
34
+ schemaElement.remove('allOf');
35
+ return undefined;
35
36
  }
36
37
 
37
38
  // collect errors if allOf keyword contains anything else than Schema Object
@@ -43,37 +44,45 @@ const AllOfVisitor = (0, _compose.default)({
43
44
  (_this$options$derefer2 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer2 = _this$options$derefer2.errors) == null || _this$options$derefer2.push == null || _this$options$derefer2.push(error);
44
45
  return undefined;
45
46
  }
46
- const mergedSchemaElement = _apidomCore.deepmerge.all([...schemaElement.allOf.content, schemaElement]);
47
+ while (schemaElement.hasKey('allOf')) {
48
+ const {
49
+ allOf
50
+ } = schemaElement;
51
+ schemaElement.remove('allOf');
52
+ const allOfMerged = _apidomCore.deepmerge.all([...allOf.content, schemaElement]);
47
53
 
48
- /**
49
- * If there was not an original $$ref value, make sure to remove
50
- * any $$ref value that may exist from the result of `allOf` merges.
51
- */
52
- if (!schemaElement.hasKey('$$ref')) {
53
- mergedSchemaElement.remove('$$ref');
54
- }
54
+ /**
55
+ * If there was not an original $$ref value, make sure to remove
56
+ * any $$ref value that may exist from the result of `allOf` merges.
57
+ */
58
+ if (!schemaElement.hasKey('$$ref')) {
59
+ allOfMerged.remove('$$ref');
60
+ }
55
61
 
56
- /**
57
- * If there was an example keyword in the original definition,
58
- * keep it instead of merging with example from other schema.
59
- */
60
- if (schemaElement.hasKey('example')) {
61
- const member = mergedSchemaElement.getMember('example');
62
- member.value = schemaElement.get('example');
63
- }
62
+ /**
63
+ * If there was an example keyword in the original schema,
64
+ * keep it instead of merging with example from other schema.
65
+ */
66
+ if (schemaElement.hasKey('example')) {
67
+ const member = allOfMerged.getMember('example');
68
+ if (member) {
69
+ member.value = schemaElement.get('example');
70
+ }
71
+ }
64
72
 
65
- /**
66
- * If there was an examples keyword in the original definition,
67
- * keep it instead of merging with examples from other schema.
68
- */
69
- if (schemaElement.hasKey('examples')) {
70
- const member = mergedSchemaElement.getMember('examples');
71
- member.value = schemaElement.get('examples');
73
+ /**
74
+ * If there was an examples keyword in the original schema,
75
+ * keep it instead of merging with examples from other schema.
76
+ */
77
+ if (schemaElement.hasKey('examples')) {
78
+ const member = allOfMerged.getMember('examples');
79
+ if (member) {
80
+ member.value = schemaElement.get('examples');
81
+ }
82
+ }
83
+ schemaElement.content = allOfMerged.content;
72
84
  }
73
-
74
- // remove allOf keyword after the merge
75
- mergedSchemaElement.remove('allOf');
76
- return mergedSchemaElement;
85
+ return undefined;
77
86
  }
78
87
  }
79
88
  }