question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON Schema support

See original GitHub issue

Is your feature request related to a problem? Please describe. I was wondering if support for JSON schemas was something you would be interested in having added? We are currently using confluent kafka and the schema registry to manage json schemas. We are using faust to process the data using the schema registry, and would love to be able to utilize and contribute to this library. Notably json schema support for the FaustSerializer would be great.

I would be happy to work with you to try submit a pull request. I would value guidance on your thoughts of how it should work and what the major changes might be.

As I see it the following is probably a good start.

  • Abstract most of what is currently AvroSchema class into a new abstract base class and create new child classes AvroSchema and JsonSchema. Also make load and async_load static methods respectively on the classes.
  • Update the serializer classes and factory. Open to ideas on exactly what should be updated here and how it would determine between avro and json schemas. Perhaps an argument given in __init__? Or perhaps distinct separate classes for avro vs json serialization?
  • Update all type references
  • Write new tests

Currently if you try use a json schema in the serializer and call _dumps you get the following exception.

  File "d:\scratch\python-schema-registry-client\schema_registry\serializers\faust_serializer.py", line 50, in _dumps
    return self.encode_record_with_schema(self.schema_subject, self.schema, payload)  # type: ignore
  File "d:\scratch\python-schema-registry-client\schema_registry\serializers\message_serializer.py", line 73, in encode_record_with_schema
    schema_id = self.schemaregistry_client.register(subject, avro_schema)
  File "d:\scratch\python-schema-registry-client\schema_registry\client\client.py", line 252, in register
    avro_schema = AvroSchema(avro_schema)
  File "d:\scratch\python-schema-registry-client\schema_registry\client\schema.py", line 13, in __init__
  File "fastavro\_schema.pyx", line 78, in fastavro._schema.parse_schema
  File "fastavro\_schema.pyx", line 254, in fastavro._schema._parse_schema
fastavro._schema_common.UnknownType

Describe the solution you’d like I would like to be able to pass json schemas to the FaustSerializer and have it serialize and deserialize objects correctly without an exception.

e.g. something like.

serializer = FaustSerializer(schema_registry_client, type(MyClass).__name__, MyClass.schema_json()) serializer._dumps(MyClass())

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
marcosschrohcommented, Sep 1, 2021

Thanks @Robospecta !!

2reactions
Robospectacommented, Aug 27, 2021

Thanks @marcosschroh. Apologies for the delay, we’ve actually moved away from Faust and Kafka for the time being. Thankfully I had already completed this work.

I have submitted a pull request, and tried to minimize any breaking changes. Hopefully the changes are acceptable, if anything needs addressing, or any issues arise after release, feel free to tag me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema | The home of JSON Schema
JSON Schema is a declarative language that allows you to annotate and validate JSON documents. JSON Schema enables the confident and reliable use...
Read more >
JSON Schema Examples Tutorial - MongoDB
This JSON schema tutorial will walk through the basics of setting JSON schema standards and using schema for validation in MongoDB Atlas and...
Read more >
Supported JSON Schema Keywords - Swagger
Supported JSON Schema Keywords. OpenAPI 3.0 uses an extended subset of JSON Schema Specification Wright Draft 00 (aka Draft 5) to describe the...
Read more >
JSON Schema Store
In supported JSON editors like Visual Studio and Visual Studio Code, schema files can offer auto-completion and validation to make sure your JSON...
Read more >
jsonschema 4.17.3 documentation
And for companies who appreciate jsonschema and its continued support and growth, jsonschema is also now supportable via TideLift. Contents#. Schema Validation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found