Skip to content

enhancement: restrict schema_reader to explicitly comparable property types #66

@marcinpsk

Description

@marcinpsk

Source: PR #64 review comment 3176840475
File: core/schema_reader.py (line 61)

The load_scalar_properties helper currently includes any property whose type is not exactly "array"/"object", so definitions without an explicit scalar type (e.g. bare $ref entries pointing to complex types, anyOf/oneOf unions) are still treated as comparable scalar fields.

This produces a bogus PATCH attempt when such a property is detected as drifted; the PATCH fails gracefully with a 400, but the UX is confusing.

Proposed fix:
Limit inclusion to $ref entries and the explicit scalar types:

if "$ref" in defn:
    result.append(name)
    continue

prop_type = defn.get("type")
scalar_types = {"string", "integer", "number", "boolean", "null"}
if isinstance(prop_type, list):
    if set(prop_type) <= scalar_types:
        result.append(name)
    continue
if prop_type in scalar_types:
    result.append(name)

Note: The risk is dual — false inclusion produces a graceful 400 failure; false exclusion silently misses drift. Verify against the actual NetBox JSON schemas before applying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions