Merge pull request #822 from quicktype/infer-maps-more
Repeatedly infer maps until nothing changes
This commit is contained in:
Коммит
2b51ccce42
|
@ -28,6 +28,15 @@ function shouldBeMap(properties: Map<string, ClassProperty>): Set<Type> | undefi
|
|||
const numProperties = properties.size;
|
||||
if (numProperties < 2) return undefined;
|
||||
|
||||
// If all property names are digit-only, we always make a map, no
|
||||
// questions asked.
|
||||
if (properties.keySeq().every(n => n.match(/^[0-9]+$/) !== null)) {
|
||||
return properties
|
||||
.valueSeq()
|
||||
.map(cp => cp.type)
|
||||
.toSet();
|
||||
}
|
||||
|
||||
if (numProperties < mapSizeThreshold) {
|
||||
const names = properties.keySeq();
|
||||
const probabilities = names.map(nameProbability);
|
||||
|
|
|
@ -243,7 +243,13 @@ export class Run {
|
|||
}
|
||||
graph = flattenStrings(graph, stringTypeMapping, debugPrintReconstitution);
|
||||
if (this._options.inferMaps) {
|
||||
graph = inferMaps(graph, stringTypeMapping, true, debugPrintReconstitution);
|
||||
for (;;) {
|
||||
const newGraph = inferMaps(graph, stringTypeMapping, true, debugPrintReconstitution);
|
||||
if (newGraph === graph) {
|
||||
break;
|
||||
}
|
||||
graph = newGraph;
|
||||
}
|
||||
}
|
||||
graph = noneToAny(graph, stringTypeMapping, debugPrintReconstitution);
|
||||
if (!targetLanguage.supportsOptionalClassProperties) {
|
||||
|
|
|
@ -325,6 +325,11 @@ class JSONToXToYFixture extends JSONFixture {
|
|||
allowMissingNull: this.runLanguage.allowMissingNull
|
||||
});
|
||||
}
|
||||
|
||||
shouldSkipTest(sample: Sample): boolean {
|
||||
if (super.shouldSkipTest(sample)) return true;
|
||||
return _.includes(this.runLanguage.skipJSON, path.basename(sample.path));
|
||||
}
|
||||
}
|
||||
|
||||
// This tests generating Schema from JSON, and then generating
|
||||
|
@ -446,6 +451,7 @@ class JSONTypeScriptFixture extends JSONToXToYFixture {
|
|||
}
|
||||
|
||||
shouldSkipTest(sample: Sample): boolean {
|
||||
if (super.shouldSkipTest(sample)) return true;
|
||||
return skipTypeScriptTests.indexOf(path.basename(sample.path)) >= 0;
|
||||
}
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -47,6 +47,7 @@ export const CSharpLanguage: Language = {
|
|||
output: "QuickType.cs",
|
||||
topLevel: "TopLevel",
|
||||
skipJSON: [
|
||||
"nbl-stats.json", // See issue #823
|
||||
"31189.json" // JSON.NET doesn't accept year 0000 as 1BC, though it should
|
||||
],
|
||||
skipMiscJSON: false,
|
||||
|
@ -138,6 +139,7 @@ export const RubyLanguage: Language = {
|
|||
"bug427.json",
|
||||
"kitchen-sink.json",
|
||||
"github-events.json",
|
||||
"nbl-stats.json",
|
||||
"reddit.json",
|
||||
"00c36.json",
|
||||
"050b0.json",
|
||||
|
@ -208,6 +210,7 @@ export const GoLanguage: Language = {
|
|||
"bug427.json",
|
||||
"github-events.json",
|
||||
"reddit.json",
|
||||
"nbl-stats.json",
|
||||
"0cffa.json",
|
||||
"0e0c2.json",
|
||||
"127a1.json",
|
||||
|
@ -269,7 +272,9 @@ export const CPlusPlusLanguage: Language = {
|
|||
topLevel: "TopLevel",
|
||||
skipJSON: [
|
||||
// fails on a string containing null
|
||||
"nst-test-suite.json"
|
||||
"nst-test-suite.json",
|
||||
// compiler error I don't want to figure out right now
|
||||
"nbl-stats.json"
|
||||
],
|
||||
skipMiscJSON: false,
|
||||
skipSchema: [],
|
||||
|
@ -293,6 +298,7 @@ export const ElmLanguage: Language = {
|
|||
skipDiffViaSchema: [
|
||||
"reddit.json",
|
||||
"github-events.json",
|
||||
"nbl-stats.json",
|
||||
"0a91a.json",
|
||||
"0cffa.json",
|
||||
"0e0c2.json",
|
||||
|
@ -444,6 +450,7 @@ export const TypeScriptLanguage: Language = {
|
|||
skipDiffViaSchema: [
|
||||
"bug427.json",
|
||||
"kitchen-sink.json",
|
||||
"nbl-stats.json",
|
||||
"00c36.json",
|
||||
"2df80.json",
|
||||
"34702.json",
|
||||
|
|
Загрузка…
Ссылка в новой задаче