Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Handling Of Empty Collections #13

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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