{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.baijimu.com/contracts/cmodel-error.schema.json",
  "title": "Baijimu CModel response",
  "description": "Versioned three-field response envelope for Baijimu-owned non-streaming HTTP and Module boundaries. Valid CModel success and business-failure envelopes use HTTP 200, and errorCode alone expresses the business outcome. Failure data is null or a standard public detail object containing message and retryable. A missing contractVersion is interpreted as 1.0.0; an explicit version must equal 1.0.0. Consumers ignore unknown top-level fields.",
  "type": "object",
  "required": [
    "errorCode",
    "data"
  ],
  "properties": {
    "contractVersion": {
      "const": "1.0.0",
      "default": "1.0.0",
      "description": "Optional on input for compatibility. When omitted, consumers must normalize it to 1.0.0. Producers should emit it explicitly."
    },
    "errorCode": {
      "$ref": "#/$defs/errorCode"
    },
    "data": true
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "errorCode": {
            "const": "0"
          }
        },
        "required": [
          "errorCode"
        ]
      },
      "else": {
        "properties": {
          "data": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/$defs/failureData"
              }
            ]
          },
          "errorCode": {
            "pattern": "^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$"
          }
        }
      }
    }
  ],
  "$defs": {
    "errorCode": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^(?:0|[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*)$"
    },
    "failureData": {
      "type": "object",
      "description": "Public failure details. message is safe for direct user display; retryable states whether retrying the same operation without changing input or authorization can succeed. Consumers ignore unknown properties for forward compatibility.",
      "required": [
        "message",
        "retryable"
      ],
      "properties": {
        "message": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        },
        "retryable": {
          "type": "boolean"
        },
        "errorPath": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[^\\s\\u0000-\\u001f\\u007f-\\u009f]+$"
          },
          "description": "Optional service-level error return path, ordered outermost service to source. Only documented public logical identities may be exposed. Repeated identities are allowed; never used for business classification."
        }
      }
    }
  }
}
