json-machete 0.5.20 → 0.6.0-alpha-358d33e7e.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 (3) hide show
  1. package/index.js +5 -0
  2. package/index.mjs +5 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -531,6 +531,7 @@ async function healJSONSchema(schema) {
531
531
  const deduplicatedSchema = deduplicateJSONSchema(schema);
532
532
  const duplicatedTypeNames = await getDeduplicatedTitles(deduplicatedSchema);
533
533
  return visitJSONSchema(deduplicatedSchema, (subSchema, { path }) => {
534
+ var _a;
534
535
  if (typeof subSchema === 'object') {
535
536
  // Some JSON Schemas use this broken pattern and refer the type using `items`
536
537
  if (subSchema.type === 'object' && subSchema.items) {
@@ -570,6 +571,10 @@ async function healJSONSchema(schema) {
570
571
  subSchema.type = 'array';
571
572
  }
572
573
  }
574
+ if (subSchema.type === 'string' && !subSchema.format && (subSchema.examples || subSchema.example)) {
575
+ const { format } = toJsonSchema(((_a = subSchema.examples) === null || _a === void 0 ? void 0 : _a[0]) || subSchema.example);
576
+ subSchema.format = format;
577
+ }
573
578
  // If it is an object type but no properties given while example is available
574
579
  if (subSchema.type === 'object' && !subSchema.properties && subSchema.example) {
575
580
  const generatedSchema = toJsonSchema(subSchema.example, {
package/index.mjs CHANGED
@@ -526,6 +526,7 @@ async function healJSONSchema(schema) {
526
526
  const deduplicatedSchema = deduplicateJSONSchema(schema);
527
527
  const duplicatedTypeNames = await getDeduplicatedTitles(deduplicatedSchema);
528
528
  return visitJSONSchema(deduplicatedSchema, (subSchema, { path }) => {
529
+ var _a;
529
530
  if (typeof subSchema === 'object') {
530
531
  // Some JSON Schemas use this broken pattern and refer the type using `items`
531
532
  if (subSchema.type === 'object' && subSchema.items) {
@@ -565,6 +566,10 @@ async function healJSONSchema(schema) {
565
566
  subSchema.type = 'array';
566
567
  }
567
568
  }
569
+ if (subSchema.type === 'string' && !subSchema.format && (subSchema.examples || subSchema.example)) {
570
+ const { format } = toJsonSchema(((_a = subSchema.examples) === null || _a === void 0 ? void 0 : _a[0]) || subSchema.example);
571
+ subSchema.format = format;
572
+ }
568
573
  // If it is an object type but no properties given while example is available
569
574
  if (subSchema.type === 'object' && !subSchema.properties && subSchema.example) {
570
575
  const generatedSchema = toJsonSchema(subSchema.example, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-machete",
3
- "version": "0.5.20",
3
+ "version": "0.6.0-alpha-358d33e7e.0",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
6
  "@graphql-mesh/utils": "0.30.2",