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

Improve ability to mock data with ToJson and FromJson generated methods #188

Open
andrewmd5 opened this issue Feb 6, 2022 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@andrewmd5
Copy link
Contributor

andrewmd5 commented Feb 6, 2022

Is your feature request related to a problem? Please describe.

Trying to use Bebop as your primary serializer when working over HTTP / REST is very painful right now. There aren’t any convenient means to easily create test data for a defined type.

With JSON you have the ability to both define values and structure, but there is no real type information. In Javascript a JSON object you manually create to mirror a type in a Bebop schema still can’t be used to encode without first manually changing runtime types to be correct ones (which requires knowledge of those types!)

Describe the solution you'd like
Aggregate kinds such as unions, structs, and messages should generate with methods that both convert JSON to their underlying type and produce a JSON encoded version.

With these two methods a user can use any data mocking framework they want to test their implementations.

Additionally, bebopc should add two new flags, —to-json and —from-json

These flags would allow for the compiler itself to generate and validate test data.

bebopc —files point.bop —root-type Point —from-json << '{“x”: 2048,“y”: 1080}' > encoded.bin

or

bebopc —files point.bop —root-type Point —to-json << encoded.bin > decoded.json

Describe alternatives you've considered
I some standalone mocking tool which I actually got somewhat working but wasn’t portable and would have been easier if generated code already had easy methods of marshaling JSON.

** Other thoughts **

Possibly —json becomes a generation target that produces a valid JSON Schema which can be used to check JSON that is crafted by humans.

@andrewmd5 andrewmd5 added the enhancement New feature or request label Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant