{
  "openapi": "3.0.3",
  "info": {
    "title": "StarGit managed repository API",
    "version": "1.0.0",
    "description": "Use a provider-scoped hosting token with explicit can_create permission. No browser session or CSRF is needed for bearer requests. Token management remains a signed-in human action."
  },
  "servers": [
    {
      "url": "https://stargit.com"
    }
  ],
  "security": [
    {
      "hostingToken": []
    }
  ],
  "components": {
    "securitySchemes": {
      "hostingToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sght_ access token"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "HostingSetup": {
        "type": "object",
        "required": [
          "owner",
          "providers"
        ],
        "properties": {
          "namespace": {
            "type": "string",
            "nullable": true
          },
          "owner": {
            "type": "object",
            "required": [
              "name",
              "address"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "address": {
                "type": "string"
              }
            }
          },
          "providers": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "hostname",
                "available",
                "message"
              ],
              "properties": {
                "id": {
                  "type": "integer"
                },
                "label": {
                  "type": "string"
                },
                "hostname": {
                  "type": "string"
                },
                "available": {
                  "type": "boolean"
                },
                "message": {
                  "type": "string",
                  "nullable": true
                }
              }
            }
          }
        }
      },
      "Repository": {
        "type": "object",
        "required": [
          "uuid",
          "state",
          "status_url",
          "name",
          "namespace",
          "https_url",
          "clone_url"
        ],
        "properties": {
          "uuid": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "namespace": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "status_url": {
            "type": "string"
          },
          "review_url": {
            "type": "string"
          },
          "overview_url": {
            "type": "string"
          },
          "access_setup_url": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "provisioning",
              "ready",
              "error"
            ]
          },
          "retry_after_seconds": {
            "type": "integer",
            "nullable": true
          },
          "https_url": {
            "type": "string",
            "nullable": true
          },
          "clone_url": {
            "type": "string",
            "nullable": true
          }
        }
      }
    }
  },
  "paths": {
    "/api/hosting/setup": {
      "get": {
        "operationId": "discoverHosting",
        "summary": "Get the token-scoped hosting destination and automatic owner",
        "responses": {
          "200": {
            "description": "Automatic owner and available token-scoped hosting destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HostingSetup"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing permission or wrong hosting destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/hosting/repositories": {
      "post": {
        "operationId": "createRepository",
        "summary": "Create a repository, or resume an identical request",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "provider_id",
                  "name"
                ],
                "properties": {
                  "provider_id": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9][a-z0-9_-]{0,79}$"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "visibility": {
                    "type": "string",
                    "enum": [
                      "private",
                      "public"
                    ],
                    "default": "private"
                  },
                  "default_branch": {
                    "type": "string",
                    "default": "main",
                    "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$"
                  },
                  "readme": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success; repository state is provisioning, ready, or error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Repository"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing permission or wrong hosting destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "202": {
            "description": "Provisioning started; poll status_url every retry_after_seconds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Repository"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Name/request conflict, limit reached, or destination unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/hosting/repositories/{uuid}": {
      "parameters": [
        {
          "name": "uuid",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getRepositoryStatus",
        "summary": "Poll repository state and retrieve clone URLs when ready",
        "responses": {
          "200": {
            "description": "Success; repository state is provisioning, ready, or error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Repository"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing permission or wrong hosting destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Repository not accessible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "retryRepository",
        "summary": "Retry failed provisioning of the same repository",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "action"
                ],
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "retry"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success; repository state is provisioning, ready, or error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Repository"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing permission or wrong hosting destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Repository not failed or destination unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
