{"record":{"id":"e6f889eb7f9d03eb","repo":"OpenAPITools/openapi-generator","slug":"the-given-http-status-code-is-not-supported-by","errorCode":null,"errorMessage":"The given HTTP status code: {} is not supported by the 'org.springframework.http.HttpStatus' enum.","messagePattern":"The given HTTP status code: (.+?) is not supported by the 'org\\.springframework\\.http\\.HttpStatus' enum\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/SpringHttpStatusLambda.java","lineNumber":216,"sourceCode":"                writer.write(HTTP_STATUS_PREFIX + \"UNAVAILABLE_FOR_LEGAL_REASONS\");\n                break;\n            case \"422\":\n                writer.write(HTTP_STATUS_PREFIX + \"UNPROCESSABLE_ENTITY\");\n                break;\n            case \"415\":\n                writer.write(HTTP_STATUS_PREFIX + \"UNSUPPORTED_MEDIA_TYPE\");\n                break;\n            case \"426\":\n                writer.write(HTTP_STATUS_PREFIX + \"UPGRADE_REQUIRED\");\n                break;\n            case \"414\":\n                writer.write(HTTP_STATUS_PREFIX + \"URI_TOO_LONG\");\n                break;\n            case \"506\":\n                writer.write(HTTP_STATUS_PREFIX + \"VARIANT_ALSO_NEGOTIATES\");\n                break;\n            default:\n                throw new IllegalArgumentException(\"The given HTTP status code: \" + httpCode\n                        + \" is not supported by the 'org.springframework.http.HttpStatus' enum.\");\n        }\n    }\n}\n","sourceCodeStart":198,"sourceCodeEnd":221,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/SpringHttpStatusLambda.java#L198-L221","documentation":"SpringHttpStatusLambda is registered as 'springHttpStatus' by the spring and kotlin-spring generators; it maps an HTTP status code string from the spec to an org.springframework.http.HttpStatus enum constant in generated code. Its switch covers all standard statuses plus many non-standard ones (418, 425, 428, 431, 451, 509, 510, 511, 226...), but any code outside that list — e.g. 421, 520-524 (Cloudflare), 599, or a vendor code — falls into default and throws IllegalArgumentException during template rendering.","triggerScenarios":"A spec response like '421:' or '520:' under an operation's responses, rendered through {{#springHttpStatus}}{{code}}{{/springHttpStatus}} in the spring/kotlin-spring api template. Generation aborts with 'The given HTTP status code: 520 is not supported...'.","commonSituations":"Specs that document CDN or gateway error codes (Cloudflare 520-522), internal telemetry codes (599), or HTTP 421 Misdirected Request; importing third-party API specs whose providers use non-standard statuses; Spring's HttpStatus enum simply lacking the constant, so the lambda cannot emit a mapping.","solutions":["Replace the non-standard status in the spec with the closest standard one (520/521 -> 502, 524 -> 504, 421 -> 400) or fold it into the 'default' response.","Keep the non-standard code in documentation/description text rather than as a response key.","If the code is essential, patch the api.mustache template to special-case it before delegating to springHttpStatus."],"exampleFix":"# before (openapi.yaml)\nresponses:\n  '520':\n    description: Cloudflare origin error\n\n# after\nresponses:\n  '502':\n    description: Cloudflare origin error (mapped to Bad Gateway)\n  default:\n    description: Unexpected error","handlingStrategy":"validation","validationCode":"// Node: reject response codes outside the mapped HttpStatus set before generating\nconst spec = require('./openapi.json');\nconst MAPPED = new Set(['100','101','102','103','200','201','202','203','204','205','206','207','208','226','300','301','302','303','304','307','308','400','401','402','403','404','405','406','407','408','409','410','411','412','413','414','415','416','417','418','422','423','424','425','426','428','429','431','451','500','501','502','503','504','505','506','507','508','509','510','511']);\nfor (const item of Object.values(spec.paths ?? {}))\n  for (const op of Object.values(item))\n    for (const code of Object.keys(op.responses ?? {}))\n      if (code !== 'default' && !MAPPED.has(code))\n        throw new Error(`HTTP status ${code} is not supported by Spring HttpStatus`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document vendor-specific statuses (520, 599...) in response descriptions, not as response keys.","Add a spectral rule that restricts response codes to standard HTTP statuses for spring/kotlin-spring targets."],"tags":["spring","java","http-status","openapi","codegen"],"backgroundTag":"unsupported-http-status-code","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}