{
 "openapi": "3.1.0",
 "info": {
  "title": "How We Age open data API",
  "version": "1.1.0",
  "description": "Read-only, precomputed survey-weighted aggregates from CDC/NCHS NHANES August 2021 – August 2023. Aggregates only; no participant-level data. Release nhanes-2021-2023-v1.0.0. Independent project, not endorsed by CDC/NCHS.",
  "license": {
   "name": "Data: CC BY 4.0; code: MIT",
   "url": "https://creativecommons.org/licenses/by/4.0/"
  }
 },
 "servers": [
  {
   "url": "https://suchee.org/how-we-age/api/v1"
  }
 ],
 "paths": {
  "/health": {
   "get": {
    "summary": "Service and release status",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/releases": {
   "get": {
    "summary": "Immutable releases with file checksums",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/metrics": {
   "get": {
    "summary": "List metrics",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/metrics/{metric_id}": {
   "get": {
    "summary": "Metric definition and source",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "Unknown metric",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/metrics/{metric_id}/distributions": {
   "get": {
    "summary": "Distribution records by age band and sex",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     },
     {
      "name": "cycle",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "2021-2023"
       ]
      }
     },
     {
      "name": "sex",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "female",
        "male",
        "all"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DistributionCollection"
        }
       }
      }
     },
     "400": {
      "description": "Unsupported cycle or sex category",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Unknown metric",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/metrics/{metric_id}/distributions.csv": {
   "get": {
    "summary": "Same, as CSV (one row per statistic)",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     },
     {
      "name": "cycle",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "2021-2023"
       ]
      }
     },
     {
      "name": "sex",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "female",
        "male",
        "all"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "CSV",
      "content": {
       "text/csv": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "400": {
      "description": "Unsupported cycle or sex category",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/metrics/{metric_id}/age-bands/{age_band}": {
   "get": {
    "summary": "All sex categories for one age band",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     },
     {
      "name": "age_band",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "20-29",
        "30-39",
        "40-49",
        "50-59",
        "60-69",
        "70-79",
        "80-and-over",
        "20-and-over"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DistributionCollection"
        }
       }
      }
     },
     "400": {
      "description": "Invalid age band (e.g. any age above 80)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/metrics/{metric_id}/shape": {
   "get": {
    "summary": "Distribution shape: weighted histogram shares, quantiles and CDF grid with 95% CIs and the value-lookup support, for every age band and sex",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Shape"
        }
       }
      }
     },
     "404": {
      "description": "Unknown metric, or no shape aggregate published for it",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/metrics/{metric_id}/treatment-context": {
   "get": {
    "summary": "Share reporting relevant current medication, for: Total cholesterol, HDL cholesterol, HbA1c (glycohemoglobin), Systolic blood pressure, Diastolic blood pressure, Triglycerides (fasting) and Fasting plasma glucose",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "No context for this metric",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/age-bands": {
   "get": {
    "summary": "Age bands and top-code notice",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/methods": {
   "get": {
    "summary": "Estimation methods and versions",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/sources": {
   "get": {
    "summary": "Source files with SHA-256 checksums and terms",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/citations/{metric_id}": {
   "get": {
    "summary": "How to cite a metric",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "Unknown metric",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/expanded": {
   "get": {
    "summary": "The 180 measures added in rc5 (index)",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/expanded/{metric_id}": {
   "get": {
    "summary": "One rc5 measure: definition, every distribution statistic and share, with quality status",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "Unknown metric",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/questionnaire": {
   "get": {
    "summary": "The 204 questionnaire items (index)",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/questionnaire/{metric_id}": {
   "get": {
    "summary": "One questionnaire item: question, who was asked, answer shares and percentiles, with quality status",
    "parameters": [
     {
      "name": "metric_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "total-cholesterol",
        "hdl-cholesterol",
        "hba1c",
        "bmi",
        "waist",
        "systolic-bp",
        "diastolic-bp",
        "body-weight",
        "standing-height",
        "pulse-rate",
        "hemoglobin",
        "serum-creatinine",
        "vitamin-d-25ohd",
        "hs-crp",
        "triglycerides-fasting",
        "fasting-glucose",
        "liver-stiffness",
        "liver-cap",
        "sleep-hours"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "Unknown metric",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Statistic": {
    "type": "object",
    "required": [
     "estimate",
     "se",
     "ci95",
     "quality"
    ],
    "properties": {
     "estimate": {
      "type": [
       "number",
       "null"
      ]
     },
     "se": {
      "type": [
       "number",
       "null"
      ]
     },
     "ci95": {
      "oneOf": [
       {
        "type": "null"
       },
       {
        "type": "array",
        "items": {
         "type": [
          "number",
          "null"
         ]
        },
        "minItems": 2,
        "maxItems": 2
       }
      ]
     },
     "n_eff": {
      "type": [
       "number",
       "null"
      ]
     },
     "quality": {
      "$ref": "#/components/schemas/Quality"
     }
    }
   },
   "Distribution": {
    "type": "object",
    "required": [
     "metric_id",
     "release_id",
     "cycle",
     "age_band",
     "sex",
     "unit",
     "statistics",
     "sample",
     "quality",
     "source"
    ],
    "properties": {
     "metric_id": {
      "type": "string",
      "enum": [
       "total-cholesterol",
       "hdl-cholesterol",
       "hba1c",
       "bmi",
       "waist",
       "systolic-bp",
       "diastolic-bp",
       "body-weight",
       "standing-height",
       "pulse-rate",
       "hemoglobin",
       "serum-creatinine",
       "vitamin-d-25ohd",
       "hs-crp",
       "triglycerides-fasting",
       "fasting-glucose",
       "liver-stiffness",
       "liver-cap",
       "sleep-hours"
      ]
     },
     "release_id": {
      "type": "string"
     },
     "method_version": {
      "type": "string"
     },
     "population": {
      "type": "string"
     },
     "survey": {
      "const": "NHANES"
     },
     "cycle": {
      "const": "2021-2023"
     },
     "age_band": {
      "type": "string",
      "enum": [
       "20-29",
       "30-39",
       "40-49",
       "50-59",
       "60-69",
       "70-79",
       "80-and-over",
       "20-and-over"
      ]
     },
     "age_band_label": {
      "type": "string"
     },
     "sex": {
      "type": "string",
      "enum": [
       "female",
       "male",
       "all"
      ]
     },
     "unit": {
      "type": "string"
     },
     "statistics": {
      "type": "object",
      "required": [
       "mean",
       "p10",
       "p25",
       "p50",
       "p75",
       "p90"
      ],
      "properties": {
       "mean": {
        "$ref": "#/components/schemas/Statistic"
       },
       "p10": {
        "$ref": "#/components/schemas/Statistic"
       },
       "p25": {
        "$ref": "#/components/schemas/Statistic"
       },
       "p50": {
        "$ref": "#/components/schemas/Statistic"
       },
       "p75": {
        "$ref": "#/components/schemas/Statistic"
       },
       "p90": {
        "$ref": "#/components/schemas/Statistic"
       }
      }
     },
     "sample": {
      "type": "object",
      "required": [
       "n_unweighted",
       "design_df",
       "weight"
      ],
      "properties": {
       "n_unweighted": {
        "type": "integer"
       },
       "n_missing_value": {
        "type": "integer"
       },
       "design_df": {
        "type": "integer"
       },
       "weight": {
        "type": "string",
        "enum": [
         "WTINT2YR",
         "WTMEC2YR",
         "WTPH2YR",
         "WTSAF2YR"
        ]
       }
      }
     },
     "quality": {
      "type": "object",
      "required": [
       "status"
      ],
      "properties": {
       "status": {
        "enum": [
         "ok",
         "partial",
         "suppressed"
        ]
       },
       "suppressed": {
        "type": "array"
       }
      }
     },
     "estimators": {
      "type": "object"
     },
     "source": {
      "$ref": "#/components/schemas/Source"
     }
    }
   },
   "DistributionCollection": {
    "type": "object",
    "required": [
     "metric_id",
     "release_id",
     "count",
     "data"
    ],
    "properties": {
     "metric_id": {
      "type": "string"
     },
     "release_id": {
      "type": "string"
     },
     "cycle": {
      "const": "2021-2023"
     },
     "sex": {
      "type": "string"
     },
     "age_band": {
      "type": "string"
     },
     "count": {
      "type": "integer"
     },
     "data": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Distribution"
      }
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "object",
      "required": [
       "type",
       "status",
       "message"
      ],
      "properties": {
       "type": {
        "type": "string"
       },
       "status": {
        "type": "integer"
       },
       "message": {
        "type": "string"
       },
       "allowed": {
        "type": [
         "array",
         "null"
        ]
       }
      }
     }
    }
   },
   "Quality": {
    "type": "object",
    "required": [
     "status",
     "reasons"
    ],
    "properties": {
     "status": {
      "enum": [
       "ok",
       "suppressed",
       "review"
      ]
     },
     "reasons": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "Source": {
    "type": "object",
    "required": [
     "dataset",
     "field",
     "codebook_url",
     "weight"
    ],
    "properties": {
     "survey": {
      "type": "string"
     },
     "dataset": {
      "type": "string"
     },
     "field": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "data_url": {
      "type": "string"
     },
     "codebook_url": {
      "type": "string"
     },
     "weight": {
      "type": "string"
     }
    }
   },
   "Shape": {
    "title": "How We Age - distribution shape and value-lookup document (one per metric)",
    "description": "Survey-weighted histogram, 19 quantiles and CDF grid with 95% confidence intervals for each adult age band x recorded sex domain of one metric, plus the data needed to apply the value-lookup rule (docs/SHAPES_METHODS.md). Aggregates only; suppressed numbers are null with reason codes. Producer: analysis/shapes_export.py. Schema 1.1 (backward compatible with 1.0 documents): optional scale, density_basis, coded_values; build_status release_candidate; message pieces for open CI bounds. Schema 1.2 (backward compatible with 1.0/1.1 documents): lookup_rule.version '2' answers whenever SR2-175 passes, adds less_certain_width, answer_rule and technical templates; max_ci_width is required only for rule v1. Schema 1.3 (backward compatible with 1.0-1.2): optional detection_limit {value, varying, label} (lookup returns below_detection_limit for a rounded value below it) and optional cdf_grid.rule (the grid is a documented subset of recordable values; lookups between grid values interpolate). Used by the rc5 measures. Schema 1.3.1 (backward compatible): optional bins[].kind ('value' default, 'below_detection_limit', 'below_detection_limit_range') and bins[].label; detection_limit.bin_index / bin_upper. For a detection-limit measure bin 0 is one bar (-inf, bin_upper) holding the results below the limit; its share is the release share below the limit.",
    "type": "object",
    "additionalProperties": false,
    "required": [
     "schema_version",
     "build_id",
     "build_status",
     "metric_id",
     "metric_label",
     "unit",
     "release_id",
     "method_version",
     "bins_version",
     "computed_at",
     "population",
     "survey_cycle",
     "source",
     "age_bands_note",
     "bins",
     "bins_closed",
     "cdf_grid",
     "quantile_probabilities",
     "lookup_rule",
     "domains"
    ],
    "properties": {
     "schema_version": {
      "type": "string"
     },
     "build_id": {
      "type": "string"
     },
     "build_status": {
      "enum": [
       "development",
       "release_candidate",
       "release"
      ]
     },
     "metric_id": {
      "type": "string",
      "pattern": "^[a-z0-9-]+$"
     },
     "metric_label": {
      "type": "string"
     },
     "unit": {
      "type": "string"
     },
     "release_id": {
      "type": "string",
      "description": "Aggregate release whose analytic tables and methods this document derives from."
     },
     "method_version": {
      "type": "string"
     },
     "bins_version": {
      "type": "string"
     },
     "computed_at": {
      "type": "string",
      "format": "date-time"
     },
     "population": {
      "type": "string"
     },
     "survey_cycle": {
      "type": "string"
     },
     "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "dataset",
       "field",
       "weight_variable",
       "codebook_url"
      ],
      "properties": {
       "dataset": {
        "type": "string"
       },
       "field": {
        "type": "string"
       },
       "weight_variable": {
        "enum": [
         "WTMEC2YR",
         "WTPH2YR",
         "WTSAF2YR",
         "WTINT2YR",
         "WTSPF2YR",
         "WTSVOC2Y"
        ],
        "description": "1.3 adds WTSPF2YR (PFAS subsample) and WTSVOC2Y (blood VOC subsample) for rc5 measures"
       },
       "codebook_url": {
        "type": "string",
        "format": "uri"
       }
      }
     },
     "age_bands_note": {
      "type": "string"
     },
     "bins": {
      "type": "array",
      "minItems": 3,
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "index",
        "lower",
        "upper"
       ],
       "properties": {
        "index": {
         "type": "integer",
         "minimum": 0
        },
        "lower": {
         "type": [
          "number",
          "null"
         ]
        },
        "upper": {
         "type": [
          "number",
          "null"
         ]
        },
        "kind": {
         "enum": [
          "value",
          "below_detection_limit",
          "below_detection_limit_range"
         ],
         "default": "value"
        },
        "label": {
         "type": "string"
        }
       }
      },
      "description": "Fixed bins shared by every domain. First bin has lower=null (open), last bin upper=null (open)."
     },
     "bins_closed": {
      "type": "string"
     },
     "cdf_grid": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "definition",
       "denominator",
       "v",
       "decimals"
      ],
      "properties": {
       "definition": {
        "type": "string"
       },
       "denominator": {
        "type": "integer",
        "minimum": 1,
        "description": "every grid value is k/denominator; equals 1/(recorded resolution)"
       },
       "v": {
        "type": "array",
        "minItems": 2,
        "items": {
         "type": "number"
        }
       },
       "decimals": {
        "type": "integer"
       },
       "rule": {
        "type": "string"
       },
       "between": {
        "enum": [
         "linear",
         "step"
        ],
        "default": "linear",
        "description": "how to read F between grid values: linear interpolation (default), or step = F at the largest grid value <= v (exact when every recorded value is a grid point)"
       },
       "range": {
        "type": "string"
       }
      }
     },
     "quantile_probabilities": {
      "type": "array",
      "minItems": 19,
      "maxItems": 19,
      "items": {
       "type": "number",
       "minimum": 0,
       "maximum": 1
      }
     },
     "lookup_rule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "p_low",
       "p_high",
       "rounding",
       "interpolation",
       "age_to_band",
       "messages",
       "method_doc",
       "support_fallback",
       "input_resolution"
      ],
      "properties": {
       "p_low": {
        "const": 0.05
       },
       "p_high": {
        "const": 0.95
       },
       "max_ci_width": {
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 0.1
       },
       "rounding": {
        "const": 5
       },
       "interpolation": {
        "type": "string"
       },
       "age_to_band": {
        "type": "string"
       },
       "messages": {
        "type": "object",
        "required": [
         "supported",
         "supported_alt",
         "below_support",
         "above_support",
         "too_uncertain",
         "unavailable"
        ],
        "additionalProperties": {
         "type": "string"
        },
        "description": "Templates. 1.1 adds ci_low_bounded/ci_low_open/ci_high_bounded/ci_high_open: the CI lower bound is ci_low_open ('below the 5th') when X_lo < 5, the upper bound ci_high_open ('above the 95th') when X_hi > 95."
       },
       "method_doc": {
        "type": "string"
       },
       "support_fallback": {
        "type": "string"
       },
       "input_resolution": {
        "type": "string"
       },
       "version": {
        "enum": [
         "1",
         "2"
        ],
        "description": "absent = rule v1 (CI-width refusal, builds up to rc3-shapes)"
       },
       "less_certain_width": {
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 0.3
       },
       "answer_rule": {
        "type": "string"
       },
       "technical": {
        "type": "object",
        "additionalProperties": {
         "type": "string"
        }
       }
      },
      "allOf": [
       {
        "if": {
         "properties": {
          "version": {
           "const": "2"
          }
         },
         "required": [
          "version"
         ]
        },
        "then": {
         "required": [
          "less_certain_width",
          "answer_rule",
          "technical"
         ],
         "not": {
          "required": [
           "max_ci_width"
          ]
         }
        },
        "else": {
         "required": [
          "max_ci_width"
         ]
        }
       }
      ]
     },
     "domains": {
      "type": "array",
      "minItems": 1,
      "items": {
       "$ref": "#/components/schemas/Shape_domain"
      }
     },
     "scale": {
      "enum": [
       "linear",
       "log"
      ],
      "default": "linear",
      "description": "x-axis scale for display. Absent = linear (schema 1.0 documents). For log, bins are on a round geometric series and density is per unit log10(value)."
     },
     "density_basis": {
      "type": "string",
      "description": "how to turn a bin share into a density for drawing"
     },
     "coded_values": {
      "type": "array",
      "description": "recorded values that stand for a range of true values (detection-limit fill, device limits, top/bottom codes). Quantiles inside the range and CDF points with lower <= v < upper are suppressed with reason_code.",
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "value",
        "lower",
        "upper",
        "upper_exclusive",
        "reason_code",
        "label"
       ],
       "properties": {
        "value": {
         "type": "number"
        },
        "lower": {
         "type": [
          "number",
          "null"
         ]
        },
        "upper": {
         "type": [
          "number",
          "null"
         ]
        },
        "upper_exclusive": {
         "type": "boolean"
        },
        "reason_code": {
         "type": "string",
         "pattern": "^[A-Z0-9_]+$"
        },
        "label": {
         "type": "string"
        }
       }
      }
     },
     "detection_limit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "value",
       "varying",
       "label"
      ],
      "properties": {
       "value": {
        "type": "number",
        "exclusiveMinimum": 0
       },
       "varying": {
        "type": "boolean"
       },
       "label": {
        "type": "string"
       },
       "bin_index": {
        "type": "integer",
        "minimum": 0
       },
       "bin_upper": {
        "type": "number"
       }
      },
      "description": "lower limit of detection (LLOD_ref, docs/PRESPEC_RC5.md section 3); readings below it are never placed"
     }
    }
   },
   "Shape_domain": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "age_band",
     "sex",
     "n_raw",
     "design_df",
     "status",
     "reasons",
     "histogram",
     "quantiles",
     "cdf",
     "lookup"
    ],
    "properties": {
     "age_band": {
      "enum": [
       "20-29",
       "30-39",
       "40-49",
       "50-59",
       "60-69",
       "70-79",
       "80+",
       "20+"
      ],
      "description": "80+ is the single top-coded group; 20+ = all adults. No other bands exist."
     },
     "sex": {
      "enum": [
       "all",
       "female",
       "male"
      ],
      "description": "NHANES recorded sex (RIAGENDR); all = both combined"
     },
     "n_raw": {
      "type": "integer",
      "minimum": 0
     },
     "design_df": {
      "type": "integer"
     },
     "status": {
      "enum": [
       "ok",
       "review",
       "suppressed"
      ]
     },
     "reasons": {
      "type": "array",
      "items": {
       "type": "string",
       "pattern": "^[A-Z0-9_]+$"
      }
     },
     "histogram": {
      "type": "array",
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "index",
        "share",
        "lo",
        "hi",
        "status",
        "reasons"
       ],
       "properties": {
        "index": {
         "type": "integer",
         "minimum": 0
        },
        "share": {
         "type": [
          "number",
          "null"
         ],
         "minimum": 0,
         "maximum": 1
        },
        "lo": {
         "type": [
          "number",
          "null"
         ]
        },
        "hi": {
         "type": [
          "number",
          "null"
         ]
        },
        "status": {
         "enum": [
          "ok",
          "review",
          "suppressed"
         ]
        },
        "reasons": {
         "type": "array",
         "items": {
          "type": "string",
          "pattern": "^[A-Z0-9_]+$"
         }
        }
       }
      }
     },
     "quantiles": {
      "type": "array",
      "minItems": 19,
      "maxItems": 19,
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "p",
        "est",
        "lo",
        "hi",
        "status",
        "interval_status",
        "reasons"
       ],
       "properties": {
        "p": {
         "type": "number",
         "minimum": 0,
         "maximum": 1
        },
        "est": {
         "type": [
          "number",
          "null"
         ]
        },
        "lo": {
         "type": [
          "number",
          "null"
         ]
        },
        "hi": {
         "type": [
          "number",
          "null"
         ]
        },
        "status": {
         "enum": [
          "ok",
          "review",
          "suppressed"
         ]
        },
        "interval_status": {
         "enum": [
          "estimated",
          "unavailable"
         ]
        },
        "reasons": {
         "type": "array",
         "items": {
          "type": "string",
          "pattern": "^[A-Z0-9_]+$"
         }
        }
       }
      }
     },
     "cdf": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "F",
       "lo",
       "hi"
      ],
      "description": "Arrays aligned with cdf_grid.v; null where the CDF value is suppressed (NCHS SR2-175).",
      "properties": {
       "F": {
        "type": "array",
        "items": {
         "type": [
          "number",
          "null"
         ],
         "minimum": 0,
         "maximum": 1
        }
       },
       "lo": {
        "type": "array",
        "items": {
         "type": [
          "number",
          "null"
         ],
         "minimum": 0,
         "maximum": 1
        }
       },
       "hi": {
        "type": "array",
        "items": {
         "type": [
          "number",
          "null"
         ],
         "minimum": 0,
         "maximum": 1
        }
       }
      }
     },
     "lookup": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "status",
       "reason",
       "supported_low",
       "supported_low_p",
       "supported_high",
       "supported_high_p",
       "supported_ranges"
      ],
      "properties": {
       "status": {
        "enum": [
         "available",
         "unavailable"
        ]
       },
       "reason": {
        "type": "string"
       },
       "supported_low": {
        "type": [
         "number",
         "null"
        ],
        "description": "lowest published quantile used as lower support boundary (P5 unless suppressed)"
       },
       "supported_high": {
        "type": [
         "number",
         "null"
        ],
        "description": "highest published quantile used as upper support boundary (P95 unless suppressed)"
       },
       "supported_ranges": {
        "type": "array",
        "items": {
         "type": "array",
         "minItems": 2,
         "maxItems": 2,
         "items": {
          "type": "number"
         }
        },
        "description": "contiguous grid ranges where an answer is given (inside the support and, for rule v1, CI width <= max_ci_width)"
       },
       "supported_low_p": {
        "type": [
         "integer",
         "null"
        ],
        "minimum": 5,
        "maximum": 50,
        "description": "percentile (x100) of supported_low"
       },
       "supported_high_p": {
        "type": [
         "integer",
         "null"
        ],
        "minimum": 50,
        "maximum": 95,
        "description": "percentile (x100) of supported_high"
       }
      },
      "if": {
       "properties": {
        "status": {
         "const": "available"
        }
       }
      },
      "then": {
       "properties": {
        "supported_low": {
         "type": "number"
        },
        "supported_high": {
         "type": "number"
        },
        "supported_low_p": {
         "type": "integer"
        },
        "supported_high_p": {
         "type": "integer"
        }
       }
      }
     }
    }
   }
  }
 }
}