{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/conjure/latest.json",
  "x-lintel": {
    "source": "https://raw.githubusercontent.com/palantir/conjure/master/conjure.schema.json",
    "sourceSha256": "00bac1e33f5de0ee7011ab6a38eda96e05b30ab3484c12e309be80fe1370a5a6",
    "fileMatch": [
      "**/conjure/**.yml"
    ],
    "parsers": [
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "types": {
      "$ref": "#/$defs/TypesDefinition"
    },
    "services": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/ServiceDefinition"
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "TypesDefinition": {
      "type": "object",
      "properties": {
        "conjure-imports": {
          "type": "object",
          "description": "A map between a namespace and a relative path to a Conjure definition file.",
          "additionalProperties": false,
          "patternProperties": {
            "^[_a-zA-Z][_a-zA-Z0-9]*$": {
              "type": "string"
            }
          }
        },
        "imports": {
          "type": "object",
          "description": "A map between a type alias and its external definition. Type aliases MUST be in PascalCase.",
          "additionalProperties": {
            "$ref": "#/$defs/ExternalTypeDefinition"
          }
        },
        "definitions": {
          "$ref": "#/$defs/NamedTypesDefinition",
          "description": "The types specified in this definition."
        }
      },
      "additionalProperties": false
    },
    "ExternalTypeDefinition": {
      "type": "object",
      "properties": {
        "base-type": {
          "$ref": "#/$defs/ConjureType",
          "description": "A base-type is provided as a hint to generators for how to handle this type when no external type reference is provided. Note that the serialization format of the base-type fallback should match the format of the imported type. If the imported type is a non-primitive JSON object, then a base-type of any should be used."
        },
        "external": {
          "$ref": "#/$defs/ExternalImportDefinition",
          "description": "The external types to reference."
        }
      },
      "additionalProperties": false
    },
    "ExternalImportDefinition": {
      "type": "object",
      "description": "References to types that are not defined within Conjure.",
      "properties": {
        "java": {
          "description": "The fully qualified Java type.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "NamedTypesDefinition": {
      "type": "object",
      "properties": {
        "default-package": {
          "type": "string"
        },
        "objects": {
          "type": "object",
          "additionalProperties": false,
          "propertyNames": {
            "$ref": "#/$defs/TypeName"
          },
          "patternProperties": {
            "": {
              "oneOf": [
                {
                  "$ref": "#/$defs/AliasDefinition"
                },
                {
                  "$ref": "#/$defs/ObjectTypeDefinition"
                },
                {
                  "$ref": "#/$defs/UnionTypeDefinition"
                },
                {
                  "$ref": "#/$defs/EnumTypeDefinition"
                }
              ]
            }
          }
        },
        "errors": {
          "type": "object",
          "additionalProperties": false,
          "propertyNames": {
            "$ref": "#/$defs/TypeName"
          },
          "patternProperties": {
            "": {
              "$ref": "#/$defs/ErrorDefinition"
            }
          }
        }
      },
      "additionalProperties": false
    },
    "ConjureType": {
      "anyOf": [
        {
          "$ref": "#/$defs/TypeName"
        },
        {
          "$ref": "#/$defs/ContainerType"
        },
        {
          "$ref": "#/$defs/BuiltIn"
        }
      ]
    },
    "TypeName": {
      "description": "Named types must be in PascalCase and be unique within a package.",
      "type": "string",
      "pattern": "^([a-zA-Z]+[.])?[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$"
    },
    "ContainerType": {
      "description": "Container types like optional<T>, list<T>, set<T> and map<K, V> can be referenced using their lowercase names, where variables like T, K and V can be substituted for a Conjure named type, a built-in or more container types:",
      "type": "string",
      "pattern": "^(optional|list|set|map)<.*>$"
    },
    "BuiltIn": {
      "enum": [
        "any",
        "bearertoken",
        "binary",
        "boolean",
        "datetime",
        "double",
        "integer",
        "rid",
        "safelong",
        "string",
        "uuid"
      ]
    },
    "AliasDefinition": {
      "type": "object",
      "required": [
        "alias"
      ],
      "properties": {
        "alias": {
          "description": "The Conjure type to be aliased.",
          "$ref": "#/$defs/ConjureType"
        },
        "safety": {
          "$ref": "#/$defs/LogSafety"
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "package": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ObjectTypeDefinition": {
      "type": "object",
      "required": [
        "fields"
      ],
      "properties": {
        "fields": {
          "additionalProperties": {
            "anyOf": [
              {
                "$ref": "#/$defs/FieldDefinition"
              },
              {
                "$ref": "#/$defs/ConjureType"
              }
            ]
          }
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "package": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "FieldDefinition": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "$ref": "#/$defs/ConjureType"
        },
        "safety": {
          "$ref": "#/$defs/LogSafety"
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "package": {
          "type": "string"
        },
        "deprecated": {
          "$ref": "#/$defs/DocString"
        }
      },
      "additionalProperties": false
    },
    "UnionTypeDefinition": {
      "type": "object",
      "required": [
        "union"
      ],
      "properties": {
        "union": {
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "$ref": "#/$defs/FieldDefinition"
              },
              {
                "$ref": "#/$defs/ConjureType"
              }
            ]
          }
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "package": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "EnumTypeDefinition": {
      "type": "object",
      "required": [
        "values"
      ],
      "properties": {
        "values": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/UpperCase"
              },
              {
                "$ref": "#/$defs/EnumValueDefinition"
              }
            ]
          }
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "package": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "EnumValueDefinition": {
      "type": "object",
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "$ref": "#/$defs/UpperCase"
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "package": {
          "type": "string"
        },
        "deprecated": {
          "$ref": "#/$defs/DocString"
        }
      },
      "additionalProperties": false
    },
    "ErrorDefinition": {
      "type": "object",
      "required": [
        "namespace",
        "code"
      ],
      "properties": {
        "namespace": {
          "$ref": "#/$defs/PascalCase"
        },
        "code": {
          "$ref": "#/$defs/ErrorCode"
        },
        "package": {
          "type": "string"
        },
        "safe-args": {
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "$ref": "#/$defs/FieldDefinition"
              },
              {
                "$ref": "#/$defs/ConjureType"
              }
            ]
          }
        },
        "unsafe-args": {
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "$ref": "#/$defs/FieldDefinition"
              },
              {
                "$ref": "#/$defs/ConjureType"
              }
            ]
          }
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        }
      },
      "additionalProperties": false
    },
    "ErrorCode": {
      "enum": [
        "PERMISSION_DENIED",
        "INVALID_ARGUMENT",
        "NOT_FOUND",
        "CONFLICT",
        "REQUEST_ENTITY_TOO_LARGE",
        "FAILED_PRECONDITION",
        "INTERNAL",
        "TIMEOUT",
        "CUSTOM_CLIENT",
        "CUSTOM_SERVER"
      ]
    },
    "ServiceDefinition": {
      "type": "object",
      "required": [
        "package",
        "endpoints"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "package": {
          "type": "string"
        },
        "base-path": {
          "$ref": "#/$defs/PathString"
        },
        "default-auth": {
          "$ref": "#/$defs/AuthDefinition"
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "endpoints": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/EndpointDefinition"
          }
        }
      },
      "additionalProperties": false
    },
    "PathString": {
      "type": "string"
    },
    "AuthDefinition": {
      "oneOf": [
        {
          "enum": [
            "none",
            "header"
          ]
        },
        {
          "type": "string",
          "pattern": "^cookie:[a-zA-Z0-9]+$"
        }
      ]
    },
    "EndpointDefinition": {
      "type": "object",
      "required": [
        "http"
      ],
      "properties": {
        "http": {
          "type": "string",
          "pattern": "^(GET|DELETE|POST|PUT) .*$"
        },
        "auth": {
          "$ref": "#/$defs/AuthDefinition"
        },
        "returns": {
          "$ref": "#/$defs/ConjureType"
        },
        "errors": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/TypeName"
              },
              {
                "$ref": "#/$defs/EndpointError"
              }
            ]
          }
        },
        "args": {
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "$ref": "#/$defs/ArgumentDefinition"
              },
              {
                "$ref": "#/$defs/ConjureType"
              }
            ]
          }
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "deprecated": {
          "$ref": "#/$defs/DocString"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "ArgumentDefinition": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "$ref": "#/$defs/ConjureType"
        },
        "param-id": {
          "type": "string"
        },
        "param-type": {
          "$ref": "#/$defs/ArgumentDefinitionParamType"
        },
        "safety": {
          "$ref": "#/$defs/LogSafety"
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "markers": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "ArgumentDefinitionParamType": {
      "enum": [
        "auto",
        "path",
        "body",
        "header",
        "query"
      ]
    },
    "EndpointError": {
      "type": "object",
      "required": [
        "error"
      ],
      "properties": {
        "error": {
          "$ref": "#/$defs/TypeName"
        },
        "docs": {
          "$ref": "#/$defs/DocString"
        }
      },
      "additionalProperties": false
    },
    "DocString": {
      "type": "string"
    },
    "LogSafety": {
      "enum": [
        "safe",
        "unsafe",
        "do-not-log"
      ]
    },
    "UpperCase": {
      "pattern": "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"
    },
    "PascalCase": {
      "type": "string",
      "pattern": "^[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$"
    }
  }
}
