quicktype
                                
                                 quicktype copied to clipboard
                                
                                    quicktype copied to clipboard
                            
                            
                            
                        Schema flag for folders incorrectly treats "*.schema.json" files
When using the --schema option with a folder with schema files, quicktype will treat files with the .schema.json or .json extension like normal JSON files, not as schema files.
That is to say, it will generate code for id, $schema etc. properties in the JSON files, and not treat them as schema files.
We have only been able to work around this by naming the files with a ".schema" extension, which makes quicktype behave correctly, but which isn't the convention for naming JSON schema files, and is not supported by default in many editors.
I ran into the same problem. Thank you @rikoe for posting your temp fix as it helped me a lot but would be nice if the work around wouldn't be neccesarry
srcSchema is added in front of the name of my top level interface from each file, anyone else has that when renaming the .json to .schema ?
I still have this issue, even if I use the -s schema option. I confirm that the problem is fixed when changing the file extension to .schema, but I don't like this solution as my IDE does not recognize it.
A solution I found is to give all the JSON Schema files to the CLI instead of the directory containing them, using src/* instead of the src/ directory.
I still have this issue, even if I use the
-s schemaoption. I confirm that the problem is fixed when changing the file extension to.schema, but I don't like this solution as my IDE does not recognize it.A solution I found is to give all the JSON Schema files to the CLI instead of the directory containing them, using
src/*instead of thesrc/directory.
Same issue
We still have this issue (same project as original reporter). We've ended up putting a script (javascript/node) in front of quicktype to prepare the arguments by reading the directories passed as arguments:
/** Utility for preparing arguments to quicktype, which workaround a specific
 * quicktype bug in command line argument handling (where a directory is used
 * as input the source language argument is ignored which causes our schemas
 * to be interpreted as JSON input, rather than JSONSchema).
 * Bug issue: https://github.com/glideapps/quicktype/issues/1278
 * */
const path = require('path');
const fs = require('fs');
const exec = require('child_process').exec;
const args = process.argv.slice(2);
const outputFile = args.pop();
const inputs = args;
console.log('Inputs: ' + inputs.join(' | '));
console.log('Output file argument: ' + outputFile);
let sources = '';
let dirIndex = 0;
while (dirIndex < inputs.length) {
  if (inputs[dirIndex].endsWith('.schema.json')) {
    sources += `--src ${path.join(inputs[dirIndex])} `;
  } else {
    fs.readdirSync(inputs[dirIndex], { withFileTypes: true }).forEach(file => {
      if (file.isDirectory()) {
        inputs.push(path.join(inputs[dirIndex], file.name));
      } else if (file.name.endsWith('.schema.json')) {
        sources += `--src ${path.join(inputs[dirIndex], file.name)} `;
      }
    });
  }
  dirIndex++;
}
// Normalise path to local quicktype executable.
//const quicktypeExec = "node " + ["..","quicktype","dist","index.js"].join(path.sep);
const quicktypeExec = ['.', 'node_modules', '.bin', 'quicktype'].join(path.sep);
const command = `${quicktypeExec} --prefer-const-values --prefer-unions -s schema -o ${outputFile} ${sources}`;
console.log('command to run: ' + command);
exec(command, function(error, stdout, stderr) {
  if (stdout) {
    console.log(stdout);
  }
  if (stderr) {
    console.log(stderr);
  }
});
Its not ideal, but we haven't had time to investigate quicktype's file handling to see if we can propose a fix.