{
  "openapi": "3.1.0",
  "info": {
    "title": "GeoAdrese API",
    "version": "1.0.0",
    "summary": "Pretraga, normalizacija i geokodiranje hrvatskih adresa.",
    "description": "Server-to-server REST API za hrvatske adrese iz službenog DGU registra. Autentikacija: header X-API-Key. FREE ključ (5.000 upita mjesečno, 2 zahtjeva/s, jedan aktivni ključ, bez kartice) otvara se samostalno na https://api.geoadrese.net/account/ prijavom preko emaila; veći paketi dogovaraju se kroz kontakt. API ključ se ne smije ugrađivati u browser ili mobilni klijent. Mjesečnu kvotu troše samo uspješni (2xx) pozivi search, autocomplete, resolve, nearest i addresses; /v1/usage, /health i greške je ne troše. Polje score je matching/ranking signal 0–1 i nije statistička vjerojatnost; confidence je heuristička kategorija."
  },
  "servers": [{ "url": "https://api.geoadrese.net", "description": "Produkcija" }],
  "security": [{ "ApiKeyAuth": [] }],
  "tags": [
    { "name": "Search" },
    { "name": "Resolve" },
    { "name": "Reverse geocoding" },
    { "name": "Addresses" },
    { "name": "Account" }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "tags": ["Account"],
        "security": [],
        "responses": {
          "200": {
            "description": "API proces radi.",
            "content": { "application/json": { "schema": { "type": "object", "required": ["status"], "properties": { "status": { "type": "string", "const": "ok" } } } } }
          }
        }
      }
    },
    "/v1/search": {
      "get": {
        "summary": "Pretraži hrvatske adrese",
        "operationId": "searchAddresses",
        "tags": ["Search"],
        "description": "Kad u cijelom dohvaćenom skupu postoje ravnopravne različite adrese, a kandidat nema dokaz kućnog broja ili mjesta, označava se najviše kao fuzzy, čak i uz score 1. Broj vraćenih rezultata ne mijenja tu klasifikaciju. Uz sva navedena polja exact zadržava značenje literalnog podudaranja; ne jamči jedinstven DGU ID. Za odluku o jednoznačnosti koristite resolve status i confidence. Redoslijed i score ostaju ranking signali.",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "description": "Slobodno napisana adresa ili dio adrese.", "schema": { "type": "string", "minLength": 1, "maxLength": 250 }, "example": "vlasska 10 zagreb" },
          { "name": "limit", "in": "query", "description": "Maksimalan broj rezultata.", "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10 }, "example": 5 }
        ],
        "responses": {
          "200": { "description": "Rezultati pretrage.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/autocomplete": {
      "get": {
        "summary": "Autocomplete adrese",
        "operationId": "autocompleteAddresses",
        "tags": ["Search"],
        "parameters": [
          { "name": "q", "in": "query", "required": true, "description": "Tekst koji korisnik upisuje.", "schema": { "type": "string", "minLength": 3, "maxLength": 250 }, "example": "ivo lola rib" },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 10, "default": 5 } }
        ],
        "responses": {
          "200": { "description": "Prijedlozi adresa.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/resolve": {
      "post": {
        "summary": "Razriješi i normaliziraj adresu",
        "operationId": "resolveAddress",
        "tags": ["Resolve"],
        "description": "Vraća jednu kanonsku adresu. status: matched (jedan siguran kandidat), ambiguous (partial, low confidence ili više različitih adresa, tj. drugih DGU id-eva, sa scoreom unutar 0.03 od najboljeg, jednako dobrim kućnim brojem i jednako potpuno imenovanom ulicom; one su u alternatives) ili no_match (nema iskoristivog kandidata; i dalje HTTP 200). confidence: high (exact, ili fuzzy sa score >= 0.90, ulicom >= 0.80 i potpuno pokrivenim značajnim riječima ulice), medium (score >= 0.80), inače low. Uz ravnopravne različite kandidate confidence je najviše medium; postojeći low ostaje low. Kad nedostaje dokaz kućnog broja ili mjesta, type je tada najviše fuzzy. Uz sva navedena polja exact ostaje literalno podudaranje i ne jamči jedinstven ID. Sam nedostatak mjesta ili broja ne snižava jednoznačan rezultat. Kolokvijalne, inicijalne, redno/rimske i dvojezične varijante najviše su fuzzy/medium; opcionalni provenance bilježi primijenjene normalizacije. Pragovi su produktna pravila, ne kalibrirana vjerojatnost. Tijelo zahtjeva najviše 8 KB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ResolveRequest" },
              "example": { "address": "vlasska 10 zagreb" }
            }
          }
        },
        "responses": {
          "200": { "description": "matched, ambiguous ili no_match.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ResolveResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "413": { "$ref": "#/components/responses/PayloadTooLarge" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/nearest": {
      "get": {
        "summary": "Najbliže adrese koordinatama",
        "operationId": "nearestAddresses",
        "tags": ["Reverse geocoding"],
        "parameters": [
          { "name": "lat", "in": "query", "required": true, "schema": { "type": "number", "minimum": -90, "maximum": 90 }, "example": 45.8135 },
          { "name": "lon", "in": "query", "required": true, "schema": { "type": "number", "minimum": -180, "maximum": 180 }, "example": 15.9793 },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 10, "default": 3 } },
          { "name": "maxDistanceMeters", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 200000, "default": 50000 } }
        ],
        "responses": {
          "200": { "description": "Adrese sortirane po udaljenosti.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NearestResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/addresses/{id}": {
      "get": {
        "summary": "Dohvati kanonsku adresu po DGU ID-u",
        "operationId": "getAddress",
        "tags": ["Addresses"],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "maxLength": 64 }, "example": "KB.0022075340" }],
        "responses": {
          "200": { "description": "Kanonska adresa.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AddressResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Mjesečna potrošnja i kvota",
        "operationId": "getUsage",
        "tags": ["Account"],
        "responses": {
          "200": { "description": "Potrošnja za trenutačni UTC mjesec.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UsageResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-Key", "description": "API ključ oblika ga_live_… Čuvajte ga samo na serveru. FREE ključ: https://api.geoadrese.net/account/" }
    },
    "responses": {
      "BadRequest": { "description": "Neispravan zahtjev.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "Unauthorized": { "description": "API ključ nedostaje ili nije valjan.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "Forbidden": { "description": "Account je suspendiran ili onemogućen.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "NotFound": { "description": "Adresa nije pronađena.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "RateLimited": { "description": "rate_limited (prekoračen limit zahtjeva u sekundi, uz Retry-After) ili quota_exceeded (potrošena mjesečna kvota, bez Retry-After).", "headers": { "Retry-After": { "schema": { "type": "integer" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "PayloadTooLarge": { "description": "Tijelo zahtjeva je veće od 8 KB (payload_too_large).", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "Unavailable": { "description": "Servis za pretragu trenutačno nije dostupan.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "InternalError": { "description": "Neočekivana greška servera (internal_error).", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": ["error"],
        "properties": { "error": { "type": "object", "required": ["code", "message"], "properties": { "code": { "type": "string", "enum": ["invalid_parameter", "invalid_body", "missing_query", "query_too_short", "query_too_long", "invalid_limit", "invalid_coordinate", "invalid_distance", "payload_too_large", "invalid_api_key", "account_suspended", "account_disabled", "not_found", "rate_limited", "quota_exceeded", "service_unavailable", "internal_error"], "example": "invalid_parameter" }, "message": { "type": "string" } } } }
      },
      "Address": {
        "type": "object",
        "required": ["id", "label", "street", "houseNumber", "settlement", "municipality", "postalCode", "lat", "lon"],
        "properties": {
          "id": { "type": "string", "example": "KB.0022075340" },
          "label": { "type": ["string", "null"], "example": "Vlaška ulica 10, 10000 Zagreb" },
          "street": { "type": ["string", "null"], "example": "Vlaška ulica" },
          "houseNumber": { "type": ["string", "null"], "example": "10" },
          "settlement": { "type": ["string", "null"], "example": "Zagreb" },
          "municipality": { "type": ["string", "null"], "description": "Trenutno null." },
          "postalCode": { "type": ["string", "null"], "example": "10000" },
          "lat": { "type": ["number", "null"], "format": "double", "example": 45.8135437 },
          "lon": { "type": ["number", "null"], "format": "double", "example": 15.9793051 }
        }
      },
      "NormalizationProvenance": {
        "type": "object",
        "required": ["schemaVersion", "normalizations"],
        "properties": { "schemaVersion": { "type": "integer", "const": 1 }, "normalizations": { "type": "array", "items": { "type": "string" }, "description": "Potvrđene normalizacije upita; izvorna DGU adresa ostaje kanonska." } }
      },
      "SearchMatch": {
        "type": "object",
        "required": ["type", "score"],
        "properties": { "type": { "type": "string", "enum": ["exact", "fuzzy", "partial"] }, "score": { "type": "number", "minimum": 0, "maximum": 1, "description": "Matching/ranking score; nije statistička vjerojatnost." }, "provenance": { "$ref": "#/components/schemas/NormalizationProvenance" } }
      },
      "SearchAddress": {
        "allOf": [{ "$ref": "#/components/schemas/Address" }, { "type": "object", "required": ["match"], "properties": { "match": { "$ref": "#/components/schemas/SearchMatch" } } }]
      },
      "SearchResponse": {
        "type": "object",
        "required": ["data", "meta"],
        "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/SearchAddress" } }, "meta": { "type": "object", "required": ["count"], "properties": { "count": { "type": "integer" } } } }
      },
      "ResolveRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["address"],
        "properties": { "address": { "type": "string", "minLength": 1, "maxLength": 250 } }
      },
      "ResolveMatch": {
        "type": "object",
        "required": ["type", "score", "confidence", "fields"],
        "properties": {
          "type": { "type": "string", "enum": ["exact", "fuzzy", "partial"] },
          "score": { "type": "number", "minimum": 0, "maximum": 1, "description": "Nije statistička vjerojatnost." },
          "confidence": { "type": "string", "enum": ["high", "medium", "low"], "description": "Heuristička kategorija." },
          "provenance": { "$ref": "#/components/schemas/NormalizationProvenance" },
          "fields": { "type": "object", "required": ["street", "houseNumber", "place"], "properties": { "street": { "type": "number" }, "houseNumber": { "type": "number" }, "place": { "type": "number" } } }
        }
      },
      "ResolveAlternative": {
        "type": "object",
        "required": ["id", "label", "score"],
        "properties": { "id": { "type": "string" }, "label": { "type": ["string", "null"] }, "score": { "type": "number", "minimum": 0, "maximum": 1, "description": "Nije statistička vjerojatnost." } }
      },
      "ResolveResponse": {
        "type": "object",
        "required": ["data", "meta"],
        "properties": {
          "data": {
            "oneOf": [
              {
                "type": "object",
                "required": ["status", "input", "canonical", "match", "alternatives"],
                "properties": {
                  "status": { "type": "string", "enum": ["matched", "ambiguous"] },
                  "input": { "type": "string" },
                  "canonical": { "$ref": "#/components/schemas/Address" },
                  "match": { "$ref": "#/components/schemas/ResolveMatch" },
                  "alternatives": { "type": "array", "maxItems": 2, "items": { "$ref": "#/components/schemas/ResolveAlternative" }, "description": "Kod ambiguous: druge adrese koje su gotovo jednako dobre. Kod matched je prazno." }
                }
              },
              { "type": "object", "required": ["status", "input", "canonical", "match", "alternatives"], "properties": { "status": { "type": "string", "const": "no_match" }, "input": { "type": "string" }, "canonical": { "type": "null" }, "match": { "type": "null" }, "alternatives": { "type": "array", "maxItems": 0 } } }
            ]
          },
          "meta": { "type": "object", "required": ["requestId"], "properties": { "requestId": { "type": "string", "format": "uuid" } } }
        }
      },
      "NearestResponse": {
        "type": "object",
        "required": ["data", "meta"],
        "properties": {
          "data": { "type": "array", "items": { "allOf": [{ "$ref": "#/components/schemas/Address" }, { "type": "object", "required": ["distanceMeters"], "properties": { "distanceMeters": { "type": "number", "minimum": 0 } } }] } },
          "meta": {
            "type": "object",
            "required": ["count", "requestId", "query"],
            "properties": {
              "count": { "type": "integer", "minimum": 0 },
              "requestId": { "type": "string", "format": "uuid" },
              "query": { "type": "object", "required": ["lat", "lon", "limit", "maxDistanceMeters"], "properties": { "lat": { "type": "number" }, "lon": { "type": "number" }, "limit": { "type": "integer" }, "maxDistanceMeters": { "type": "integer" } } }
            }
          }
        }
      },
      "AddressResponse": { "type": "object", "required": ["data"], "properties": { "data": { "$ref": "#/components/schemas/SearchAddress" } } },
      "UsageResponse": {
        "type": "object",
        "required": ["data"],
        "properties": { "data": { "type": "object", "required": ["period", "used", "limit", "remaining", "resetAt"], "properties": { "period": { "type": "string", "example": "2026-10" }, "used": { "type": "integer" }, "limit": { "type": "integer" }, "remaining": { "type": "integer" }, "resetAt": { "type": "string", "format": "date-time" } } } }
      }
    }
  }
}
