Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing Json Schema files among projects with versioning

Tags:

Problem

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.

my solution

  1. I have set up a github project and put json schema files there
  2. For each change to schemas I update the repo and tag it with a new version
  3. I use jsdelivr to access it like this: https://cdn.jsdelivr.net/gh/[GITHUB-ID]/[GITHUB-PROJECT]@[TAG]/schema.js
  4. When I want to clone the code of a random microservice which requires schema file(s), as part of build process I download the schema file from jsdelivr and save it to my local repo, However the downloaded schema file(s) are git ignored.

What do you think about it, Is there a better and smoother way to handle this case?

like image 215
sepisoad Avatar asked May 19 '19 08:05

sepisoad


People also ask

Does JSON support versioning?

JSON-B does not have a versioning API but it has actually some versioning capabilities.

What is the difference between JSON and JSON Schema?

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.

Can a JSON file reference another JSON file?

JSON Reference allows a JSON value to reference another value in a JSON document. This module implements utilities for exploring these objects.

How do you reference a JSON Schema in another JSON Schema?

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.


1 Answers

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 -

  1. 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

  1. 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.

like image 56
Shobhit Chittora Avatar answered Sep 30 '22 18:09

Shobhit Chittora