{
  "openapi": "3.1.0",
  "info": {
    "title": "SaaS RENTRI — documenti FIR e copie restituite",
    "version": "1.1.0",
    "description": "Native DEMO/PROD; disabilitato per default al rilascio locale. Nessuna conferma di presa visione, upload, firma o trasmissione automatica. Metadata e documenti recuperati su richiesta, nessuno storage dei file. PROD: richiede opt-in del modulo, deployment vincolato, capacità di lettura e certificato approvato; le mutazioni richiedono anche i gate di invio."
  },
  "x-implementation-status": "implemented-demo-prod-offline-tested-disabled-by-default",
  "x-inventory-downloads-files": false,
  "paths": {
    "/api/v1/fir/{numero_fir}/documenti": {
      "get": {
        "operationId": "getFirDocuments",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scopes": [
          "fir:read"
        ],
        "parameters": [
          {
            "name": "numero_fir",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Chiave non valida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope o contesto non autorizzato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "FIR/file/link non disponibile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "HEAD non scarica documenti",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "GET con query/body non ammessi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite concorrenza: un lavoro per client, due complessivi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Capacità disabilitata, dati upstream incompleti o lettura fallita",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Metadati freschi delle copie; nessun download automatico. Non attesta conservazione/adempimenti.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InventoryResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/fir/{numero_fir}/documenti/{tipo}": {
      "get": {
        "operationId": "downloadFirDocument",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scopes": [
          "fir:read",
          "fir:download"
        ],
        "parameters": [
          {
            "name": "numero_fir",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tipo",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "pdf",
                "xfir"
              ]
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Chiave non valida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope o contesto non autorizzato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "FIR/file/link non disponibile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "HEAD non scarica documenti",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "GET con query/body non ammessi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite concorrenza: un lavoro per client, due complessivi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Capacità disabilitata, dati upstream incompleti o lettura fallita",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Byte originali decodificati da base64; nome file generato dal gateway. Per xFIR il download può impedire un successivo rollback firma.",
            "headers": {
              "X-Content-SHA256": {
                "description": "SHA-256 dei byte restituiti, non attestazione di firma",
                "schema": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Length": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/fir/{numero_fir}/documenti/copie/{token}": {
      "get": {
        "operationId": "downloadFirReturnedCopy",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scopes": [
          "fir:read",
          "fir:download"
        ],
        "parameters": [
          {
            "name": "numero_fir",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "description": "Link cifrato ottenuto dall’inventario, legato a client/FIR/contesto/tipo/id, validità 10 minuti. Non contiene una API key e richiede comunque Authorization.",
            "schema": {
              "type": "string",
              "maxLength": 4096
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Chiave non valida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope o contesto non autorizzato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "FIR/file/link non disponibile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "HEAD non scarica documenti",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "GET con query/body non ammessi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite concorrenza: un lavoro per client, due complessivi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Capacità disabilitata, dati upstream incompleti o lettura fallita",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Byte originali decodificati da base64; nome file generato dal gateway. Per xFIR il download può impedire un successivo rollback firma.",
            "headers": {
              "X-Content-SHA256": {
                "description": "SHA-256 dei byte restituiti, non attestazione di firma",
                "schema": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Length": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    }
  },
  "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"
              }
            }
          }
        }
      },
      "InventoryResponse": {
        "type": "object",
        "required": [
          "request_id",
          "data"
        ],
        "properties": {
          "request_id": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/Inventory"
          }
        }
      },
      "Inventory": {
        "type": "object",
        "required": [
          "numero_fir",
          "verificato_il",
          "fonte",
          "documenti",
          "copie_restituite",
          "chiusura_documentale"
        ],
        "properties": {
          "numero_fir": {
            "type": "string"
          },
          "verificato_il": {
            "type": "string",
            "format": "date-time"
          },
          "fonte": {
            "const": "lettura_rentri_su_richiesta"
          },
          "documenti": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "object",
              "required": [
                "tipo",
                "disponibilita",
                "download_url",
                "richiede_scope",
                "download_puo_impedire_rollback_firma"
              ],
              "properties": {
                "tipo": {
                  "enum": [
                    "pdf",
                    "xfir"
                  ]
                },
                "disponibilita": {
                  "const": "da_verificare_al_download"
                },
                "download_url": {
                  "type": "string"
                },
                "richiede_scope": {
                  "const": "fir:download"
                },
                "download_puo_impedire_rollback_firma": {
                  "type": "boolean"
                }
              }
            }
          },
          "copie_restituite": {
            "type": "array",
            "maxItems": 1000,
            "items": {
              "$ref": "#/components/schemas/Copy"
            }
          },
          "chiusura_documentale": {
            "type": "object",
            "required": [
              "restituzione",
              "presa_visione_automatica",
              "conferma_via_saas",
              "attesta_adempimenti_completi",
              "attesta_conservazione"
            ],
            "properties": {
              "restituzione": {
                "enum": [
                  "non_rilevata_nella_lettura",
                  "copie_osservate"
                ]
              },
              "presa_visione_automatica": {
                "const": false
              },
              "conferma_via_saas": {
                "const": "non_implementata"
              },
              "attesta_adempimenti_completi": {
                "const": false
              },
              "attesta_conservazione": {
                "const": false
              }
            }
          }
        }
      },
      "Copy": {
        "type": "object",
        "required": [
          "tipo",
          "identificativo",
          "data_caricamento",
          "esito_accettazione",
          "presa_visione",
          "data_presa_visione",
          "download_url",
          "download_scade_il"
        ],
        "properties": {
          "tipo": {
            "enum": [
              "digitale",
              "cartacea"
            ]
          },
          "identificativo": {
            "type": "string"
          },
          "data_caricamento": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "esito_accettazione": {
            "enum": [
              "A",
              "P",
              "R",
              null
            ]
          },
          "presa_visione": {
            "enum": [
              "confermata_osservata",
              "non_rilevata",
              "non_disponibile"
            ]
          },
          "data_presa_visione": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "download_url": {
            "type": "string"
          },
          "download_scade_il": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "x-native-environments": [
    "demo",
    "prod"
  ]
}
