Skip to content

Consider use of pydantic built-ins to generate JSON schemas from python data classes #702

@ahouseholder

Description

@ahouseholder

now that we're using pydantic for the python data classes, there are some built-in functions available to us like GenerateJsonSchema that we should consider integrating in so that we can ensure our ability to round-trip between the python and javascript usages.

Originally posted by @ahouseholder in #697

This would get us another step closer to unifying the different representations of the SSVC datastructures.

Background

We are currently maintaining two distinct processes for creating SSVC related data objects:

  1. Python data classes
  2. manually created JSON Schemas

This leads to situations in which one or the other is either ahead or behind because the process for updating them is not synchronized.

Further, since #674 we have been using Pydantic dataclasses, which have much better built-in support for JSON serialization, deserialization, and schema generation.

The proposal here is that we should leverage the JSON Schema features built into Pydantic to generate the schema files in data/schema. Our current hand-built schemas have some fields that are not natively part of the generated schema, but that all seems to be addressable using features like json_schema_extra and other customization features.

The end result would be that the python dataclasses would be used as the basis for defining the JSON schemas and we could take steps to ensure they're always in sync.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    EpicLarge-scale issues that represent multi-step implementations, used to thematically link other issuestech/backendBack-end tools, code, infrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions