{
  "openapi": "3.1.0",
  "info": {
    "title": "LaneSpark Google Driving Mileage",
    "version": "1.0.0",
    "description": "Standard Google driving mileage, not truck-specific. Check each result status. Preserve Google Maps attribution. No authentication or API key required. Requests share a daily allowance."
  },
  "servers": [
    {
      "url": "https://lanespark.co"
    }
  ],
  "security": [],
  "paths": {
    "/api/v1/mileage": {
      "post": {
        "operationId": "calculateDrivingMiles",
        "summary": "Calculate Google driving miles for one or more lanes",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "lanes"
                ],
                "properties": {
                  "lanes": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 25,
                    "items": {
                      "$ref": "#/components/schemas/Lane"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ordered results, including individual lane failures",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "results",
                    "provider",
                    "mileageType",
                    "truckSpecific",
                    "calculatedAt"
                  ],
                  "properties": {
                    "provider": {
                      "const": "Google Maps"
                    },
                    "mileageType": {
                      "const": "google_driving_miles"
                    },
                    "truckSpecific": {
                      "const": false
                    },
                    "routingPreference": {
                      "const": "APPS_SCRIPT_DRIVING"
                    },
                    "calculatedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Result"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON or lane fields"
          },
          "413": {
            "description": "Request exceeds 16 KB"
          },
          "429": {
            "description": "Burst limit reached; Retry-After gives seconds"
          },
          "503": {
            "description": "Not configured, script busy, or daily allowance reached"
          },
          "502": {
            "description": "Apps Script connection, authorization, response, or timeout error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Lane": {
        "type": "object",
        "required": [
          "origin",
          "destination"
        ],
        "properties": {
          "reference": {
            "type": "string",
            "maxLength": 100
          },
          "origin": {
            "type": "string",
            "minLength": 2,
            "maxLength": 250
          },
          "destination": {
            "type": "string",
            "minLength": 2,
            "maxLength": 250
          }
        }
      },
      "Result": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Lane"
          },
          {
            "type": "object",
            "required": [
              "status"
            ],
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "ok",
                  "error"
                ]
              },
              "miles": {
                "type": "number"
              },
              "distanceMeters": {
                "type": "number"
              },
              "durationSeconds": {
                "type": "number"
              },
              "error": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "mapsUrl": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        ]
      }
    }
  }
}
