{
    "openapi": "3.0.3",
    "info": {
        "title": "Markpact Portal API",
        "version": "0.2.4",
        "description": "REST API for publishing and fetching UriPack documents (*.markpact.md).",
        "contact": {
            "url": "https://markpact.com/api/docs"
        }
    },
    "servers": [
        {
            "url": "https://markpact.com"
        }
    ],
    "tags": [
        {
            "name": "packages",
            "description": "Browse and publish Markpact packages"
        },
        {
            "name": "auth",
            "description": "Token-authenticated user context"
        },
        {
            "name": "ssh",
            "description": "SSH-signed publish and key management"
        }
    ],
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "API token from dashboard (mp_...)"
            },
            "markpactTokenHeader": {
                "type": "apiKey",
                "in": "header",
                "name": "X-Markpact-Token"
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "ok": {
                        "type": "boolean",
                        "example": false
                    },
                    "error": {
                        "type": "string"
                    }
                }
            },
            "Package": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "owner_slug": {
                        "type": "string"
                    },
                    "pack_slug": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "scheme": {
                        "type": "string"
                    },
                    "version": {
                        "type": "string"
                    },
                    "url": {
                        "type": "string",
                        "format": "uri"
                    },
                    "raw_url": {
                        "type": "string",
                        "format": "uri"
                    },
                    "install_command": {
                        "type": "string"
                    }
                }
            },
            "PublishRequest": {
                "type": "object",
                "required": [
                    "content"
                ],
                "properties": {
                    "content": {
                        "type": "string",
                        "description": "Full Markpact markdown with yaml markpact:pack block"
                    },
                    "name": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string"
                    }
                }
            },
            "PublishSignedRequest": {
                "type": "object",
                "required": [
                    "content",
                    "timestamp",
                    "nonce",
                    "fingerprint",
                    "signature"
                ],
                "properties": {
                    "content": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string"
                    },
                    "timestamp": {
                        "type": "integer"
                    },
                    "nonce": {
                        "type": "string"
                    },
                    "fingerprint": {
                        "type": "string"
                    },
                    "signature": {
                        "type": "string"
                    }
                }
            }
        }
    },
    "paths": {
        "/api/packages": {
            "get": {
                "tags": [
                    "packages"
                ],
                "summary": "List latest packages",
                "responses": {
                    "200": {
                        "description": "Package list",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "ok": {
                                            "type": "boolean"
                                        },
                                        "packages": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Package"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/publish": {
            "post": {
                "tags": [
                    "packages"
                ],
                "summary": "Publish Markpact document (Bearer token)",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "markpactTokenHeader": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/PublishRequest"
                            }
                        },
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "file": {
                                        "type": "string",
                                        "format": "binary"
                                    },
                                    "name": {
                                        "type": "string"
                                    },
                                    "description": {
                                        "type": "string"
                                    },
                                    "content": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Published"
                    },
                    "401": {
                        "description": "Unauthorized",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/publish-signed": {
            "post": {
                "tags": [
                    "ssh"
                ],
                "summary": "Publish with SSH signature",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/PublishSignedRequest"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Published with ssh-signature auth"
                    },
                    "400": {
                        "description": "Invalid signature"
                    }
                }
            }
        },
        "/api/me": {
            "get": {
                "tags": [
                    "auth"
                ],
                "summary": "Current API user",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "markpactTokenHeader": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "User profile"
                    },
                    "401": {
                        "description": "Unauthorized"
                    }
                }
            }
        },
        "/api/ssh-keys": {
            "get": {
                "tags": [
                    "ssh"
                ],
                "summary": "List SSH public keys",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Key list"
                    }
                }
            },
            "post": {
                "tags": [
                    "ssh"
                ],
                "summary": "Register SSH public key",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "public_key"
                                ],
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "public_key": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Key added"
                    }
                }
            }
        },
        "/raw/{owner}/{pack}.markpact.md": {
            "get": {
                "tags": [
                    "packages"
                ],
                "summary": "Raw Markpact markdown",
                "parameters": [
                    {
                        "name": "owner",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "pack",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "text/markdown"
                    },
                    "404": {
                        "description": "Not found"
                    }
                }
            }
        }
    }
}