Skip to content

Conversation

geographika
Copy link
Owner

Update all schemas and validation code to use the draft 2020-12 JSON schema.
Resolves #80 (skipping version 07 and going to the latest version).

@coveralls
Copy link

Coverage Status

coverage: 91.944%. remained the same
when pulling 823a305 on draft202012
into 903d381 on master.

@geographika geographika merged commit 3d385a5 into master Sep 2, 2025
8 checks passed
@geographika
Copy link
Owner Author

geographika commented Sep 3, 2025

There didn't seem to be a Python library that would help migrate the schemas, so I used JS and the https://www.npmjs.com/package/json-schema-migrate-x library. Code below for reference:

// npm install json-schema-migrate-x
// run from same folder as node with above package
// node ./migrate-schemas.js D:\GitHub\mappyfile\mappyfile\schemas\ D:\Temp\schemas\

// migrate-schemas.js
import fs from 'fs';
import path from 'path';
import * as migrate from 'json-schema-migrate-x';

// Get command-line arguments
// Usage: node migrate-schemas.js ./input-folder ./output-folder
const args = process.argv.slice(2);

if (args.length < 2) {
  console.error('Usage: node migrate-schemas.js <input-folder> <output-folder>');
  process.exit(1);
}

const inputFolder = args[0];
const outputFolder = args[1];

// Make sure output folder exists
if (!fs.existsSync(outputFolder)) {
  fs.mkdirSync(outputFolder, { recursive: true });
}

// Loop through all JSON files in the input folder
fs.readdirSync(inputFolder).forEach((file) => {
  if (path.extname(file).toLowerCase() !== '.json') return;

  const inputPath = path.join(inputFolder, file);
  const outputPath = path.join(outputFolder, file);

  // Read JSON
  const schemaJson = fs.readFileSync(inputPath, 'utf8');
  let schema;
  try {
    schema = JSON.parse(schemaJson);
  } catch (err) {
    console.error(`Error parsing ${file}: ${err}`);
    return;
  }

  // Migrate schema to Draft 2020-12
  migrate.draft2020(schema);

  // Write the migrated schema to output folder
  fs.writeFileSync(outputPath, JSON.stringify(schema, null, 2), 'utf8');

  console.log(`Migrated ${file} -> ${outputPath}`);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update to JSONSchema Draft 07
2 participants