We have a few independent projects (micro-services) that at some point in their life will refer to some JSON schema files, needles to say that each project has its own programming stack (mostly Nodejs and Golang though).
What are the best practices for sharing such data among different projects while keeping versioning.
Bellow I describe my own solution, however I would like to get your feedback as well.
What do you think about it, Is there a better and smoother way to handle this case?
JSON-B does not have a versioning API but it has actually some versioning capabilities.
JSON (JavaScript Object Notation) is a simple and lightweight text-based data format. JSON Schema is an IETF standard providing a format for what JSON data is required for a given application and how to interact with it.
JSON Reference allows a JSON value to reference another value in a JSON document. This module implements utilities for exploring these objects.
A schema can reference another schema using the $ref keyword. The value of $ref is a URI-reference that is resolved against the schema's Base URI. When evaluating a $ref , an implementation uses the resolved identifier to retrieve the referenced schema and applies that schema to the instance.
Handling multiple dependencies is ( at least in my opinion ), one of the major pain points in working with multiple microservices. A few ways which I can think of or have seen are -
Having a Monorepo -
It becomes a lot easier if you have all your services co-located under just one repository. This means you might use monorepo helpers like lerna ( for JS projects ) or similar. In this case you can have a folder structure like -
-- root
---- shared schema files ( with versioning )
---- service 1
---- service 2
Having a service which provides schema files -
The idea here is to have a separate repo for the schema files and serve them when any of your app loads. This can be done in several ways -
a). By maintaining different packages for different languages - like gems for ruby and node_modules for Node projects. Then these modules are responsible for fetching relevant schemas from a central repo.
b). By having a docker image running locally - you can also keep these schemas as docker image ( with versioning of course ) and server them by mounting as logical volumes. The image can have all kinds of helper libraries you might need to maintain the schema ( maybe validators , tests, and UI views for schemas ).
PS: you might also wanna have a look at tools like prototool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With