{
  "openapi": "3.1.0",
  "info": {
    "title": "GISGP Free GIS API",
    "version": "0.1.0",
    "description": "Curated public spec for GISGP's free REST endpoints (format conversion, GeoJSON validation, ArcGIS FeatureServer inspection). For the full agent toolset use the MCP server at https://gisgp.com/mcp — docs at https://gisgp.com/api. Fair-use limits apply; uploads max 9 MB (API Gateway limit)."
  },
  "servers": [{ "url": "https://gisgp.com" }],
  "paths": {
    "/convert/geojson-validate": {
      "post": {
        "summary": "Validate a GeoJSON file",
        "description": "RFC 7946 structure check, topology validation via shapely (self-intersections, degenerate shapes) and WGS84 coordinate range sanity. Max 9 MB.",
        "operationId": "validateGeojson",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": { "file": { "type": "string", "format": "binary", "description": ".geojson or .json file" } }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation report",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": { "type": "boolean" },
                    "errors": { "type": "array", "items": { "type": "object" } },
                    "warnings": { "type": "array", "items": { "type": "object" } },
                    "stats": { "type": "object" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/convert/shapefile-to-geojson": {
      "post": {
        "summary": "Convert a Shapefile ZIP to GeoJSON",
        "description": "Upload a .zip containing .shp/.dbf/.shx (optionally .prj — reprojected to WGS84). Returns a GeoJSON FeatureCollection file. Max 9 MB.",
        "operationId": "shapefileToGeojson",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": { "file": { "type": "string", "format": "binary", "description": "Shapefile bundle as .zip" } }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "GeoJSON FeatureCollection (attachment)", "content": { "application/geo+json": {} } }
        }
      }
    },
    "/convert/csv-to-geojson": {
      "post": {
        "summary": "Convert a CSV with coordinate columns to GeoJSON",
        "description": "Auto-detects lat/lon columns (also handles EU decimal comma). Returns a GeoJSON FeatureCollection file. Max 9 MB.",
        "operationId": "csvToGeojson",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": { "file": { "type": "string", "format": "binary", "description": ".csv file with coordinate columns" } }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "GeoJSON FeatureCollection (attachment)", "content": { "application/geo+json": {} } }
        }
      }
    },
    "/convert/geojson-to-csv": {
      "post": {
        "summary": "Convert GeoJSON to CSV",
        "description": "Flattens a FeatureCollection to CSV: one row per feature, properties as columns plus a geometry column. Max 9 MB.",
        "operationId": "geojsonToCsv",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": { "file": { "type": "string", "format": "binary", "description": ".geojson or .json file" } }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "CSV file (attachment)", "content": { "text/csv": {} } }
        }
      }
    },
    "/tools/feature-count/query": {
      "get": {
        "summary": "Count features in an ArcGIS FeatureServer layer",
        "description": "Works with public layers without a token; pass token for secured layers. Optional SQL WHERE clause counts a subset.",
        "operationId": "featureCount",
        "parameters": [
          { "name": "url", "in": "query", "required": true, "schema": { "type": "string" }, "description": "Full layer URL ending in /FeatureServer/<n>" },
          { "name": "where", "in": "query", "required": false, "schema": { "type": "string", "default": "1=1" }, "description": "ArcGIS SQL WHERE clause" },
          { "name": "token", "in": "query", "required": false, "schema": { "type": "string" }, "description": "AGOL token for secured layers (used once, never stored)" }
        ],
        "responses": {
          "200": {
            "description": "Count result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "count": { "type": "integer" },
                    "name": { "type": "string" },
                    "geometry": { "type": "string" },
                    "error": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
