Skip to content

Swagger model generation

Ghost User requested to merge dmitriy/swagger_models into master

Fixes #244 (closed)

Description

This MR will provide dynamic model generation from the swagger definitions.

Basic models will be generated from the swagger/models/procedure.yml file and overwrite models from the src/prozorro_sale/procedure/models/models module.

All specs have to contain _schema key with swagger definition for the specific models (at least procedure).

The configure_dynamic_models function from the prozorro_sale/procedure/model_generator module is responsible for generation new models for each procedure type from spec.

Custom keys for swagger definition:

  • x-baseClass - base class (schematics model)

Example: x-baseClass: prozorro_sale.procedure.models.models.Procedure

  • x-default - custom default value to process when generate model

Example: x-default: hex

CUSTOM_DEFAULT = {
    'hex': lambda: uuid4().hex,
    'now': datetime.now,
    'object_id': ObjectId,
    'auction_id': generate_auction_id,
}
  • x-format - field format according to the custom field types

Example: x-format__: multilang

multilang, decimal-float, ds-url, rel-url, object-id, list-object, timer

For the swagger types use type and format keys according to the swagger doc.

  • x-legalNameUa, x-legalNameEn - legal names to show in the swagger UI

  • x-serialize_when_none - serialize_when_none attribute for schematics model fields

Example: x-serialize_when_none: false

Edited by Ghost User

Merge request reports