coursera / courier

Data interchange for the modern web + mobile stack.
http://coursera.github.io/courier/
Apache License 2.0
98 stars 24 forks source link

.courier to .pdsc generator script #81

Closed amory-coursera closed 3 years ago

amory-coursera commented 5 years ago

Coursera is looking into tooling to bridge the gap between Naptime / Courier (frameworks developed in-house) and outside specifications like gRPC. One path forward would be to build Courier -> X generators for each target X within this repository. An alternative path is to add support for generating artifacts in a smaller set of intermediate target languages, then build / make use of external libraries to convert these intermediate artifacts into some final target form.

This revision explores the latter path by adding a .courier to .pdsc generator. While .pdsc is not a widely adopted external specification, it is fairly simple and its JSON-serialized form is easy to parse, which makes it far more portable and easier mesh with other tooling than the human-optimized .courier schema format. The rough idea is that the org.coursera.courier.PdscGenerator class can be packaged as a fat jar that takes a list of .courier files and generates a corresponding list of .pdsc files. This in turn could be script called within a generic build framework like gradle or bazel, which would feed the .pdsc files into downstream generators.

In addition to the simple generator implementation, this PR fixes a bug in the assignment of ClassTemplateSpec::_location property within CourierTemplateSpecGenerator and DefaultGeneratorRunner. The previous implementation sporadically mis-labeled schema file sources for schemas referenced by an earlier target due to a map traversal order race, making it impossible to configure the generator to generator schemas defined only within specific files. Since I wanted this generator API to be able to convert specific .courier files without necessarily generating files for child types, I decided to fix here.

I'll seed a README with some of the above as part of a followup push.

cc @cliu587 @jnwng @dguo-coursera