Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c34e7e5
Stepping stone
MrRooni May 6, 2019
2a1498d
Fix a build error
MrRooni May 6, 2019
ff61903
Put the encoder/decoder helper functions into a supporting file
MrRooni May 7, 2019
fe01b7f
Handle objects with no properties
MrRooni May 7, 2019
94fb4d7
Make “description” a keyword for the Swift renderer
MrRooni May 7, 2019
eaecb8b
Make sure to import Foundation for enums and unions
MrRooni May 7, 2019
a5b3a98
Give the top level aliases the same access level as the rest of the file
MrRooni May 7, 2019
b563367
Move the alias, array, and map emitters into the helper file
MrRooni May 7, 2019
36fc2ac
Merge branch 'master' of github.com:quicktype/quicktype into swift/ro…
MrRooni May 7, 2019
544a6bd
Manually repair merge conflict
MrRooni May 7, 2019
2e965c6
Get rid of a file we don’t need anymore
MrRooni May 7, 2019
5a0381c
Fix the Swift tests to reflect their new reality
MrRooni May 7, 2019
aca272f
Correct some of the code generation in the JSONSchemaSupport.swift file
MrRooni May 7, 2019
147196f
More test fixes
MrRooni May 7, 2019
075435f
Handle multiple objects with case-insensitive matching names
MrRooni May 9, 2019
90a2097
Add support for emitting a line once
MrRooni May 9, 2019
5a19f02
Merge branch 'master' of github.com:quicktype/quicktype into swift/ro…
MrRooni May 9, 2019
4f49725
Manually repair merge conflict
MrRooni May 9, 2019
b668760
Fix the header renderer
MrRooni May 9, 2019
2d165be
Put a warning in the header about the generated nature of the source …
MrRooni May 9, 2019
cccee5b
Replace mistaken removal of YAML
MrRooni May 9, 2019
63cc340
Add a clarifying comment
MrRooni May 9, 2019
c2a78d2
No need to toString() toLowerCase()
MrRooni May 9, 2019
aaf3294
Add an option for Swift 5 support
MrRooni May 9, 2019
74b4810
Fix a spelling mistake in a comment
MrRooni May 10, 2019
b85ae52
Emit a single Swift file by default
MrRooni May 10, 2019
24a2c71
Revert "Get rid of a file we don’t need anymore"
MrRooni May 10, 2019
61eb3e5
Revert "Fix the Swift tests to reflect their new reality"
MrRooni May 10, 2019
f06342d
Add the new header comment to the test quicktype.swift file
MrRooni May 10, 2019
44d2aa1
Remove the date generated header comment
MrRooni May 10, 2019
dbfd27c
Correct the URL session output
MrRooni May 10, 2019
2ce4243
Repair Alamofire output and add some structure to the output file
MrRooni May 10, 2019
a933eb6
Small formatting changes
MrRooni May 10, 2019
a674cb0
Clean up some comments
MrRooni May 10, 2019
23f0f9f
No need to toString()
MrRooni May 10, 2019
3248825
Add bug863.json to the skipped diff testing
MrRooni May 10, 2019
0c82a1e
Merge branch 'master' of github.com:quicktype/quicktype into swift/ro…
MrRooni May 17, 2019
5adeb2f
In single-file mode output all the comments to the top of the single …
MrRooni May 17, 2019
af0b72f
Minor formatting change
MrRooni May 18, 2019
4c7f291
=== not ==
MrRooni May 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/quicktype-core/ConvenienceRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ export abstract class ConvenienceRenderer extends Renderer {
this._alphabetizeProperties = value;
}

// Returns the number of properties defined for the specified object type.
protected propertyCount(o: ObjectType): number {
const propertyNames = defined(this._propertyNamesStoreView).get(o);
return propertyNames.size;
}

protected forEachClassProperty(
o: ObjectType,
blankLocations: BlankLineConfig,
Expand Down Expand Up @@ -898,7 +904,7 @@ export abstract class ConvenienceRenderer extends Renderer {
processed.add(process(t));
}

for (; ;) {
for (;;) {
const maybeType = queue.pop();
if (maybeType === undefined) {
break;
Expand Down
36 changes: 36 additions & 0 deletions src/quicktype-core/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class EmitContext {
this.pushItem(item);
}

containsItem(item: Sourcelike): boolean {
const existingItem = this._currentEmitTarget.find((value: Sourcelike) => item === value);
return existingItem !== undefined;
}

ensureBlankLine(numBlankLines: number): void {
if (this._preventBlankLine) return;
this._numBlankLinesNeeded = Math.max(this._numBlankLinesNeeded, numBlankLines);
Expand All @@ -119,6 +124,7 @@ export abstract class Renderer {

private _names: ReadonlyMap<Name, string> | undefined;
private _finishedFiles: Map<string, Source>;
private _finishedEmitContexts: Map<string, EmitContext>;

private _emitContext: EmitContext;

Expand All @@ -127,6 +133,7 @@ export abstract class Renderer {
this.leadingComments = renderContext.leadingComments;

this._finishedFiles = new Map();
this._finishedEmitContexts = new Map();
this._emitContext = new EmitContext();
}

Expand All @@ -142,6 +149,23 @@ export abstract class Renderer {
this._emitContext.emitItem(item);
}

emitItemOnce(item: Sourcelike): void {
if (this._emitContext.containsItem(item)) {
return;
}

this.emitItem(item);
}

emitLineOnce(...lineParts: Sourcelike[]): void {
if (lineParts.length === 1) {
this.emitItemOnce(lineParts[0]);
} else if (lineParts.length > 1) {
this.emitItemOnce(lineParts);
}
this._emitContext.emitNewline();
}

emitLine(...lineParts: Sourcelike[]): void {
if (lineParts.length === 1) {
this._emitContext.emitItem(lineParts[0]);
Expand Down Expand Up @@ -266,10 +290,22 @@ export abstract class Renderer {
return assignNames(this.setUpNaming());
}

protected initializeEmitContextForFilename(filename: string): void {
if (this._finishedEmitContexts.has(filename.toLowerCase())) {
const existingEmitContext = this._finishedEmitContexts.get(filename.toLowerCase());
if (existingEmitContext !== undefined) {
this._emitContext = existingEmitContext;
}
}
}

protected finishFile(filename: string): void {
assert(!this._finishedFiles.has(filename), `Tried to emit file ${filename} more than once`);
const source = sourcelikeToSource(this._emitContext.source);
this._finishedFiles.set(filename, source);

// [Michael Fey (@MrRooni), 2019-5-9] We save the current EmitContext for possible reuse later. We put it into the map with a lowercased version of the key so we can do a case-insensitive lookup later. The reason we lowercase it is because some schema (looking at you keyword-unions.schema) define objects of the same name with different casing. BOOL vs. bool, for example.
this._finishedEmitContexts.set(filename.toLowerCase(), this._emitContext);
this._emitContext = new EmitContext();
}

Expand Down
Loading