Closes: #388 - CustomObjectType schema exporter#450
Closes: #388 - CustomObjectType schema exporter#450jnovinger merged 7 commits into386-schema-exportfrom
Conversation
|
@claude /review |
|
Claude finished @bctiemann's task in 2m 32s —— View job PR Review: CustomObjectType Schema Exporter (#450)
OverviewThis PR introduces a clean, well-structured schema exporter for Issues1.
|
|
Fixed 1, 2, 4, 5. |
Closes: #388
Implements the COT schema exporter: a public Python API that serialises one or more
CustomObjectTypeinstances to the portable schema document format defined in #386 (PR #449).Public API —
exporter.pyBehaviour
FIELD_DEFAULTSare omitted from the output, keeping documents minimal. Round-trip safe: the importer re-applies the same defaults on load.schema_idorder for stable diffs.schema_id— skipped with aWARNINGlog entry. These are fields created before the schema-format feature was introduced and cannot be tracked portably.removed_fieldsentries are read fromcot.schema_document(populated by the apply endpoint, Custom Object Type upgrade plan/execute API endpoints #390, PR Closes: #390 - Schema validation/apply endpoints #454). Until apply is wired up this list is always empty in fresh exports.related_object_typeencoding — built-in NetBox objects encode as"app_label/model"(e.g."dcim/device"); Custom Object Types encode as"custom-objects/<slug>"using the COT slug, not its internal table model name.Data migration —
0006_backfill_schema_ids.pyAssigns sequential
schema_idvalues to existingCustomObjectTypeFieldrows that haveschema_id IS NULL(i.e. created before migration0005). Also updatesnext_schema_idon each parent COT so the auto-assign counter is never lower than the highest assigned ID.The reverse migration is a no-op (IDs are not revoked).
Tests —
test_exporter.py(32 tests, 8 classes)ExporterBasicTestCaseExporterDefaultElisionTestCaseFIELD_DEFAULTSentry is elided when equal to default; non-default values are includedExporterFieldTypesTestCaserelated_object_typeencoding for both built-in and COT targetsExporterDeprecationTestCasedeprecated,deprecated_since,scheduled_removalround-tripExporterSchemaIdTestCaseschema_id; fields withoutschema_idare skipped with a warningExporterTombstoneTestCaseremoved_fieldsread fromschema_documentand included in outputExporterSchemaValidationTestCasecot_schema_v1.json(skipped ifjsonschemanot installed)SchemaIdBackfillTestCase