{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/zuegle-com/json-schema/zuegle-com-listing-recommendations-schema.json",
  "title": "ListingRecommendations",
  "description": "Listings found in one municipality. `cached` says whether this came from the 6-hour cache. Every figure is indicative — see the route description.",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/zuegle-com-openapi.yaml#/components/schemas/ListingRecommendations",
  "type": "object",
  "properties": {
    "bfsId": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "canton": {
      "type": "string"
    },
    "cached": {
      "type": "boolean"
    },
    "fetchedAt": {
      "type": "integer",
      "description": "Epoch ms when the portals were last queried for this municipality."
    },
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ListingSummary"
      }
    },
    "matchedCount": {
      "type": [
        "integer",
        "null"
      ],
      "description": "How many of `items` are within one room of the caller's `rooms`. Null when no size was supplied, in which case `items` keeps the plain cheapest-first order and carries no `fit`/`similarity`."
    },
    "rent": {
      "description": "Official BFS average rent. NOTE the geography: BFS does not publish rent below canton level (the source is a ~200k-household sample, so per-commune cells fall under the confidentiality threshold), so for almost every municipality `basis` is \"canton\" and the figure describes the canton, not the town. Only the 10 cities BFS tabulates individually return basis \"city\". Null when no figure applies — the national average is never substituted. Licensed terms_by: consumers must display the attribution carried in `source`.",
      "nullable": true,
      "allOf": [
        {
          "$ref": "#/$defs/BfsRent"
        }
      ]
    },
    "rentStats": {
      "description": "Live median ASKING rent of listings currently advertised in this municipality — a different question from `rent`, and never merged with it. Computed over the full residential result set before the cheapest-first sort and the item limit, which is what makes it a median rather than a floor. Null when fewer than 5 usable listings, and null when the area hit the provider's result cap (a capped subset's median is not the municipality's median).",
      "nullable": true,
      "allOf": [
        {
          "$ref": "#/$defs/LiveRentStats"
        }
      ]
    },
    "errors": {
      "type": "array",
      "description": "Per-provider failures. A portal that fails degrades the list instead of blanking it, and the failure is reported rather than dropped — an empty list with no errors genuinely means \"nothing for rent here\".",
      "items": {
        "type": "object",
        "properties": {
          "source": {
            "type": "string"
          },
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "$defs": {
    "BfsRent": {
      "type": "object",
      "properties": {
        "value": {
          "type": "number",
          "description": "Average rent in CHF per month."
        },
        "basis": {
          "type": "string",
          "enum": [
            "city",
            "canton"
          ],
          "description": "WHICH GEOGRAPHY the figure describes. The UI must surface this — rendering a cantonal average under a municipality's name without saying so presents one geography's number as another's."
        },
        "label": {
          "type": "string",
          "description": "The canton abbreviation",
          "or the city name.": null
        },
        "year": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "string"
            }
          ],
          "description": "A year for canton figures; a cumulated window like \"2022-2024\" for cities."
        },
        "marginChf": {
          "type": [
            "number",
            "null"
          ],
          "description": "The ± confidence interval BFS publishes. Deliberately not a sample count — BFS does not publish one, and inventing it would be fabrication."
        },
        "source": {
          "type": "object",
          "description": "Attribution required by the terms_by licence.",
          "properties": {
            "name": {
              "type": "string"
            },
            "url": {
              "type": "string",
              "format": "uri"
            },
            "retrievedAt": {
              "type": "string",
              "format": "date-time"
            }
          }
        }
      }
    },
    "ListingSummary": {
      "type": "object",
      "description": "The public projection of one listing (server/listingSponsors.js toPublicListing). Sponsor internals - weight, schedule, enabled - are never included.",
      "properties": {
        "source": {
          "type": "string"
        },
        "sourceId": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "title": {
          "type": [
            "string",
            "null"
          ]
        },
        "zip": {
          "type": [
            "string",
            "null"
          ]
        },
        "city": {
          "type": [
            "string",
            "null"
          ]
        },
        "rooms": {
          "type": [
            "number",
            "null"
          ]
        },
        "surface": {
          "type": [
            "number",
            "null"
          ]
        },
        "rentGross": {
          "type": [
            "number",
            "null"
          ]
        },
        "image": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "sponsored": {
          "type": "boolean",
          "description": "Present and true only on a paid placement. Always accompanied by sponsorLabel, which the UI must display - there is no way to promote a listing silently."
        },
        "sponsorLabel": {
          "type": [
            "string",
            "null"
          ]
        },
        "fit": {
          "type": "boolean",
          "description": "Present only when the request supplied a size. True when this listing is within one room of the caller's, and true for a listing that states no room count at all — an unstated size is not evidence of a mismatch, and hiding it behind the \"show all\" toggle would be a hard filter by the back door."
        },
        "similarity": {
          "type": [
            "number",
            "null"
          ],
          "description": "0-1, how close this listing is to the caller's home (rooms dominant, m² as tiebreak). Present only when the request supplied a size. The sort key behind the order of `items`."
        }
      }
    },
    "LiveRentStats": {
      "type": "object",
      "properties": {
        "median": {
          "type": "number",
          "description": "Median asking rent",
          "CHF/month.": null
        },
        "count": {
          "type": "integer",
          "description": "Usable listings the median was computed over."
        },
        "medianPerM2": {
          "type": [
            "number",
            "null"
          ],
          "description": "Median of the per-listing CHF/m² ratios — not median rent divided by median surface, which is a different and wrong statistic."
        },
        "sizedCount": {
          "type": "integer",
          "description": "Listings whose room count is known — the denominator for \"what share of this market is my size\". Deliberately not `count`, which counts PRICED listings."
        },
        "byRooms": {
          "type": "object",
          "description": "The room-size distribution of what is on the market here, keyed by room count snapped to the nearest half (\"1\", \"1.5\", \"2\"…). Two consumers with different strictness, hence two fields per bucket: `count` always (server/recommend.js's `fit` criterion needs the counts, and two 4.5s on offer is a real fact), `median` only above 5 listings in that bucket (a median over two is noise). Never guessed from a neighbouring bucket.",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer"
              },
              "median": {
                "type": [
                  "number",
                  "null"
                ]
              }
            }
          }
        }
      }
    }
  }
}