
{
  "openapi": "3.1.0",
  "info": {
    "title": "USTIVO Public API",
    "description": "Public API for accessing the USTIVO service catalog and active listings.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://ustivo.uz"
    }
  ],
  "paths": {
    "/api/catalog.php": {
      "get": {
        "operationId": "getCatalog",
        "summary": "Get service catalog",
        "description": "Returns all categories, subcategories and the number of active listings.",
        "responses": {
          "200": {
            "description": "Catalog returned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/listings.php": {
      "get": {
        "operationId": "getListings",
        "summary": "Get listings by subcategory",
        "description": "Returns active listings for the selected subcategory.",
        "parameters": [
          {
            "name": "subcategory_id",
            "in": "query",
            "required": true,
            "description": "Subcategory ID obtained from catalog.php",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "city_id",
            "in": "query",
            "required": false,
            "description": "Optional city ID filter",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "district_id",
            "in": "query",
            "required": false,
            "description": "Optional district ID filter",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum number of records to return",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Listings returned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListingsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "404": {
            "description": "Subcategory not found"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CatalogResponse": {
        "type": "object",
        "properties": {
          "provider": {
            "type": "string"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          },
          "total_categories": {
            "type": "integer"
          },
          "total_active_ads": {
            "type": "integer"
          },
          "categories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Category"
            }
          }
        },
        "required": [
          "provider",
          "updated",
          "total_categories",
          "total_active_ads",
          "categories"
        ]
      },
      "Category": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "subcategories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Subcategory"
            }
          }
        },
        "required": [
          "id",
          "name",
          "subcategories"
        ]
      },
      "Subcategory": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "count"
        ]
      },
      "ListingsResponse": {
        "type": "object",
        "properties": {
          "provider": {
            "type": "string"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          },
          "subcategory": {
            "$ref": "#/components/schemas/SubcategoryInfo"
          },
          "total": {
            "type": "integer"
          },
          "has_more": {
            "type": "boolean"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Listing"
            }
          }
        },
        "required": [
          "provider",
          "updated",
          "subcategory",
          "total",
          "has_more",
          "items"
        ]
      },
      "SubcategoryInfo": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "category": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "category"
        ]
      },
      "Listing": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "photo_url": {
            "type": "string",
            "format": "uri"
          },
          "city": {
            "type": "string"
          },
          "district": {
            "type": "string"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "google_url": {
            "type": "string",
            "format": "uri"
          }
        },
        "required": [
          "id",
          "title",
          "description",
          "photo_url",
          "city",
          "district",
          "updated_at",
          "google_url"
        ]
      }
    }
  }
}

