chore!: Automate data model generation from upcoming CycloneDX 2.0 modularized specification
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
- Type d'issue
- Refactorisation
- Clarté
- À clarifier
- Activité
- Calme
- Stack technique
- python
- Domaine
- build-system, tooling
Piste de recherche
Commencez par le schéma CycloneDX 2.0 dans schema/2.0/model et examinez les outils de génération nommés ainsi que le travail de preuve de concept. Définissez comment le prétraitement, la génération de code, le post-traitement et la sortie commitée s’intègrent au processus de build ou de release du projet. Done comprend des modèles déterministes, une documentation et des exemples mis à jour, des tests du schéma et de enum, ainsi qu’un guide de transition ou des limitations de migration documentées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
Currently, the data models in this library are largely written and maintained manually. While this approach has worked so far, it is time-consuming and requires significant effort for both implementation and review. This effort could be better invested in feature development and bug fixing. (Also the issue is that the models code also implement the business logic, like property constraints, etc.)
With the upcoming CycloneDX 2.0 specification, a modularized and machine-readable format will be introduced. This presents an opportunity to rethink how data models are created and maintained in this project.
Reference (work in progress):
- PR https://github.com/CycloneDX/cyclonedx-python-lib/issues
- modularized schema https://github.com/CycloneDX/specification/tree/2.0-dev/schema/2.0/model
Problem
- Data models are mostly handwritten and mix in the business logic
- High maintenance overhead
- Repetitive work for contributors
- Slows down development velocity due to review effort
Proposal
Leverage the machine-readable specification planned for CycloneDX 2.0 to introduce static code generation for data models (not business logic).
This would involve:
- Parsing the official CycloneDX specification (once available in machine-readable form)
- Generating Python data models automatically
- Integrating generation into the build or release process
- Minimizing manual intervention for future spec updates
There have already been proof-of-concept implementations demonstrating that automated generation of data models from the specification is feasible. These approaches should be revisited, consolidated, and applied as part of this effort.
Pipeline:
flowchart TB
A["Input: CycloneDX JSON Schema files"]
B["Preprocessing (if needed)"]
C["Code Generation"]
D["Post-processing: formatting, code style, adjustments"]
subgraph E["Result: Generated Python code"]
direction LR
E1["Data Models"]
E2["Factories"]
E3["Serialization-specific Normalizers"]
end
A --> B --> C --> D --> E
Philosophy: decouple logic fro mdata
- Models are pure dumb typed data classes.
- Factories implement business logic for instancing data classes with the propeties' constrinats defined in the schema
- normalizers turn data classes into objects that can be handed over to serializers
- serializers take prepared objects and render XML/JSON/PB
possible file layput in the distributable:
Core
V1
v2
Models
Cyclonedx
Modules
Common
Normalizers
Serializes
Possible Tools / Libraries
The following tools could be evaluated as part of this effort:
-
datamodel-code-generator — MIT
https://pypi.org/project/datamodel-code-generator/ -
pydantic — MIT
https://pypi.org/project/pydantic/ -
dataclasses-json — MIT
https://pypi.org/project/dataclasses-json/ -
dacite — MIT
https://pypi.org/project/dacite/ -
marshmallow — MIT
https://pypi.org/project/marshmallow/ -
marshmallow-jsonschema — MIT
https://pypi.org/project/marshmallow-jsonschema/ -
jsonschema (validation, not models) — MIT
https://pypi.org/project/jsonschema/ -
quicktype — Apache 2.0
https://pypi.org/project/quicktype/ -
genson (schema generator, reverse direction) — MIT
https://pypi.org/project/genson/
Community Input
Community discussions have already suggested evaluating tools such as:
- datamodel-code-generator
- json-schema-to-pydantic (https://pypi.org/project/json-schema-to-pydantic/)
- jambo (https://pypi.org/project/jambo/)
and
- de/serialization with cattrs (https://pypi.org/project/cattrs/)
These should be considered as primary candidates during evaluation.
see discussions:
Expected Benefits
- Significant reduction in maintenance effort
- Improved consistency across models
- Faster adoption of new specification versions
- More time available for feature development and bug fixing
Considerations / Open Questions
- What format will the machine-readable spec be published in (e.g., JSON Schema, OpenAPI, etc.)?
- JSON Schema it is
- Should generated code be committed or generated at build time?
- decision: generated before build time, and commited to the repo
- How to handle custom logic or extensions on top of generated models?
- Backward compatibility with CycloneDX 1.x
- easy path: breaking change in the library, and only support 2.0 from then on
Additional Context
This proposal aligns with the direction of CycloneDX 2.0, which aims to make the specification more modular and tooling-friendly. Taking advantage of this early could significantly improve long-term maintainability of this library.
Note: This issue is intended as a meta-ticket to collect related sub-tasks and track overall implementation efforts.
Checklist
- have the models created in a deterministic way from schema
- generate the docs
- have examples updated
- have tests
- test with all schema test cases
- tests all enum completeness
- write a transition guide in the docs
- section "Upgrading to vXXX"
- we might not be able to provide a proper guide at all, since basically everything is rewrite.
- we might point to the github discussions - section FAQ - to pride at least some help
- Langage dominant
- Python
- Étoiles
- 117
- Forks
- 67
- Merge moyen
- 3 j 9 h
- PR mergées (30 j)
- 4
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de CycloneDX/cyclonedx-python-lib
-
Support Python 3.15Peut-être pris @jkowalleck l’a pris il y a 3 jours. Ouverteenhancement
CycloneDX/cyclonedx-python-lib#1056 · 1 personne assignée ·
-
[PERF] Quadratic (O(N^2)) serialization time for large BOMs — `Bom.validate()` → `register_dependency()` linear scanPeut-être pris @inspired-geek l’a pris il y a 123 jours. Ouverteperformance
Difficulté 3/5 1-2 jours Accessibilité débutants 36/100
CycloneDX/cyclonedx-python-lib#1006 · 2 commentaires ·
-
tests: test all model enumsPeut-être à nouveau libre @jkowalleck l’a pris il y a 139 jours, et aucune pull request n’est ouverte. OuverteQA
CycloneDX/cyclonedx-python-lib#991 · 1 personne assignée ·
-
feat(deps)!: make all de/serialization libraries optionalPeut-être à nouveau libre @Simoh23999 l’a pris il y a 87 jours, et aucune pull request n’est ouverte. Ouvertebreaking change dependencies
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
CycloneDX/cyclonedx-python-lib#979 · 2 commentaires ·
-
feat: Add support for Component signaturePeut-être pris @wiebe-vandendriessche l’a pris il y a 138 jours. Ouverteenhancement help wanted schema 1.4
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
CycloneDX/cyclonedx-python-lib#978 · 4 commentaires ·
Toutes les issues de CycloneDX/cyclonedx-python-lib
Issues similaires
-
intake mcp-intake needs-ac needs-human-review priority:medium
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
Ikalus1988/MisakaNet#3848 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
521xueweihan/HelloGitHub#4105 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
igormcsouza/bookloud#54 ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
aws-samples/sample-per-model-bedrock#526 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
ok-oldking/ok-wuthering-waves#1802 ·
Les mainteneurs répondent en général sous 2 jours