{
  "openapi": "3.1.0",
  "info": {
    "title": "US Address Validation API",
    "version": "1.0",
    "description": "Rule-based US address validation for form and negative testing: USPS-style standardisation, ZIP format and ZIP-to-state area checks, a sample ZIP lookup and per-field 422 errors."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/address/v1"
    }
  ],
  "tags": [
    {
      "name": "validation",
      "description": "validate and standardise"
    },
    {
      "name": "lookup",
      "description": "ZIPs and states"
    }
  ],
  "paths": {
    "/validate": {
      "post": {
        "tags": [
          "validation"
        ],
        "summary": "Validate and standardise a US address (USPS-style abbreviations, ZIP/state check)",
        "operationId": "ad-validate",
        "responses": {
          "200": {
            "description": "Result: valid flag, standardised address, issues",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": {
                      "type": "boolean"
                    },
                    "standardized": {
                      "type": "object",
                      "properties": {
                        "street": {
                          "type": "string"
                        },
                        "city": {
                          "type": "string"
                        },
                        "state": {
                          "type": "string"
                        },
                        "zip": {
                          "type": "string"
                        }
                      }
                    },
                    "issues": {
                      "type": "array"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Missing or malformed fields",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "street": {
                    "type": "string"
                  },
                  "city": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string"
                  },
                  "zip": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "street": "100 north congress avenue suite 200",
                "city": "austin",
                "state": "tx",
                "zip": "78701"
              }
            }
          }
        }
      }
    },
    "/zip/{zip}": {
      "get": {
        "tags": [
          "lookup"
        ],
        "summary": "City and state for a ZIP code in the sample set",
        "operationId": "ad-zip",
        "responses": {
          "200": {
            "description": "City and state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "zip": {
                      "type": "string"
                    },
                    "city": {
                      "type": "string"
                    },
                    "state": {
                      "type": "string"
                    },
                    "stateName": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Not a 5-digit ZIP",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "ZIP not in the sample set",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "zip",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "94105"
          }
        ]
      }
    },
    "/states": {
      "get": {
        "tags": [
          "lookup"
        ],
        "summary": "The 50 states and DC with their codes",
        "operationId": "ad-states",
        "responses": {
          "200": {
            "description": "States",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Use qa-admin-token / qa-viewer-token, or a JWT from POST /auth/v1/login."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Cargo demo key: cargo-key-123."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "requestId": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  }
}
