{
  "openapi": "3.1.0",
  "info": {
    "title": "SaaS RENTRI — sincronizzazione FIR su richiesta",
    "version": "1.1.0",
    "description": "Capacità nativa DEMO/PROD, con gate dedicati. Nessuna mutation del FIR o invio webhook nel POST. Il completamento può riutilizzare una lettura recente. PROD: richiede opt-in del modulo, deployment vincolato, capacità di lettura e certificato approvato; le mutazioni richiedono anche i gate di invio."
  },
  "x-post-performs-remote-read": false,
  "x-status-performs-remote-read": false,
  "x-delivery-is-separately-enabled": true,
  "paths": {
    "/api/v1/fir/{numero_fir}/sincronizzazione": {
      "post": {
        "operationId": "requestFirSynchronization",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "fir:read",
        "parameters": [
          {
            "name": "numero_fir",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Chiave non valida",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope/contesto non autorizzato",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "FIR o richiesta non appartenente al client",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Body/query non validi",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Quota HTTP: rispettare Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Gate o persistenza indisponibili",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Osservazione corrente riutilizzata; nessuna nuova lettura garantita",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncResponse"
                }
              }
            }
          },
          "202": {
            "description": "Richiesta accodata/accorpata; non conferma un aggiornamento",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "maxProperties": 0
              }
            }
          }
        }
      }
    },
    "/api/v1/fir/{numero_fir}/sincronizzazioni/{sync_id}": {
      "get": {
        "operationId": "getFirSynchronizationRequest",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "fir:read",
        "parameters": [
          {
            "name": "numero_fir",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sync_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^syn_[a-f0-9]{32}$"
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Chiave non valida",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope/contesto non autorizzato",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "FIR o richiesta non appartenente al client",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Body/query non validi",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Quota HTTP: rispettare Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Gate o persistenza indisponibili",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Stato locale della richiesta; nessuna interrogazione RENTRI",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "request_id",
          "error"
        ],
        "properties": {
          "request_id": {
            "type": "string"
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "SyncResponse": {
        "type": "object",
        "required": [
          "request_id",
          "data"
        ],
        "properties": {
          "request_id": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/SyncRequest"
          }
        }
      },
      "SyncRequest": {
        "type": "object",
        "required": [
          "sync_id",
          "numero_fir",
          "status",
          "esito",
          "errore",
          "tentativi",
          "retry_after",
          "status_url",
          "fir_url",
          "osservazione",
          "notifiche",
          "richiesta_il",
          "iniziata_il",
          "conclusa_il",
          "scade_il",
          "prossimo_tentativo"
        ],
        "properties": {
          "sync_id": {
            "type": "string",
            "pattern": "^syn_[a-f0-9]{32}$"
          },
          "numero_fir": {
            "type": "string"
          },
          "status": {
            "enum": [
              "queued",
              "running",
              "completed",
              "failed",
              "cancelled"
            ]
          },
          "esito": {
            "enum": [
              "changed",
              "unchanged",
              "reused",
              null
            ]
          },
          "errore": {
            "type": [
              "string",
              "null"
            ]
          },
          "tentativi": {
            "type": "integer",
            "minimum": 0
          },
          "retry_after": {
            "type": "integer",
            "minimum": 0
          },
          "status_url": {
            "type": "string"
          },
          "fir_url": {
            "type": "string"
          },
          "accorpata": {
            "type": "boolean",
            "description": "Solo POST: è stata restituita una risorsa già esistente."
          },
          "osservazione": {
            "type": "object",
            "required": [
              "ultima_verifica",
              "revisione",
              "versione_rentri"
            ],
            "properties": {
              "ultima_verifica": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "revisione": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "versione_rentri": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "notifiche": {
            "type": "object",
            "required": [
              "consegna_abilitata",
              "endpoint_configurato",
              "evento_della_revisione"
            ],
            "properties": {
              "consegna_abilitata": {
                "type": "boolean"
              },
              "endpoint_configurato": {
                "type": "boolean"
              },
              "evento_della_revisione": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "stato_consegna": {
                    "enum": [
                      "pending",
                      "unconfigured",
                      "delivered",
                      "cancelled",
                      "failed"
                    ]
                  }
                }
              }
            }
          },
          "richiesta_il": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "iniziata_il": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "conclusa_il": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "scade_il": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "prossimo_tentativo": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      }
    }
  },
  "x-native-environments": [
    "demo",
    "prod"
  ]
}
