How to use the quicktype-core.quicktype function in quicktype-core

To help you get started, we’ve selected a few quicktype-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / angular-cli / tools / quicktype_runner.js View on Github external
async function generate(inPath) {
  // Best description of how to use the API was found at
  //   https://blog.quicktype.io/customizing-quicktype/
  const inputData = new InputData();
  const content = fs.readFileSync(inPath, 'utf-8');
  const source = { name: 'Schema', schema: appendDeprecatedDescription(content) };

  await inputData.addSource('schema', source, () => {
    return new JSONSchemaInput(new FetchingJSONSchemaStore(inPath));
  });

  const lang = new TypeScriptTargetLanguage();

  const { lines } = await quicktype({
    lang,
    inputData,
    alphabetizeProperties: true,
    rendererOptions: {
      'just-types': 'true',
      'explicit-unions': 'true',
      'acronym-style': 'camel',
    },
  });

  return header + lines.join('\n') + footer;
}
github segmentio / typewriter / src / commands / gen-js / typescript.ts View on Github external
export async function genTSDeclarations(
  events: TrackedEvent[],
  client = Client.js
): Promise {
  const { lines } = await quicktype({
    lang: new AJSTSDeclarationsTargetLanguage(client),
    inputData: processEventsForQuickType(events),
    rendererOptions: { 'nice-property-names': 'true' }
  })

  return prettier.format(lines.join('\n'), { parser: 'typescript' })
}
github quicktype / quicktype-vscode / src / extension.ts View on Github external
inputData,
        leadingComments: ["Generated by https://quicktype.io"].concat(additionalLeadingComments),
        rendererOptions,
        indentation,
        inferMaps: configuration.inferMaps,
        inferEnums: configuration.inferEnums,
        inferDateTimes: configuration.inferDateTimes,
        inferIntegerStrings: configuration.inferIntegerStrings
    };
    for (const flag of inferenceFlagNames) {
        if (typeof configuration[flag] === "boolean") {
            options[flag] = configuration[flag];
        }
    }

    return await quicktype(options);
}
github segmentio / typewriter / src / commands / gen-ts.ts View on Github external
$schema: 'http://json-schema.org/draft-04/schema#',
      title: rules.title,
      description: rules.description,
      ...rules.properties.properties
    }

    inputData.addSource(
      'schema',
      { name, uris: [name], schema: JSON.stringify(schema) },
      () => new JSONSchemaInput(undefined)
    )
  })

  const lang = new AJSTargetLanguage()

  const { lines } = await quicktype({
    lang,
    inputData,
    rendererOptions: { 'nice-property-names': 'true' }
  })
  return lines.join('\n')
}