Skip to content

Commit

Permalink
Merge pull request #13 from guardian/fix-handling-of-empty-collections
Browse files Browse the repository at this point in the history
Fix Handling Of Empty Collections
  • Loading branch information
JamieB-gu authored Feb 12, 2021
2 parents 4c57ad9 + 4993745 commit 012f40a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target

.idea
.idea

node_modules
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "scrooge-extras",
"version": "1.2.6",
"description": "An SBT plugin to generate typescript definitions from thrift files.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/guardian/scrooge-extras.git"
},
"author": "",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/guardian/scrooge-extras/issues"
},
"homepage": "https://github.com/guardian/scrooge-extras#readme",
"devDependencies": {
"typescript": "^4.1.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ if (listInfo{{depth}}.etype === {{nestedType.thriftType}}) {
{{/nestedType}}
{{variableName}}.push({{nestedType.variableName}});
}
protocol.{{endReadingStatement}}();
} else {
protocol.skip(ftype);
}
protocol.{{endReadingStatement}}();
{{/isCollection}}
{{#isMap}}
const mapInfo{{depth}} = protocol.readMapBegin();
Expand All @@ -34,8 +32,6 @@ if (mapInfo{{depth}}.ktype === {{keyType.thriftType}} && mapInfo{{depth}}.vtype
{{/valueType}}
{{variableName}}[{{keyType.variableName}}] = {{valueType.variableName}};
}
protocol.readMapEnd();
} else {
protocol.skip(ftype);
}
protocol.readMapEnd();
{{/isMap}}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ struct School {
6: required map<string,shared.Student> classes
10: required map<i32,shared.Student> otherMapOfPeople
11: optional i64 ageInMs
12: optional map<string,i32> emptyMap
13: optional list<string> emptyList
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TypescriptGeneratorSpec extends AnyFlatSpec with Matchers {
val npmInstall = Process("npm install", npmProject.packageDirectory.toFile).!
npmInstall shouldEqual 0

val tsc = Process("tsc", npmProject.packageDirectory.toFile).!
val tsc = Process("./node_modules/.bin/tsc", npmProject.packageDirectory.toFile).!
tsc shouldEqual 0
}

Expand Down Expand Up @@ -101,7 +101,9 @@ class TypescriptGeneratorSpec extends AnyFlatSpec with Matchers {
schoolName = Some("Hogwarts School of Witchcraft and Wizardry"),
students = Seq(harry, hermione),
crazyNestedList = Seq(Set(Seq(harry), Seq(hermione))),
classes = Map("Magic" -> harry)
classes = Map("Magic" -> harry),
emptyMap = Some(Map.empty),
emptyList = Some(List.empty)
)
}

Expand Down

0 comments on commit 012f40a

Please sign in to comment.