{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tradedashboard-eu/json-schema/tradedashboard-eu-validate-customs-code-response-schema.json",
  "title": "ValidateCustomsCodeResponse",
  "description": "GET /api/reference/validate-customs-code/{customs_code} — a validated\ncustoms code with its description hierarchy.  Also one batch item's\nsuccess shape.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tradedashboard-eu-openapi.json#/components/schemas/ValidateCustomsCodeResponse",
  "properties": {
    "customs_code": {
      "type": "string",
      "title": "Customs Code",
      "description": "The validated, normalised customs code."
    },
    "levels": {
      "items": {
        "$ref": "#/$defs/DescriptionLevel"
      },
      "type": "array",
      "title": "Levels",
      "description": "The code's CN description hierarchy (one entry per ancestor level), in the requested language."
    },
    "customs_code_label": {
      "type": "string",
      "title": "Customs Code Label",
      "description": "The code's display label (the deepest level's text).",
      "default": ""
    },
    "has_subcodes": {
      "type": "boolean",
      "title": "Has Subcodes",
      "description": "Whether the code has children in the current CN edition.",
      "default": false
    },
    "interpreted_from": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Interpreted From",
      "description": "The raw input, when it was reformatted into customs_code (always the input as typed, never a note)."
    },
    "residual_kind": {
      "anyOf": [
        {
          "$ref": "#/$defs/WireEnum_ResidualKind_"
        },
        {
          "type": "null"
        }
      ],
      "description": "Residual class for residual spellings: 'xx' or 'letter' (reason groups report 'letter', the class of the codes they group)."
    },
    "residual_spelling": {
      "anyOf": [
        {
          "$ref": "#/$defs/WireEnum_ResidualSpelling_"
        },
        {
          "type": "null"
        }
      ],
      "description": "The residual spelling's exact shape: 'xx', 'letter' or 'reason_group'."
    },
    "residual_reason": {
      "anyOf": [
        {
          "$ref": "#/$defs/WireEnum_ResidualReason_"
        },
        {
          "type": "null"
        }
      ],
      "description": "The reason letter of a letter code or reason group (S, Y, E, I, …)."
    },
    "in_eurostat_api": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "In Eurostat Api",
      "description": "For residual spellings: whether Eurostat's API serves the code as a PRODUCT value (XX codes only)."
    },
    "residual_customs_codes": {
      "anyOf": [
        {
          "items": {
            "$ref": "#/$defs/SubcodeRow"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Residual Customs Codes",
      "description": "Residual customs codes related to this code: those directly under a digit code (its XX code plus one reason group per reason letter), or the letter codes inside a reason group."
    },
    "in_current_cn": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "In Current Cn",
      "description": "For digit codes: whether the current CN edition lists the code. False for a code known only from its recorded history (expired or abolished)."
    },
    "segment_history": {
      "anyOf": [
        {
          "items": {
            "$ref": "#/$defs/SegmentHistoryPayload"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Segment History",
      "description": "Every recorded definition of the code, with direct recorded links; null when no classification history is recorded for it. Use these windows to compose windowed pieces (the basket request form)."
    }
  },
  "additionalProperties": false,
  "type": "object",
  "required": [
    "customs_code",
    "levels",
    "customs_code_label",
    "has_subcodes",
    "interpreted_from",
    "residual_kind",
    "residual_spelling",
    "residual_reason",
    "in_eurostat_api",
    "residual_customs_codes",
    "in_current_cn",
    "segment_history"
  ],
  "$defs": {
    "CodeLabel_CustomsCode_": {
      "properties": {
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "A canonical customs code, TOTAL, or a supported residual spelling."
        },
        "text": {
          "type": "string",
          "title": "Text"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "customs_code",
        "text"
      ],
      "title": "CodeLabel[CustomsCode]"
    },
    "DescriptionLevel": {
      "properties": {
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "The level's customs code."
        },
        "text": {
          "type": "string",
          "title": "Text",
          "description": "The level's label, in the requested language."
        },
        "untranslated": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Untranslated",
          "description": "True when the label fell back to English."
        },
        "is_catch_all": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Is Catch All",
          "description": "True for a catch-all ('other') level."
        },
        "siblings": {
          "anyOf": [
            {
              "items": {
                "$ref": "#/$defs/CodeLabel_CustomsCode_"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "title": "Siblings",
          "description": "For a catch-all level, the ordinary siblings it excludes."
        },
        "segment": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Segment",
          "description": "True for a historical segment's own definition."
        },
        "residual": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Residual",
          "description": "True for the synthetic level of a residual spelling."
        },
        "window": {
          "anyOf": [
            {
              "$ref": "#/$defs/SegmentWindow"
            },
            {
              "type": "null"
            }
          ],
          "description": "For a level read from a dated edition (a former definition, or one of its ancestors as that edition had them): the validity window of the definition shown. Absent for current-edition levels."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "customs_code",
        "text"
      ],
      "title": "DescriptionLevel",
      "description": "One level of a customs code's description hierarchy, chapter first\n(``ComextNomenclature.get_description_levels``, plus the synthetic\nlevels of residual spellings and the dated levels of former editions).\n\nThe optional flags are sparse on the wire: present when true, absent\notherwise (the shape of the nomenclature layer's raw dicts)."
    },
    "RecordedLinkPayload": {
      "properties": {
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "The other segment's customs code."
        },
        "valid_from": {
          "type": "string",
          "title": "Valid From",
          "description": "The other segment's window start, ISO date."
        },
        "valid_to": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Valid To",
          "description": "The other segment's window end, ISO date; null when open."
        },
        "marker": {
          "type": "string",
          "title": "Marker",
          "description": "Eurostat's relation marker, as recorded."
        },
        "match": {
          "$ref": "#/$defs/WireEnum_LinkMatch_",
          "description": "'matched' when the endpoint resolves to a recorded segment by its full window, 'unmatched' otherwise (never attached to a guessed segment)."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "customs_code",
        "valid_from",
        "valid_to",
        "marker",
        "match"
      ],
      "title": "RecordedLinkPayload",
      "description": "One recorded predecessor/successor edge of an exact segment."
    },
    "RecordedLinksPayload": {
      "properties": {
        "successors": {
          "items": {
            "$ref": "#/$defs/RecordedLinkPayload"
          },
          "type": "array",
          "title": "Successors",
          "description": "Edges recorded from this segment."
        },
        "predecessors": {
          "items": {
            "$ref": "#/$defs/RecordedLinkPayload"
          },
          "type": "array",
          "title": "Predecessors",
          "description": "Edges recorded into this segment."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "successors",
        "predecessors"
      ],
      "title": "RecordedLinksPayload"
    },
    "SegmentHistoryEntry": {
      "properties": {
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "The customs code the segment defines."
        },
        "valid_from": {
          "type": "string",
          "title": "Valid From",
          "description": "First day of the segment's validity window, ISO date."
        },
        "valid_to": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Valid To",
          "description": "Last day of the window, ISO date; null for a segment still in force."
        },
        "kind": {
          "$ref": "#/$defs/WireEnum_SegmentKind_",
          "description": "The classification row's kind ('cn', 'residual_xx', 'letter_coded')."
        },
        "label": {
          "type": "string",
          "title": "Label",
          "description": "The segment's own label (the definition in force during its window), in the requested language when available."
        },
        "label_lang": {
          "type": "string",
          "enum": [
            "bg",
            "cs",
            "da",
            "de",
            "el",
            "en",
            "es",
            "et",
            "fi",
            "fr",
            "ga",
            "hr",
            "hu",
            "it",
            "lt",
            "lv",
            "mt",
            "nl",
            "pl",
            "pt",
            "ro",
            "sk",
            "sl",
            "sv"
          ],
          "title": "Label Lang",
          "description": "The label's language (English when the requested one is not recorded for this definition)."
        },
        "untranslated": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Untranslated",
          "description": "True when the label fell back to English."
        },
        "recorded_links": {
          "$ref": "#/$defs/RecordedLinksPayload",
          "description": "Direct correspondence edges recorded for this exact definition. An empty list means no recorded direct link -- not that the code never changed (headings have no edges of their own)."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "customs_code",
        "valid_from",
        "valid_to",
        "kind",
        "label",
        "label_lang",
        "recorded_links"
      ],
      "title": "SegmentHistoryEntry",
      "description": "One recorded definition of a customs code with its direct recorded\nlinks (``SegmentHistoryPayload.segments``)."
    },
    "SegmentHistoryPayload": {
      "properties": {
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "The base customs code."
        },
        "metadata_generation": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Metadata Generation",
          "description": "The classification snapshot the history comes from."
        },
        "segments": {
          "items": {
            "$ref": "#/$defs/SegmentHistoryEntry"
          },
          "type": "array",
          "title": "Segments",
          "description": "The definitions, oldest first."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "customs_code",
        "metadata_generation",
        "segments"
      ],
      "title": "SegmentHistoryPayload",
      "description": "Every recorded definition of one customs code (the CN classification\nfiles), independent of the current edition."
    },
    "SegmentPayload": {
      "properties": {
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "The customs code the segment defines."
        },
        "valid_from": {
          "type": "string",
          "title": "Valid From",
          "description": "First day of the segment's validity window, ISO date."
        },
        "valid_to": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Valid To",
          "description": "Last day of the window, ISO date; null for a segment still in force."
        },
        "kind": {
          "$ref": "#/$defs/WireEnum_SegmentKind_",
          "description": "The classification row's kind ('cn', 'residual_xx', 'letter_coded')."
        },
        "label": {
          "type": "string",
          "title": "Label",
          "description": "The segment's own label (the definition in force during its window), in the requested language when available."
        },
        "label_lang": {
          "type": "string",
          "enum": [
            "bg",
            "cs",
            "da",
            "de",
            "el",
            "en",
            "es",
            "et",
            "fi",
            "fr",
            "ga",
            "hr",
            "hu",
            "it",
            "lt",
            "lv",
            "mt",
            "nl",
            "pl",
            "pt",
            "ro",
            "sk",
            "sl",
            "sv"
          ],
          "title": "Label Lang",
          "description": "The label's language (English when the requested one is not recorded for this definition)."
        },
        "untranslated": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Untranslated",
          "description": "True when the label fell back to English."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "customs_code",
        "valid_from",
        "valid_to",
        "kind",
        "label",
        "label_lang"
      ],
      "title": "SegmentPayload",
      "description": "One recorded definition of a customs code: a fact of the\nclassification metadata, with its window and its own label."
    },
    "SegmentWindow": {
      "properties": {
        "valid_from": {
          "type": "string",
          "title": "Valid From",
          "description": "First day of the window, ISO date."
        },
        "valid_to": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Valid To",
          "description": "Last day of the window, ISO date; null while in force."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "valid_from",
        "valid_to"
      ],
      "title": "SegmentWindow",
      "description": "The validity window of one customs-code segment (one definition)."
    },
    "SubcodeRow": {
      "properties": {
        "basket_key": {
          "type": "string",
          "title": "Basket Key",
          "description": "The key of this row's basket in the payload's per-sub-code maps: the sub-code (read over the parent piece's window), or the entered basket's label."
        },
        "customs_code": {
          "type": "string",
          "title": "Customs Code",
          "description": "The sub-code (or residual spelling)."
        },
        "label": {
          "type": "string",
          "title": "Label",
          "description": "The label of the row's (latest) definition, in the requested language when recorded."
        },
        "untranslated": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Untranslated",
          "description": "True when the label fell back to English."
        },
        "segments": {
          "items": {
            "$ref": "#/$defs/SegmentPayload"
          },
          "type": "array",
          "title": "Segments",
          "description": "The definitions in force during the basket's window (empty for residual rows and for validation rows)."
        },
        "residual_kind": {
          "anyOf": [
            {
              "$ref": "#/$defs/WireEnum_ResidualKind_"
            },
            {
              "type": "null"
            }
          ],
          "description": "For a residual row: 'xx' or 'letter'. Residual rows explain the gap between the sub-codes and the parent, and are pinned outside the top-N ranking."
        },
        "residual_spelling": {
          "anyOf": [
            {
              "$ref": "#/$defs/WireEnum_ResidualSpelling_"
            },
            {
              "type": "null"
            }
          ],
          "description": "For a residual row: 'xx', 'letter' or 'reason_group'."
        },
        "residual_reason": {
          "anyOf": [
            {
              "$ref": "#/$defs/WireEnum_ResidualReason_"
            },
            {
              "type": "null"
            }
          ],
          "description": "For a letter code or reason group: the reason letter (S, Y, E, I, …)."
        },
        "in_eurostat_api": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "In Eurostat Api",
          "description": "For a residual row: whether Eurostat's API serves the spelling as a PRODUCT value (XX codes only)."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "basket_key",
        "customs_code",
        "label",
        "segments"
      ],
      "title": "SubcodeRow",
      "description": "One sub-code or residual customs code row, shared by breakdown views\n(``subcode-compare``, ``concentration-compare``, ``volatility``) and\nvalidation responses (``ValidateCustomsCodeResponse.residual_customs_codes``)."
    },
    "WireEnum_LinkMatch_": {
      "type": "string",
      "enum": [
        "matched",
        "unmatched"
      ],
      "title": "LinkMatch"
    },
    "WireEnum_ResidualKind_": {
      "type": "string",
      "enum": [
        "xx",
        "letter"
      ],
      "title": "ResidualKind"
    },
    "WireEnum_ResidualReason_": {
      "type": "string",
      "enum": [
        "A",
        "B",
        "C",
        "E",
        "F",
        "I",
        "M",
        "P",
        "R",
        "S",
        "T",
        "V",
        "W",
        "Y"
      ],
      "title": "ResidualReason"
    },
    "WireEnum_ResidualSpelling_": {
      "type": "string",
      "enum": [
        "xx",
        "letter",
        "reason_group"
      ],
      "title": "ResidualSpelling"
    },
    "WireEnum_SegmentKind_": {
      "type": "string",
      "enum": [
        "cn",
        "residual_xx",
        "letter_coded",
        "chapter_00",
        "other"
      ],
      "title": "SegmentKind",
      "description": "The ingest classification of one CN.txt identity."
    }
  }
}