{
  "openapi": "3.0.3",
  "info": {
    "title": "DNGate Developer API",
    "version": "1.0.0",
    "description": "List your domains, manage DNS records and nameservers. Create a key in the app under Profile → API access."
  },
  "servers": [
    {
      "url": "https://dngate.io"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key (dgk_…)"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ]
      },
      "Domain": {
        "type": "object",
        "properties": {
          "domain": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "registrar": {
            "type": "string"
          },
          "registration_date": {
            "type": "string",
            "format": "date-time"
          },
          "expiry_date": {
            "type": "string",
            "format": "date-time"
          },
          "auto_renew": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Record": {
        "type": "object",
        "required": [
          "name",
          "type",
          "data"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Record name; \"@\" is the zone apex. \"\", the bare domain and \"www.example.com\" forms are normalized."
          },
          "type": {
            "type": "string",
            "enum": [
              "A",
              "AAAA",
              "CNAME",
              "MX",
              "TXT",
              "NS",
              "SRV",
              "CAA"
            ]
          },
          "ttl": {
            "type": "integer",
            "minimum": 60,
            "maximum": 86400
          },
          "data": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/domains": {
      "get": {
        "summary": "List domains in the key account",
        "responses": {
          "200": {
            "description": "Domain list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "domains": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Domain"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/domains/{domain}/records": {
      "parameters": [
        {
          "name": "domain",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "ASCII/Punycode domain name"
        }
      ],
      "get": {
        "summary": "List DNS records",
        "responses": {
          "200": {
            "description": "Records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "domain": {
                      "type": "string"
                    },
                    "records": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Record"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "not_owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "zone_not_found (with nameservers + usesRegistrarDns)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Add a DNS record",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Record"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "validation_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Update a record (match locates it — no record ids upstream)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "match",
                  "record"
                ],
                "properties": {
                  "match": {
                    "allOf": [
                      {
                        "$ref": "#/components/schemas/Record"
                      }
                    ],
                    "description": "name/type/data locate the old record; ttl ignored"
                  },
                  "record": {
                    "$ref": "#/components/schemas/Record"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a record (query params, or JSON body for TXT-heavy payloads)",
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "data",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required — records are addressed by ⟨name,type,data⟩"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "type",
                  "data"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Record name; \"@\" is the zone apex. \"\", the bare domain and \"www.example.com\" forms are normalized."
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "A",
                      "AAAA",
                      "CNAME",
                      "MX",
                      "TXT",
                      "NS",
                      "SRV",
                      "CAA"
                    ]
                  },
                  "ttl": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 86400
                  },
                  "data": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/domains/{domain}/nameservers": {
      "parameters": [
        {
          "name": "domain",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "List nameservers",
        "responses": {
          "200": {
            "description": "Nameserver set",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "domain": {
                      "type": "string"
                    },
                    "nameservers": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Replace the full nameserver set (1–13 hosts)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "nameservers"
                ],
                "properties": {
                  "nameservers": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 13,
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replaced",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "domain_tokenized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
