OpenAPITools/openapi-generator · error · IllegalArgumentException

The given HTTP status code: {} is not supported by the 'org.

Error message

The given HTTP status code: {} is not supported by the 'org.springframework.http.HttpStatus' enum.

What it means

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.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/SpringHttpStatusLambda.java:216

                writer.write(HTTP_STATUS_PREFIX + "UNAVAILABLE_FOR_LEGAL_REASONS");
                break;
            case "422":
                writer.write(HTTP_STATUS_PREFIX + "UNPROCESSABLE_ENTITY");
                break;
            case "415":
                writer.write(HTTP_STATUS_PREFIX + "UNSUPPORTED_MEDIA_TYPE");
                break;
            case "426":
                writer.write(HTTP_STATUS_PREFIX + "UPGRADE_REQUIRED");
                break;
            case "414":
                writer.write(HTTP_STATUS_PREFIX + "URI_TOO_LONG");
                break;
            case "506":
                writer.write(HTTP_STATUS_PREFIX + "VARIANT_ALSO_NEGOTIATES");
                break;
            default:
                throw new IllegalArgumentException("The given HTTP status code: " + httpCode
                        + " is not supported by the 'org.springframework.http.HttpStatus' enum.");
        }
    }
}

View on GitHub (pinned to fcec517be3)

Solutions

  1. 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.
  2. Keep the non-standard code in documentation/description text rather than as a response key.
  3. If the code is essential, patch the api.mustache template to special-case it before delegating to springHttpStatus.

Example fix

# before (openapi.yaml)
responses:
  '520':
    description: Cloudflare origin error

# after
responses:
  '502':
    description: Cloudflare origin error (mapped to Bad Gateway)
  default:
    description: Unexpected error
Defensive patterns

Strategy: validation

Validate before calling

// Node: reject response codes outside the mapped HttpStatus set before generating
const spec = require('./openapi.json');
const 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']);
for (const item of Object.values(spec.paths ?? {}))
  for (const op of Object.values(item))
    for (const code of Object.keys(op.responses ?? {}))
      if (code !== 'default' && !MAPPED.has(code))
        throw new Error(`HTTP status ${code} is not supported by Spring HttpStatus`);

Prevention

When it happens

Trigger: 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...'.

Common situations: 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.

Related errors


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/e6f889eb7f9d03eb. Report an issue: GitHub.