{
  "openapi": "3.1.0",
  "info": {
    "title": "Formula Cards Authoring API",
    "version": "1.0.0",
    "description": "Validate mixed course drafts and propose them for owner review. No automatic publication. Course/deck content only: submit a complete course using registered card types. These endpoints do not accept provider code or register new card types."
  },
  "servers": [
    {
      "url": "https://deckrehearsal.com"
    }
  ],
  "paths": {
    "/api/authoring/validate": {
      "post": {
        "summary": "Validate without saving",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "/course.schema.json"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Course validation succeeded; nothing saved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Validation"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation issues",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Validation"
                }
              }
            }
          },
          "429": {
            "description": "Rate or quota limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "validateCourse"
      }
    },
    "/api/authoring/proposals": {
      "post": {
        "summary": "Submit immutable draft",
        "security": [
          {
            "submissionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "requestId",
                  "course"
                ],
                "properties": {
                  "requestId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "course": {
                    "$ref": "/course.schema.json"
                  },
                  "supersedes": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$",
                    "description": "Optional predecessor proposal ID submitted with the same token for the same course. Immutable on retry; does not change predecessor status."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent receipt for an already saved proposal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "201": {
            "description": "Proposal saved, not published",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Wrong scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting requestId",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation issues",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Validation"
                }
              }
            }
          },
          "429": {
            "description": "Rate or quota limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "submitProposal"
      },
      "get": {
        "summary": "Recover proposal receipts submitted with this token",
        "operationId": "listOwnProposals",
        "security": [
          {
            "submissionToken": []
          }
        ],
        "description": "Newest first, at most the token quota of 20 proposals. No course JSON or review notes; follow statusUrl for details. Expired or revoked tokens are rejected.",
        "responses": {
          "200": {
            "description": "Token-scoped proposal summaries",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "proposals"
                  ],
                  "properties": {
                    "proposals": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/Receipt"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "requestId": {
                                "type": "string",
                                "format": "uuid"
                              },
                              "courseId": {
                                "type": "string"
                              },
                              "title": {
                                "type": "string"
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time"
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired token"
          }
        }
      }
    },
    "/api/authoring/proposals/{id}": {
      "get": {
        "summary": "Get review status for own proposal",
        "security": [
          {
            "submissionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Status, review_note, published:false",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "getProposalStatus"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "submissionToken": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Issue": {
        "type": "object",
        "required": [
          "severity",
          "code",
          "path",
          "message"
        ],
        "properties": {
          "severity": {
            "enum": [
              "error",
              "warning"
            ]
          },
          "code": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "cardId": {
            "type": "string"
          }
        }
      },
      "Validation": {
        "type": "object",
        "required": [
          "ok",
          "stage",
          "issues",
          "cards"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "stage": {
            "type": "string"
          },
          "issues": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Issue"
            }
          },
          "cards": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "scope": {
            "type": "string"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "required": [
          "id",
          "status",
          "published"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "enum": [
              "pending",
              "needs-revision",
              "approved",
              "rejected"
            ]
          },
          "published": {
            "const": false
          },
          "duplicate": {
            "type": "boolean"
          },
          "statusUrl": {
            "type": "string"
          },
          "review_note": {
            "type": "string"
          },
          "validation": {
            "$ref": "#/components/schemas/Validation"
          },
          "supersedes": {
            "type": [
              "string",
              "null"
            ],
            "description": "Predecessor proposal ID, or null for an unlinked draft."
          },
          "revisions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "In status responses, IDs of proposals that directly supersede this proposal."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "retryable": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
