Parse @errors {400: desc, 401: desc} or @errors {400, 401}.
(line: str)
| 316 | |
| 317 | |
| 318 | def _parse_errors(line: str) -> list[ErrorSchema]: |
| 319 | """Parse @errors {400: desc, 401: desc} or @errors {400, 401}.""" |
| 320 | m = re.match(r'^@errors\s*\{(.*)\}\s*$', line, re.DOTALL) |
| 321 | if not m: |
| 322 | return [] |
| 323 | content = m.group(1).strip() |
| 324 | parts = _split_error_entries(content) |
| 325 | errors = [] |
| 326 | for part in parts: |
| 327 | part = part.strip() |
| 328 | if ':' in part: |
| 329 | # Could be "400: desc" or "400:type: desc" |
| 330 | first_colon = part.index(':') |
| 331 | code_part = part[:first_colon].strip() |
| 332 | rest = part[first_colon + 1:].strip() |
| 333 | # Check if rest starts with a type (no spaces before next colon) |
| 334 | type_m = re.match(r'^(\S+?):\s*(.*)$', rest) |
| 335 | if type_m and ' ' not in type_m.group(1): |
| 336 | errors.append(ErrorSchema(code=code_part, type=type_m.group(1), description=type_m.group(2))) |
| 337 | else: |
| 338 | errors.append(ErrorSchema(code=code_part, description=rest)) |
| 339 | else: |
| 340 | errors.append(ErrorSchema(code=part)) |
| 341 | return errors |
| 342 | |
| 343 | |
| 344 | def _parse_params_block(line: str) -> list[Param]: |