@xyd-js/openapi-sampler 0.0.0-build-56377ca-20251013180714 → 0.0.0-build-1f6458c-20251015205119

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @xyd-js/openapi-sampler
2
2
 
3
- ## 0.0.0-build-56377ca-20251013180714
3
+ ## 0.0.0-build-1f6458c-20251015205119
4
4
 
5
5
  ### Patch Changes
6
6
 
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ const SKIP_SYMBOL = Symbol('skip');
2
+
1
3
  function pad(number) {
2
4
  if (number < 10) {
3
5
  return '0' + number;
@@ -153,7 +155,10 @@ function allOfSample(into, children, options, spec, context) {
153
155
  const subSamples = [];
154
156
 
155
157
  for (let subSchema of children) {
156
- const { type, readOnly, writeOnly, value } = traverse({ type: res.type, ...subSchema }, options, spec, context);
158
+ const { type, readOnly, writeOnly, value } = traverse({ type: res.type, ...subSchema }, options, spec, {
159
+ ...context,
160
+ isAllOfChild: true,
161
+ });
157
162
  if (res.type && type && type !== res.type) {
158
163
  console.warn('allOf: schemas with different types can\'t be merged');
159
164
  res.type = type;
@@ -166,6 +171,11 @@ function allOfSample(into, children, options, spec, context) {
166
171
 
167
172
  if (res.type === 'object') {
168
173
  res.value = mergeDeep(res.value || {}, ...subSamples.filter(sample => typeof sample === 'object'));
174
+ for (const key in res.value) {
175
+ if (res.value[key] === SKIP_SYMBOL) {
176
+ delete res.value[key];
177
+ }
178
+ }
169
179
  return res;
170
180
  } else {
171
181
  if (res.type === 'array') {
@@ -782,10 +792,16 @@ function sampleObject(schema, options = {}, spec, context) {
782
792
 
783
793
  const sample = traverse(schema.properties[propertyName], options, spec, { propertyName, depth: depth + 1 });
784
794
  if (options.skipReadOnly && sample.readOnly) {
795
+ if (context?.isAllOfChild) {
796
+ res[propertyName] = SKIP_SYMBOL;
797
+ }
785
798
  return;
786
799
  }
787
800
 
788
801
  if (options.skipWriteOnly && sample.writeOnly) {
802
+ if (context?.isAllOfChild) {
803
+ res[propertyName] = SKIP_SYMBOL;
804
+ }
789
805
  return;
790
806
  }
791
807
 
@@ -1018,7 +1034,9 @@ function regexSample$1(pattern) {
1018
1034
  pattern = pattern.toString();
1019
1035
  pattern = pattern.match(/\/(.+?)\//)?.[1] ?? ''; // Remove frontslash from front and back of RegExp
1020
1036
  }
1021
-
1037
+
1038
+ pattern = pattern.replace(/^(\^)?(.*?)(\$)?$/, '$2'); // Remove anchors if present
1039
+
1022
1040
  let min;
1023
1041
  let max;
1024
1042
  let repetitions;