{
  "openapi": "3.2.0",
  "info": {
    "title": "API Registrar NIC Monaco",
    "version": "1.0.0",
    "description": "API officielle d'interfaçage de l'espace registrar NIC Monaco pour les\nbureaux d'enregistrement : gestion des domaines, des contacts, de la fiche\ndu bureau et suivi des demandes.\n\n## Authentification\n\nChaque requête doit porter un jeton d'API dans l'en-tête HTTP :\n\n```\nAuthorization: Bearer ksl_...\n```\n\nLes jetons sont créés dans l'espace registrar (**Paramètres → Jetons\nd'API**, page `/api-tokens`). Le jeton n'est affiché qu'une seule fois à\nsa création : conservez-le dans un coffre de secrets. Il peut être révoqué\nà tout moment depuis la même page. Maximum 5 jetons actifs par bureau.\n\n## Portées et droits\n\n* `read` : consultation (toutes les routes `GET`).\n* `write` : dépôt de demandes (toutes les routes `POST`), à cocher à la\n  création du jeton.\n\nUn jeton agit **au nom de l'utilisateur qui l'a créé** et hérite de ses\ndroits dans l'espace registrar (ex. `domains.register`, `contacts.manage`).\nIl ne peut jamais faire plus que lui. Si ce créateur est bloqué ou quitte\nle bureau, le jeton cesse de fonctionner.\n\nToutes les réponses sont limitées au bureau porteur du jeton : un domaine,\nun contact ou une demande d'un autre bureau répond `404`.\n\n## Demandes et validation par le registre\n\nComme dans l'interface web, **aucune écriture n'est appliquée\nimmédiatement** : chaque route `POST` crée une *demande* (réponse `202`\navec un `request_id`), validée ou refusée par le registre. Suivez-la avec\n`GET /api/v1/requests/detail?id=…`. Tant qu'une demande est en attente,\nles fiches exposent les valeurs demandées dans `pending_changes`.\n\n## Quotas\n\n600 requêtes par heure et par jeton (HTTP 429 avec en-tête Retry-After\nau-delà). L'automatisation de l'interface web (hors API) est interdite.\n\n## Format\n\nCorps de requête en JSON (`Content-Type: application/json`), réponses en\nJSON UTF-8. Les erreurs suivent le schéma `Error` :\n`{\"error\": \"<code>\", \"message\": \"<détail>\", \"details\": {…}}` — `details`\nliste les erreurs par champ pour les réponses `422`. Les messages\nd'erreur sont rédigés en français.\n"
  },
  "servers": [
    {
      "url": "/",
      "description": "Serveur courant (même domaine que l'espace registrar)"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Compte",
      "description": "Identité et diagnostic du jeton"
    },
    {
      "name": "Bureau",
      "description": "Fiche du bureau d'enregistrement"
    },
    {
      "name": "Domaines",
      "description": "Consultation et demandes sur les noms de domaine du bureau"
    },
    {
      "name": "Contacts",
      "description": "Contacts (titulaires, administratifs, techniques) du bureau"
    },
    {
      "name": "Demandes",
      "description": "Suivi et annulation des demandes déposées"
    }
  ],
  "paths": {
    "/api/v1/me": {
      "get": {
        "tags": [
          "Compte"
        ],
        "summary": "Identité du jeton",
        "description": "Bureau, utilisateur et portées du jeton. Endpoint de test recommandé pour valider une intégration.",
        "operationId": "getMe",
        "responses": {
          "200": {
            "description": "Identité du jeton",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/v1/registrar": {
      "get": {
        "tags": [
          "Bureau"
        ],
        "summary": "Fiche du bureau",
        "description": "Coordonnées du bureau et modifications en attente de validation. Portée `read`.",
        "operationId": "getRegistrar",
        "responses": {
          "200": {
            "description": "Fiche du bureau",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Registrar"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/api/v1/registrar/update": {
      "post": {
        "tags": [
          "Bureau"
        ],
        "summary": "Demander la modification de la fiche du bureau",
        "description": "Seuls les champs fournis sont modifiés. Portée `write`, droit `registrar.manage`.",
        "operationId": "updateRegistrar",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegistrarUpdate"
              },
              "example": {
                "phone": "+377 93 00 00 00",
                "billing_email": "billing@registrar.mc"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/NoChange"
          },
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/v1/domains": {
      "get": {
        "tags": [
          "Domaines"
        ],
        "summary": "Liste des domaines du bureau",
        "description": "Domaines du bureau (hors archivés), triés par nom. Portée `read`, droit `domains.view`.",
        "operationId": "listDomains",
        "responses": {
          "200": {
            "description": "Domaines du bureau",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainCollection"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/v1/domains/detail": {
      "get": {
        "tags": [
          "Domaines"
        ],
        "summary": "Fiche d'un domaine",
        "description": "Contacts, serveurs DNS, DNSSEC, demandes en attente et état effectif\n(valeurs en base + demandes en attente). Portée `read`, droit `domains.view`.\n",
        "operationId": "getDomain",
        "parameters": [
          {
            "$ref": "#/components/parameters/DomainQuery"
          }
        ],
        "responses": {
          "200": {
            "description": "Fiche du domaine",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/domains/check": {
      "get": {
        "tags": [
          "Domaines"
        ],
        "summary": "Vérifier la disponibilité d'un nom",
        "description": "Mêmes contrôles que le formulaire d'enregistrement. Portée `read`.",
        "operationId": "checkDomain",
        "parameters": [
          {
            "$ref": "#/components/parameters/DomainQuery"
          }
        ],
        "responses": {
          "200": {
            "description": "Résultat de la vérification",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainCheck"
                },
                "examples": {
                  "available": {
                    "value": {
                      "domain": "new-name.mc",
                      "available": true,
                      "reason": null
                    }
                  },
                  "taken": {
                    "value": {
                      "domain": "example.mc",
                      "available": false,
                      "reason": "already_registered"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/create": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Demander l'enregistrement d'un domaine",
        "description": "Les trois contacts doivent appartenir au bureau (un contact dont la\ncréation est en attente est accepté). Au moins deux serveurs DNS, huit\nau maximum. `auto_renew` vaut par défaut le réglage du bureau.\nPortée `write`, droit `domains.register`.\n",
        "operationId": "createDomain",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DomainCreate"
              },
              "example": {
                "domain": "new-name.mc",
                "auto_renew": true,
                "contacts": {
                  "holder": "DUPO1-MC",
                  "admin": "DUPO1-MC",
                  "tech": "TECH3-MC"
                },
                "nameservers": [
                  "ns1.host.mc",
                  "ns2.host.mc"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/v1/domains/update": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Demander la modification d'un domaine",
        "description": "Seuls les champs fournis sont modifiés. `nameservers` remplace la liste\ncomplète ; `dnssec: null` supprime le DNSSEC. Refusé (409) si le domaine\nest gelé, bloqué, expiré, supprimé ou en cours de transfert.\nPortée `write`, droit `domains.register`.\n",
        "operationId": "updateDomain",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DomainUpdate"
              },
              "example": {
                "domain": "example.mc",
                "contacts": {
                  "tech": "TECH3-MC"
                },
                "nameservers": [
                  "ns1.new-host.mc",
                  "ns2.new-host.mc"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/NoChange"
          },
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/v1/domains/renew": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Demander le renouvellement d'un domaine (1 an)",
        "description": "Possible si l'expiration est à moins de 365 jours. Un renouvellement\nautomatique actif est désactivé dans la même demande.\nPortée `write`, droit `domains.renew`.\n",
        "operationId": "renewDomain",
        "requestBody": {
          "$ref": "#/components/requestBodies/DomainOnly"
        },
        "responses": {
          "202": {
            "description": "Demande créée",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/RequestCreated"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "new_expires_at": {
                          "type": "string",
                          "format": "date",
                          "example": "2028-03-14"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/api/v1/domains/delete": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Demander la suppression d'un domaine",
        "description": "Portée `write`, droit `domains.delete`.",
        "operationId": "deleteDomain",
        "requestBody": {
          "$ref": "#/components/requestBodies/DomainOnly"
        },
        "responses": {
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/domains/reactivate": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Demander la réactivation d'un domaine expiré ou supprimé",
        "description": "Portée `write`, droit `domains.renew`.",
        "operationId": "reactivateDomain",
        "requestBody": {
          "$ref": "#/components/requestBodies/DomainOnly"
        },
        "responses": {
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/api/v1/domains/authcode": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Générer un code de transfert",
        "description": "Code valable 48 h, à communiquer au bureau entrant. Il n'est retourné\nqu'une fois (stocké haché) ; en générer un nouveau annule le précédent.\nPortée `write`, droit `domains.authcode`.\n",
        "operationId": "createAuthCode",
        "requestBody": {
          "$ref": "#/components/requestBodies/DomainOnly"
        },
        "responses": {
          "201": {
            "description": "Code généré",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthCode"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/domains/authcode/cancel": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Annuler le code de transfert actif",
        "description": "Portée `write`, droit `domains.authcode`.",
        "operationId": "cancelAuthCode",
        "requestBody": {
          "$ref": "#/components/requestBodies/DomainOnly"
        },
        "responses": {
          "200": {
            "description": "Code annulé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "cancelled": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/domains/transfer": {
      "post": {
        "tags": [
          "Domaines"
        ],
        "summary": "Demander le transfert entrant d'un domaine",
        "description": "Transfère vers le bureau du jeton un domaine d'un autre bureau, avec le\ncode fourni par le bureau sortant (consommé à l'enregistrement de la\ndemande). Les contacts doivent appartenir à votre bureau : créez-les au\nbesoin avec `POST /api/v1/contacts/create`. Portée `write`, droit\n`domains.transfer`.\n",
        "operationId": "transferDomain",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DomainTransfer"
              },
              "example": {
                "domain": "example.mc",
                "auth_code": "48213907561234098765",
                "contacts": {
                  "holder": "DUPO1-MC",
                  "admin": "DUPO1-MC",
                  "tech": "TECH3-MC"
                },
                "nameservers": [
                  "ns1.host.mc",
                  "ns2.host.mc"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/v1/contacts": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "summary": "Liste des contacts du bureau",
        "description": "Recherche sur nichandle, nom, prénom ou email. Portée `read`, droit `contacts.view`.",
        "operationId": "listContacts",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Texte recherché"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Contacts du bureau",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactCollection"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/api/v1/contacts/detail": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "summary": "Fiche d'un contact",
        "description": "Coordonnées, modifications en attente et domaines du bureau où le contact intervient. Portée `read`, droit `contacts.view`.",
        "operationId": "getContact",
        "parameters": [
          {
            "$ref": "#/components/parameters/NichandleQuery"
          }
        ],
        "responses": {
          "200": {
            "description": "Fiche du contact",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/contacts/create": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "summary": "Demander la création d'un contact",
        "description": "Nom ou société obligatoire ; email ou téléphone obligatoire. Le\nnichandle est attribué immédiatement : il peut être utilisé tout de\nsuite dans une demande d'enregistrement ou de transfert.\nPortée `write`, droit `contacts.manage`.\n",
        "operationId": "createContact",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactCreate"
              },
              "example": {
                "last_name": "Dupont",
                "first_name": "Marie",
                "address1": "1 avenue des Fleurs",
                "postal_code": "98000",
                "city": "Monaco",
                "country": "MC",
                "email": "marie.dupont@example.mc"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Demande créée",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/RequestCreated"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "nichandle": {
                          "type": "string",
                          "example": "DUPO1-MC"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/v1/contacts/update": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "summary": "Demander la modification d'un contact",
        "description": "Seuls les champs fournis sont modifiés. Nom, prénom et société ne sont\nplus modifiables après création (422). Portée `write`, droit `contacts.manage`.\n",
        "operationId": "updateContact",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactUpdate"
              },
              "example": {
                "nichandle": "DUPO1-MC",
                "email": "new.address@example.mc"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/NoChange"
          },
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/v1/contacts/delete": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "summary": "Demander la suppression d'un contact",
        "description": "Impossible tant que le contact est lié à un domaine (409). Portée `write`, droit `contacts.manage`.",
        "operationId": "deleteContact",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "nichandle"
                ],
                "properties": {
                  "nichandle": {
                    "type": "string",
                    "example": "DUPO1-MC"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "$ref": "#/components/responses/RequestCreated"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/api/v1/requests": {
      "get": {
        "tags": [
          "Demandes"
        ],
        "summary": "Liste des demandes du bureau",
        "description": "Demandes en attente (défaut) ou traitées, les plus récentes d'abord. Portée `read`, droit `requests.view`.",
        "operationId": "listRequests",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "completed"
              ],
              "default": "pending"
            }
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Demandes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RequestCollection"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/api/v1/requests/detail": {
      "get": {
        "tags": [
          "Demandes"
        ],
        "summary": "Détail d'une demande",
        "description": "Statut et liste des changements demandés. Pour un transfert entrant,\nles anciennes valeurs du bureau sortant (bureau, contacts) ne sont pas\ncommuniquées. Portée `read`, droit `requests.view`.\n",
        "operationId": "getRequest",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "example": 260930004
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Détail de la demande",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RequestDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/requests/cancel": {
      "post": {
        "tags": [
          "Demandes"
        ],
        "summary": "Annuler une demande en attente",
        "description": "Réservé aux demandes créées par l'utilisateur du jeton, non encore\ntraitées. Les pièces justificatives associées sont supprimées.\nPortée `write`, droit `requests.delete`.\n",
        "operationId": "cancelRequest",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id"
                ],
                "properties": {
                  "id": {
                    "type": "integer",
                    "example": 260930004
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Demande annulée",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "request_id": {
                      "type": "integer"
                    },
                    "cancelled": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Jeton d'API du bureau (`ksl_` suivi de 64 caractères hexadécimaux), créé sur /api-tokens."
      }
    },
    "parameters": {
      "DomainQuery": {
        "name": "domain",
        "in": "query",
        "required": true,
        "description": "Nom de domaine complet",
        "schema": {
          "type": "string",
          "example": "example.mc"
        }
      },
      "NichandleQuery": {
        "name": "nichandle",
        "in": "query",
        "required": true,
        "schema": {
          "type": "string",
          "example": "DUPO1-MC"
        }
      },
      "Page": {
        "name": "page",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 1
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200,
          "default": 50
        }
      }
    },
    "requestBodies": {
      "DomainOnly": {
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "domain"
              ],
              "properties": {
                "domain": {
                  "type": "string",
                  "example": "example.mc"
                }
              }
            }
          }
        }
      }
    },
    "responses": {
      "RequestCreated": {
        "description": "Demande créée, en attente de validation par le registre",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/RequestCreated"
            }
          }
        }
      },
      "NoChange": {
        "description": "Aucune différence avec l'état actuel, aucune demande créée",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "request_id": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "example": null
                },
                "message": {
                  "type": "string",
                  "example": "Aucune modification"
                }
              }
            }
          }
        }
      },
      "BadRequest": {
        "description": "Paramètre manquant ou mal formé",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "invalid_request",
              "message": "Paramètre 'domain' manquant"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Jeton manquant, invalide, révoqué, expiré, ou créateur inactif",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "unauthorized",
              "message": "Jeton invalide, révoqué ou expiré"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Portée du jeton ou droit de son créateur insuffisant",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "forbidden",
              "message": "Scope 'write' requis pour ce jeton"
            }
          }
        }
      },
      "NotFound": {
        "description": "Ressource inexistante ou appartenant à un autre bureau",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "not_found",
              "message": "Domaine introuvable pour ce bureau"
            }
          }
        }
      },
      "Conflict": {
        "description": "Opération impossible dans l'état actuel",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "conflict",
              "message": "Renouvellement impossible : expiration à plus de 365 jours"
            }
          }
        }
      },
      "ValidationFailed": {
        "description": "Données refusées ; `details` liste les erreurs par champ",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "validation_failed",
              "message": "Demande refusée",
              "details": {
                "domain": "Ce domaine est déjà enregistré",
                "nameservers.1": "Serveur DNS invalide : ns2"
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Quota horaire du jeton atteint (600 requêtes/heure)",
        "headers": {
          "Retry-After": {
            "description": "Délai conseillé avant nouvel essai, en secondes",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "too_many_requests",
              "message": "Quota horaire du jeton atteint"
            }
          }
        }
      }
    },
    "schemas": {
      "Me": {
        "type": "object",
        "properties": {
          "registrar_id": {
            "type": "integer",
            "example": 42
          },
          "registrar": {
            "type": [
              "string",
              "null"
            ],
            "description": "Nichandle du bureau",
            "example": "REGISTRAR-NIC"
          },
          "token_label": {
            "type": "string",
            "example": "ERP sync"
          },
          "acting_as": {
            "type": "string",
            "description": "Utilisateur au nom duquel agit le jeton",
            "example": "JDUP1-MC"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "read",
                "write"
              ]
            },
            "example": [
              "read",
              "write"
            ]
          }
        }
      },
      "Registrar": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer",
                "example": 42
              },
              "nichandle": {
                "type": "string",
                "example": "REGISTRAR-NIC"
              },
              "name": {
                "type": "string",
                "description": "Désignation",
                "example": "Example Registrar SAM"
              }
            }
          },
          {
            "$ref": "#/components/schemas/RegistrarFields"
          },
          {
            "type": "object",
            "properties": {
              "pending_changes": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/RegistrarFields"
                  }
                ],
                "description": "Valeurs demandées, en attente de validation"
              }
            }
          }
        ]
      },
      "RegistrarFields": {
        "type": "object",
        "properties": {
          "address1": {
            "type": "string",
            "example": "1 boulevard Princesse Charlotte"
          },
          "address2": {
            "type": "string"
          },
          "postal_code": {
            "type": "string",
            "example": "98000"
          },
          "city": {
            "type": "string",
            "example": "Monaco"
          },
          "country": {
            "type": "string",
            "description": "Code pays ISO",
            "example": "MC"
          },
          "phone": {
            "type": "string",
            "example": "+377 93 00 00 00"
          },
          "phone2": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "billing_email": {
            "type": "string",
            "format": "email"
          },
          "directory_listed": {
            "type": "boolean",
            "description": "Présence dans l'annuaire public des bureaux"
          },
          "auto_renew_default": {
            "type": "boolean",
            "description": "Renouvellement automatique par défaut des nouveaux domaines"
          },
          "website": {
            "type": "string"
          },
          "public_name": {
            "type": "string"
          },
          "public_phone": {
            "type": "string"
          },
          "public_email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "RegistrarUpdate": {
        "allOf": [
          {
            "$ref": "#/components/schemas/RegistrarFields"
          }
        ],
        "description": "Champs à modifier (au moins un). address1, postal_code, city, email et phone ne peuvent pas être vidés."
      },
      "DomainStatus": {
        "type": "string",
        "enum": [
          "active",
          "frozen",
          "blocked",
          "deleted",
          "orphan",
          "expired",
          "archived"
        ],
        "example": "active"
      },
      "DomainCollection": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer"
          },
          "domains": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer",
                  "example": 1234
                },
                "domain": {
                  "type": "string",
                  "example": "example.mc"
                },
                "status": {
                  "$ref": "#/components/schemas/DomainStatus"
                },
                "expires_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "example": "2027-03-14"
                },
                "auto_renew": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "Contacts": {
        "type": "object",
        "properties": {
          "holder": {
            "type": "string",
            "description": "Nichandle du titulaire",
            "example": "DUPO1-MC"
          },
          "admin": {
            "type": "string",
            "description": "Nichandle du contact administratif",
            "example": "DUPO1-MC"
          },
          "tech": {
            "type": "string",
            "description": "Nichandle du contact technique",
            "example": "TECH3-MC"
          }
        }
      },
      "Dnssec": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "keytag": {
            "type": "string",
            "example": "12345"
          },
          "algorithm": {
            "type": "string",
            "example": "13"
          },
          "digest_type": {
            "type": "string",
            "example": "2"
          },
          "key_digest": {
            "type": "string",
            "example": "3F1A…"
          }
        }
      },
      "Nameservers": {
        "type": "array",
        "minItems": 2,
        "maxItems": 8,
        "items": {
          "type": "string",
          "example": "ns1.host.mc"
        }
      },
      "DomainDetail": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "domain": {
            "type": "string",
            "example": "example.mc"
          },
          "status": {
            "$ref": "#/components/schemas/DomainStatus"
          },
          "registered_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "auto_renew": {
            "type": "boolean"
          },
          "contacts": {
            "$ref": "#/components/schemas/Contacts"
          },
          "nameservers": {
            "$ref": "#/components/schemas/Nameservers"
          },
          "dnssec": {
            "$ref": "#/components/schemas/Dnssec"
          },
          "transfer_pending": {
            "type": "boolean",
            "description": "Transfert sortant en cours"
          },
          "pending_changes": {
            "type": "object",
            "description": "Valeurs demandées par votre bureau, en attente (clés : auto_renew, holder, admin, tech, nameservers, dnssec.*, expires_at, status…)",
            "additionalProperties": true
          },
          "effective": {
            "type": "object",
            "description": "État qui s'appliquera si les demandes en attente sont validées",
            "properties": {
              "auto_renew": {
                "type": "boolean"
              },
              "contacts": {
                "$ref": "#/components/schemas/Contacts"
              },
              "nameservers": {
                "$ref": "#/components/schemas/Nameservers"
              },
              "dnssec": {
                "$ref": "#/components/schemas/Dnssec"
              }
            }
          }
        }
      },
      "DomainCheck": {
        "type": "object",
        "properties": {
          "domain": {
            "type": "string"
          },
          "available": {
            "type": "boolean"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "invalid_extension",
              "invalid_syntax",
              "already_registered",
              "reserved",
              "bsa_blocked",
              "request_pending",
              null
            ]
          }
        }
      },
      "DomainCreate": {
        "type": "object",
        "required": [
          "domain",
          "contacts",
          "nameservers"
        ],
        "properties": {
          "domain": {
            "type": "string",
            "description": "Nom complet en .mc",
            "example": "new-name.mc"
          },
          "auto_renew": {
            "type": "boolean",
            "description": "Défaut = réglage du bureau"
          },
          "contacts": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Contacts"
              }
            ],
            "required": [
              "holder",
              "admin",
              "tech"
            ]
          },
          "nameservers": {
            "$ref": "#/components/schemas/Nameservers"
          },
          "dnssec": {
            "$ref": "#/components/schemas/Dnssec"
          }
        }
      },
      "DomainUpdate": {
        "type": "object",
        "required": [
          "domain"
        ],
        "properties": {
          "domain": {
            "type": "string",
            "example": "example.mc"
          },
          "auto_renew": {
            "type": "boolean"
          },
          "contacts": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Contacts"
              }
            ],
            "description": "Rôles à changer uniquement"
          },
          "nameservers": {
            "$ref": "#/components/schemas/Nameservers"
          },
          "dnssec": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Dnssec"
              }
            ],
            "description": "null pour supprimer le DNSSEC"
          }
        }
      },
      "DomainTransfer": {
        "type": "object",
        "required": [
          "domain",
          "auth_code",
          "contacts",
          "nameservers"
        ],
        "properties": {
          "domain": {
            "type": "string",
            "example": "example.mc"
          },
          "auth_code": {
            "type": "string",
            "description": "Code fourni par le bureau sortant"
          },
          "contacts": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Contacts"
              }
            ],
            "required": [
              "holder",
              "admin",
              "tech"
            ]
          },
          "nameservers": {
            "$ref": "#/components/schemas/Nameservers"
          }
        }
      },
      "AuthCode": {
        "type": "object",
        "properties": {
          "auth_code": {
            "type": "string",
            "example": "48213907561234098765"
          },
          "expires_at": {
            "type": "string",
            "example": "2026-10-02 14:30:00"
          }
        }
      },
      "ContactFields": {
        "type": "object",
        "properties": {
          "company": {
            "type": "string",
            "description": "Société (ou last_name obligatoire)"
          },
          "last_name": {
            "type": "string"
          },
          "first_name": {
            "type": "string"
          },
          "address1": {
            "type": "string"
          },
          "address2": {
            "type": "string"
          },
          "postal_code": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "description": "Code pays ISO",
            "example": "MC"
          },
          "phone": {
            "type": "string",
            "description": "Email ou téléphone obligatoire"
          },
          "phone2": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "Contact": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "nichandle": {
                "type": "string",
                "example": "DUPO1-MC"
              }
            }
          },
          {
            "$ref": "#/components/schemas/ContactFields"
          }
        ]
      },
      "ContactCollection": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer",
            "description": "Total (toutes pages)"
          },
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "contacts": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Contact"
                },
                {
                  "type": "object",
                  "properties": {
                    "domain_count": {
                      "type": "integer"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "ContactDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Contact"
          },
          {
            "type": "object",
            "properties": {
              "pending_changes": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/ContactFields"
                  }
                ],
                "description": "Valeurs demandées par votre bureau, en attente de validation"
              },
              "domains": {
                "type": "array",
                "description": "Domaines de votre bureau où le contact intervient",
                "items": {
                  "type": "object",
                  "properties": {
                    "domain": {
                      "type": "string",
                      "example": "example.mc"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "holder",
                        "admin",
                        "tech",
                        "other"
                      ]
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "ContactCreate": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ContactFields"
          }
        ],
        "required": [
          "address1",
          "postal_code",
          "city",
          "country"
        ]
      },
      "ContactUpdate": {
        "type": "object",
        "required": [
          "nichandle"
        ],
        "properties": {
          "nichandle": {
            "type": "string",
            "example": "DUPO1-MC"
          },
          "address1": {
            "type": "string"
          },
          "address2": {
            "type": "string"
          },
          "postal_code": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "phone2": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "RequestCreated": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "integer",
            "description": "Numéro de la demande",
            "example": 260930004
          },
          "status": {
            "type": "string",
            "enum": [
              "pending"
            ],
            "example": "pending"
          }
        }
      },
      "RequestSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 260930004
          },
          "type": {
            "type": "string",
            "enum": [
              "creation",
              "modification",
              "deletion",
              "transfer",
              "renewal",
              "reactivation"
            ]
          },
          "object": {
            "type": "string",
            "enum": [
              "domain",
              "contact",
              "registrar"
            ]
          },
          "subject": {
            "type": [
              "string",
              "null"
            ],
            "description": "Nom de domaine ou nichandle concerné",
            "example": "new-name.mc"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "rejected"
            ]
          },
          "submitted_at": {
            "type": "string",
            "example": "2026-09-30 10:12:44"
          },
          "processed_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "submitted_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "Utilisateur ayant déposé la demande"
          }
        }
      },
      "RequestCollection": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "requests": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RequestSummary"
            }
          }
        }
      },
      "RequestDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/RequestSummary"
          },
          {
            "type": "object",
            "properties": {
              "changes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "field": {
                      "type": "string",
                      "example": "DNS1"
                    },
                    "old": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "new": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_request",
              "unauthorized",
              "forbidden",
              "not_found",
              "conflict",
              "validation_failed",
              "too_many_requests",
              "unavailable",
              "server_error"
            ]
          },
          "message": {
            "type": "string",
            "description": "Détail lisible (en français)"
          },
          "details": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Erreurs par champ (422)"
          }
        }
      }
    }
  }
}
