ads2_2022/code/python/models
raj_mathe 3b8f80cff9 master > master: code py - verbesserte Darstellung + »korrekte« Behandlung von Reihenfolgen
- im Kurs wird die Permutation nur für Greedy-Berechnungen angewandt
- die Reihenfolge der Items in der Hauptberechnung bei B&B bleibt wie bei Angaben
2022-06-14 14:40:02 +02:00
..
commands-schema.yaml master > master: code py - verbesserte Darstellung + »korrekte« Behandlung von Reihenfolgen 2022-06-14 14:40:02 +02:00
config-schema.yaml master > master: code py - schemata für rucksack 2022-06-14 01:34:44 +02:00
README.md master > master: code py - models + config implementiert 2022-06-10 11:51:05 +02:00

Models

  • In this folder the configuration files for the models of data classes (as *.yaml-files) are stored.
  • These are interpreted by openapi to generate the classes for the source code during the build phase of the programme.
  • Once the models are generated, the app configurations are read at run time and interpreted as these models.
  • Generating instead of manually encoding the classes is safer/more stable as it allows for validation.

Folder structure

As per the 3rd point, the yaml-file/s for the models (schemata) and the yaml-file/s for actual configuration values for the app are to be kept separately.

All models are to be stored in ./models, whereas configuration files are to be stored in ./assets.

Note that the generated python files are not stored in the repository. When deployed on a server, these are generated as part of the build-process.

Developer notes

Prerequisites

For the python source code, we currently use:

  • Python: v3.10.*
  • Modules:
    • datamodel-code-generator==0.12.0

(This is all taken care of during the build process.)

Building the models

To build the models before run time, use the following command + options:

datamodel-codegen
    --input-file-type openapi
    --encoding "UTF-8"
    --disable-timestamp
    --use-schema-description
    --snake-case-field
    --strict-nullable
    --input <path/to/file.yml>
    --output <path/to/file.py>

(cf. https://pydantic-docs.helpmanual.io/datamodel_code_generator/).

Alternatively, call:

just build