Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
avro-schema-validator
Advanced tools
A tool to infer AVRO schema's from JSON messages, and to validate it.
A repository to maintain AVRO schema's for use in the DRIVER+ test-bed.
The test-bed is a message-based system, i.e. its functionality is based on exchanging messages between systems. Therefore, messages become a kind of contract between information producers and consumers. This is different from an API (Application Programmer Interface) based system such as REST, where the API is the contract.
Since messages are so important, the test-bed requires you to define an AVRO-based schema for each message that you want to send. These schema's will be stored in the test-bed's schema registry. As multiple producers may use the same topic, each message is a so-called KeyedMessage, where the key is set to the producer's ID, and the value is the actual message. In this way, we can easily filter messages based on producer's ID.
In order to register a new message, therefore, we need two schema's, one for the key and one for the value. By convention, these schema's are named TOPIC_NAME-key
and TOPIC_NAME-value
, and need to be registered before actually sending messages with them. Fortunately, it is no problem to register them multiple times: in case the schema is already present, it will simply be ignored. Additionally, please note that all messages use the same key schema, based on EDXL DE, which can be found here. So you just need to copy it over to your TOPIC_NAME-key
file.
To register a new schema pair, you have several possibilities:
TOPIC_NAME-key
and TOPIC_NAME-value
, respectively. Please note that I've experienced schema rejections using the UI, which were accepted by the schema registry.In this repository, we store the known schema's, divided in two main folders:
core
: Contains the core schema's for use in the test-bed, e.g. for logging, configuration and heartbeat. These should always be registered in the schema registry. Also note that core schema's should be prefixed with 'connect-status-' in order to show as system topics. See this issue here.other
: Contains schema's that may be useful during a trial, depending on the systems that are connected.Each folder is subdivided into folders per topic. The core
topics are preceded by an underscore by convention, as to indicate that we are dealing with system topics.
eu.driver.model.YYY
, where YYY is either core for the core messages, or something else otherwise.The AVRO schema is specified here. When creating a new schema from scratch based on an XML schema definition (XSD), most conversions are quite straightforward. However, there were some small issues that I observed while converting the CAP XML Schema definition to a CAP AVRO schema:
any
element, meaning that you can put anything you like in the CAP message. Besides the fact that I don't consider this a good idea, I also do not know how to encode this in AVRO. So for now, I have ignored it.xs:dateTime
, which is basically a string that can be validated using a regular expression pattern. In AVRO, such functionality seems to be missing, and I represented it using a string. Alternatively, we could use a LogicalType for this, but those must be defined in each adapter.minOccors = "0"
(optional element). I've converted this to an AVRO UnionType, for example when the type is xs:string
, it becomes type: ["null", "string"], default: null
.maxOccors = "unbounded"
(array). I've converted this to an AVRO UnionType, for example when the type is xs:string
, it becomes type: ["null", "string", { type: "array", items: "string" }], default: null
. So the element is optional (type is null and default is null), a simple string, or a string array.enum
with symbols (e.g. for simpleType
)), or record
(e.g. for complexType
). As a consequence, the AVRO schema may contain many types, in which case we need to specify the actual (top) type that we will use for validating/encoding/decoding messages.This repository also contains a simple JavaScript tool, which can be used to validate a schema against a JSON or XML message, and which can infer a schema too. You can install it using:
npm i -g avro-schema-validator
In case this does not work due to permission issues, you can also run it from a Linux VM or Docker (docker pull node
)
# After installing node.js using the package manager
$ sudo npm i -g avro-schema-validator --unsafe-perm=true --allow-root
avro-schema-validator, v0.2.0
MIT license.
A tool to infer AVRO schema's from JSON messages, and to validate it.
Use avro-schema-validator to infer an AVRO schema based on JSON or XML input,
or validate a JSON message against a schema.
In some cases, a valid JSON message may be considered invalid when wrapped
unions are used, e.g. when you have a property 'content', whose type is
['int', 'float'], in JSON you would need to wrap its value in order to
distinguish between an integer and a float. In case normal parsing fails,
it retries the validation using the -w option (wrapped).
Options
-h, --help Show help text
-f, --file string JSON or XML file that must be validated against a schema, or for
which we want to infer a schema.
-s, --schema string The schema file which is used to validate the JSON or XML file.
-o, --output string Override the default schema file name.
-w, --wrapped If set, use wrapped union types.
Examples
01. Infer a cap.avsc schema from the $ avro-schema-validator cap.json
cap.json file.
02. Infer a schema, and specify the output $ avro-schema-validator cap.json -o
file. mySchema.avsc
03. Validate a cap.json against the $ avro-schema-validator cap.json -s
cap.avsc schema. cap.avsc
04. Validate a wrapped cap.json against the $ avro-schema-validator -w cap.json -s
cap.avsc schema. cap.avsc
FAQs
A tool to infer AVRO schema's from JSON messages, and to validate it.
The npm package avro-schema-validator receives a total of 31 weekly downloads. As such, avro-schema-validator popularity was classified as not popular.
We found that avro-schema-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.