{
  "openapi": "3.1.0",
  "$id": "https://recit.dev/schema/v1/form-submission.openapi.json",
  "info": {
    "title": "Récit Form Submission API",
    "version": "1.0.0",
    "summary": "What an endpoint must do to receive a Récit :::form.",
    "description": "The contract between a `:::form` of a static Récit site and the API that receives it. Récit hosts no endpoint: the integrator writes it (see the TODO API checklist, https://docs.recit.dev/documentation/reference/form-submission-api). Validation, idempotency, rate limiting and the honeypot are the API's job: the client only helps. Errors follow RFC 9457 (Problem Details), with an `errors[]` member that is a Récit extension.",
    "license": {
      "name": "All rights reserved, used under a license from Récit"
    }
  },
  "servers": [
    {
      "url": "{endpoint}",
      "variables": {
        "endpoint": {
          "default": "https://api.example.com/v1/forms",
          "description": "The endpoint= of the form"
        }
      }
    }
  ],
  "paths": {
    "/": {
      "options": {
        "operationId": "preflightSubmission",
        "summary": "CORS preflight",
        "description": "Required only for encoding=json or an auth header: the default urlencoded and multipart bodies are simple requests, sent without a preflight.",
        "responses": {
          "204": {
            "description": "The origin is allowed",
            "headers": {
              "Access-Control-Allow-Origin": {
                "description": "One origin of the site (never * with credentials), on every response",
                "schema": {
                  "type": "string"
                }
              },
              "Access-Control-Allow-Methods": {
                "schema": {
                  "type": "string",
                  "const": "POST"
                }
              },
              "Access-Control-Allow-Headers": {
                "schema": {
                  "type": "string",
                  "examples": [
                    "Content-Type, Idempotency-Key, Authorization"
                  ]
                }
              },
              "Access-Control-Expose-Headers": {
                "schema": {
                  "type": "string",
                  "examples": [
                    "Location, Retry-After"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "submitForm",
        "summary": "Receive one submission of a form",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Sent with encoding=json only (it triggers a preflight). The same key is in meta.submissionId, or in _recit.submission for the default body.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {},
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/FlatSubmission"
              },
              "example": {
                "name": "Lorem Ipsum",
                "email": "lorem@example.com",
                "mode": "remote",
                "consent": "true",
                "_recit.website": "",
                "_recit.form": "signup",
                "_recit.version": "1",
                "_recit.locale": "en",
                "_recit.submission": "3f2c0d8e-0000-4000-8000-000000000000",
                "_recit.story": "meetup",
                "_recit.elapsed": "8421",
                "_recit.consent": "2026-10"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/FlatSubmission"
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Envelope"
              },
              "example": {
                "form": "signup",
                "version": 1,
                "locale": "en",
                "data": {
                  "name": "Lorem Ipsum",
                  "email": "lorem@example.com",
                  "mode": "remote"
                },
                "meta": {
                  "submissionId": "3f2c0d8e-0000-4000-8000-000000000000",
                  "story": "meetup",
                  "page": "https://example.com/meetup",
                  "elapsedMs": 8421,
                  "consent": {
                    "name": "consent",
                    "version": "2026-10",
                    "granted": true
                  },
                  "antispam": {
                    "honeypot": "",
                    "turnstile": null
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Accepted (200 and 202 are accepted too). A filled honeypot gets a 2xx too, without any processing.",
            "headers": {
              "Access-Control-Allow-Origin": {
                "description": "One origin of the site (never * with credentials), on every response",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "example": {
                  "id": "sub_01",
                  "message": "Thanks, lorem ipsum."
                }
              }
            }
          },
          "303": {
            "description": "Accepted, submit=native: the browser follows Location to the success page",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Malformed body (JSON that does not parse)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Authentication needed (auth=publishable-key, or auth=bearer without an accepted token)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "description": "For auth=bearer: `Bearer realm=\"form\"`, the token missing or not accepted",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Origin or key refused",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "The same idempotency key with a different body",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Too large",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Content type refused",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation: one entry of errors[] per field, its pointer and its code",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                },
                "example": {
                  "type": "https://recit.dev/problems/validation",
                  "title": "Your answers need a correction",
                  "status": 422,
                  "detail": "One field is not valid.",
                  "errors": [
                    {
                      "pointer": "#/data/email",
                      "code": "format",
                      "detail": "Lorem ipsum."
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                },
                "example": {
                  "type": "about:blank",
                  "title": "Too many requests",
                  "status": 429
                }
              }
            },
            "headers": {
              "Access-Control-Allow-Origin": {
                "description": "One origin of the site (never * with credentials), on every response",
                "schema": {
                  "type": "string"
                }
              },
              "Retry-After": {
                "required": true,
                "description": "Seconds, or an HTTP date",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "5XX": {
            "description": "Server error, generic: no personal data of another submission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/uploads": {
      "options": {
        "operationId": "preflightUploadTicket",
        "summary": "CORS preflight",
        "description": "Required only for encoding=json or an auth header: the default urlencoded and multipart bodies are simple requests, sent without a preflight.",
        "responses": {
          "204": {
            "description": "The origin is allowed",
            "headers": {
              "Access-Control-Allow-Origin": {
                "description": "One origin of the site (never * with credentials), on every response",
                "schema": {
                  "type": "string"
                }
              },
              "Access-Control-Allow-Methods": {
                "schema": {
                  "type": "string",
                  "const": "POST"
                }
              },
              "Access-Control-Allow-Headers": {
                "schema": {
                  "type": "string",
                  "examples": [
                    "Content-Type, Idempotency-Key, Authorization"
                  ]
                }
              },
              "Access-Control-Expose-Headers": {
                "schema": {
                  "type": "string",
                  "examples": [
                    "Location, Retry-After"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "askUploadTicket",
        "summary": "Give a ticket to send one file (upload=presigned)",
        "description": "Only for a form with upload=presigned. The client asks one ticket per chosen file, sends the bytes to the ticket's url (PUT with its headers, or POST with its fields then the file, as an object store's presigned URL or policy expects), then submits the ticket's file reference as the field's value, without multipart. The API checks the form, the field, accept= and max-size=, and binds the address to the asked size and type; an unknown reference in the submission is a 422 on its field (code format).",
        "security": [
          {},
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UploadRequest"
              },
              "example": {
                "form": "apply",
                "field": "cv",
                "name": "lorem.pdf",
                "type": "application/pdf",
                "size": 182044,
                "submissionId": "3f2c0d8e-0000-4000-8000-000000000000"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The ticket: where the bytes go, and the reference to submit",
            "headers": {
              "Access-Control-Allow-Origin": {
                "description": "One origin of the site (never * with credentials), on every response",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadTicket"
                },
                "example": {
                  "file": "up_01",
                  "url": "https://bucket.example.com/up_01?X-Amz-Signature=lorem",
                  "method": "PUT",
                  "headers": {
                    "Content-Type": "application/pdf"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Not an upload request",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "auth=bearer without an accepted token: no ticket is given",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "description": "For auth=bearer: `Bearer realm=\"form\"`, the token missing or not accepted",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Origin refused",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Too large",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Content type refused: application/json only",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "The form takes no presigned upload (#/form), or the file is refused on its field (accept, maxSize, enum)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "501": {
            "description": "This API takes no presigned upload",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Envelope": {
        "type": "object",
        "properties": {
          "form": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*$"
          },
          "version": {
            "type": "number",
            "const": 1
          },
          "locale": {
            "type": "string",
            "minLength": 1
          },
          "data": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          },
          "meta": {
            "type": "object",
            "properties": {
              "submissionId": {
                "type": "string",
                "minLength": 1
              },
              "story": {
                "type": "string"
              },
              "about": {
                "type": "string",
                "maxLength": 200
              },
              "page": {
                "type": "string"
              },
              "elapsedMs": {
                "type": "number",
                "minimum": 0
              },
              "consent": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "version": {
                    "type": "string"
                  },
                  "granted": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "name",
                  "version",
                  "granted"
                ],
                "additionalProperties": {}
              },
              "antispam": {
                "type": "object",
                "properties": {
                  "honeypot": {
                    "type": "string"
                  },
                  "turnstile": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "additionalProperties": {}
              },
              "publishableKey": {
                "type": "string"
              }
            },
            "required": [
              "submissionId"
            ],
            "additionalProperties": {}
          }
        },
        "required": [
          "form",
          "version",
          "locale",
          "data",
          "meta"
        ],
        "additionalProperties": {}
      },
      "FlatSubmission": {
        "type": "object",
        "description": "The fields of the form, flat, plus the reserved fields prefixed with \"_recit.\" and the honeypot \"_recit.website\". An author's field never starts with \"_recit.\".",
        "properties": {
          "_recit.form": {
            "type": "string"
          },
          "_recit.version": {
            "type": "string",
            "const": "1"
          },
          "_recit.locale": {
            "type": "string"
          },
          "_recit.submission": {
            "type": "string",
            "description": "The idempotency key; absent without JavaScript"
          },
          "_recit.story": {
            "type": "string"
          },
          "_recit.about": {
            "type": "string",
            "description": "The scene the answer is about (a calendar event, a roadmap item): the recit-about parameter of the page"
          },
          "_recit.elapsed": {
            "type": "string",
            "description": "Milliseconds between display and submission (the time trap)"
          },
          "_recit.consent": {
            "type": "string",
            "description": "Version of the accepted consent text"
          },
          "_recit.key": {
            "type": "string",
            "description": "auth=publishable-key: a public key, never a secret"
          },
          "_recit.website": {
            "type": "string",
            "description": "Must be empty: a filled one is dropped in silence"
          }
        },
        "required": [
          "_recit.form",
          "_recit.version",
          "_recit.locale"
        ],
        "additionalProperties": true
      },
      "Accepted": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "redirect": {
            "type": "string"
          }
        },
        "additionalProperties": {}
      },
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "detail": {
            "type": "string"
          },
          "instance": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "pointer": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                }
              },
              "required": [
                "pointer",
                "code"
              ],
              "additionalProperties": {}
            }
          }
        },
        "additionalProperties": {}
      },
      "UploadRequest": {
        "type": "object",
        "properties": {
          "form": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*$"
          },
          "field": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_.-]*$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "type": {
            "type": "string",
            "maxLength": 255
          },
          "size": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9007199254740991
          },
          "submissionId": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "form",
          "field",
          "name",
          "type",
          "size"
        ],
        "additionalProperties": false
      },
      "UploadTicket": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string",
            "minLength": 1
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "method": {
            "type": "string",
            "enum": [
              "PUT",
              "POST"
            ]
          },
          "headers": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "string"
            }
          },
          "fields": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "string"
            }
          }
        },
        "required": [
          "file",
          "url"
        ],
        "additionalProperties": {}
      }
    },
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "auth=bearer: the token of the person signed in to the site, given by the host at run time; the API checks it"
      }
    }
  }
}
