OpenAPITools/openapi-generator · error · IllegalArgumentException
Invalid HTTP library " + getLibrary() + ". Only httr, httr2
Error message
Invalid HTTP library " + getLibrary() + ". Only httr, httr2 are supported.
What it means
The R client generator supports exactly two HTTP libraries: httr and httr2. In processOpts() the library value selects template branches (httr2 additionally enables the generateWrapper option and the *_api.R wrapper); any other -l/--library value falls into the else branch and throws IllegalArgumentException listing the supported values.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java:348
supportingFiles.add(new SupportingFile("ApiResponse.mustache", File.separator + "R", "api_response.R"));
supportingFiles.add(new SupportingFile("api_client.mustache", File.separator + "R", "api_client.R"));
supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE"));
supportingFiles.add(new SupportingFile("testthat.mustache", File.separator + "tests", "testthat.R"));
supportingFiles.add(new SupportingFile("r-client.mustache", File.separator + ".github" + File.separator + "workflows", "r-client.yaml"));
supportingFiles.add(new SupportingFile("lintr.mustache", "", ".lintr"));
if (HTTR.equals(getLibrary())) {
// for httr
setLibrary(HTTR);
} else if (HTTR2.equals(getLibrary())) {
// for httr2
setLibrary(HTTR2);
additionalProperties.put("isHttr2", Boolean.TRUE);
if (generateWrapper) { // generateWrapper option only supports in httr2 library
supportingFiles.add(new SupportingFile("api_wrapper.mustache", "R", packageName.toLowerCase(Locale.ROOT) + "_api.R"));
}
} else {
throw new IllegalArgumentException("Invalid HTTP library " + getLibrary() + ". Only httr, httr2 are supported.");
}
// add lambda for mustache templates to fix license field
additionalProperties.put("lambdaLicense", new Mustache.Lambda() {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String content = fragment.execute();
content = content.trim().replace("Apache-2.0", "Apache License 2.0");
writer.write(content);
}
});
// add lambda for mustache templates to escape %
additionalProperties.put("lambdaRdocEscape", new Mustache.Lambda() {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String content = fragment.execute();
content = content.trim().replace("%", "\\%");View on GitHub (pinned to fcec517be3)
Solutions
- Use -l httr or -l httr2 (exact lowercase)
- Omit -l entirely to take the generator default instead of guessing a value
- If you need the wrapper API, use -l httr2 together with -c generateWrapper=true (wrapper is httr2-only)
Example fix
# before openapi-generator-cli generate -i api.yaml -g r -l httr3 # after openapi-generator-cli generate -i api.yaml -g r -l httr2 -c generateWrapper=true
Defensive patterns
Strategy: validation
Validate before calling
# bash: whitelist the library before generating
R_LIBS='httr httr2'
[[ " ${R_LIBS} " == *" ${R_LIBRARY:-httr} "* ]] || { echo "-l must be one of: ${R_LIBS}"; exit 1; }
openapi-generator-cli generate -i api.yaml -g r -l "${R_LIBRARY:-httr}" Try / catch
try {
RClientCodegen codegen = new RClientCodegen();
codegen.setLibrary("httr2"); // or leave default
new DefaultGenerator().opts(new ClientOptInput().opts(codegen)).generate();
} catch (IllegalArgumentException e) {
// 'Invalid HTTP library ...' - only httr and httr2 are valid; fix and rerun
} Prevention
- Pin -l httr or -l httr2 explicitly in CI instead of templating from other generators
- Remember generateWrapper only works with httr2
- Omit -l to fall back to the generator default when unsure
When it happens
Trigger: openapi-generator-cli generate -i api.yaml -g r -l curl / -l httr3 / -l restifts; also setting <library> in the Maven plugin to a value copied from another generator's docs.
Common situations: Copy-pasting a -l flag from a python or java example into an R job; assuming the library flag is free-form; typos like httr2-client. The flag is also case-sensitive: HTTR vs httr are compared exactly.
Related errors
- Invalid operationIdNaming: " + operationIdNaming + ". Must b
- Invalid HTTP library " + getLibrary() + ". Only faraday, typ
- recursionLimit must be an integer, e.g. 2000.
- recursionLimit must be an integer, e.g. 2000.
- DateLibrary " + dateLibrary + " is not supported. Please use
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/eb7cb6290557bdd2.
Report an issue: GitHub.