OpenAPITools/openapi-generator · error · IllegalArgumentException
Invalid providedIn level '%s'. Must be one of %s.
Error message
Invalid providedIn level '%s'. Must be one of %s.
What it means
providedIn sets the scope used in @Injectable() of the generated Angular services and maps to an enum with values 'none', 'root', 'any' and 'platform'. Any other string throws during option parsing, with the accepted list included in the message.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java:762
}
return name;
}
/**
* Set the Injectable level
*
* @param level the wanted level
*/
public void setProvidedIn(String level) {
try {
providedIn = PROVIDED_IN_LEVEL.valueOf(level);
} catch (IllegalArgumentException e) {
String values = Stream.of(PROVIDED_IN_LEVEL.values())
.map(value -> "'" + value.name() + "'")
.collect(Collectors.joining(", "));
String msg = String.format(Locale.ROOT, "Invalid providedIn level '%s'. Must be one of %s.", level, values);
throw new IllegalArgumentException(msg);
}
}
/**
*
*/
private boolean getIsProvidedInNone() {
return PROVIDED_IN_LEVEL.none.equals(providedIn);
}
}
View on GitHub (pinned to fcec517be3)
Solutions
- Use one of the supported values: 'root' (default), 'any', 'platform' or 'none'.
- If module-level scope is required, generate with 'none' and register the service in the module's providers array.
Example fix
# before -DprovidedIn=module # after -DprovidedIn=none # then add the service to NgModule providers manually
Defensive patterns
Strategy: type-guard
Validate before calling
// node: verify providedIn against the generator's enum
const LEVELS = ['none', 'root', 'any', 'platform'];
if (opts.providedIn && !LEVELS.includes(opts.providedIn))
throw new Error(`providedIn must be one of ${LEVELS.join('|')}`); Type guard
const PROVIDED_IN = ['none', 'root', 'any', 'platform'] as const; export type ProvidedInLevel = typeof PROVIDED_IN[number]; const isProvidedInLevel = (v: string): v is ProvidedInLevel => (PROVIDED_IN as readonly string[]).includes(v);
Try / catch
// Java
try { new DefaultGenerator().opts(input).generate(); }
catch (IllegalArgumentException e) {
// message lists none/root/any/platform; pick one and rerun
} Prevention
- Remember 'module' scope is not modelled; plan manual NgModule registration with 'none'.
- Type config values as unions so invalid scopes fail at compile time.
- Validate enum-backed options in a pre-flight script.
When it happens
Trigger: -DprovidedIn=module (not modelled by the generator), 'Root' (wrong case), or any value outside none/root/any/platform.
Common situations: Wanting Angular's providedIn: 'module' scope, which the generator does not support; case mismatches from hand-edited configs; copying examples written for a different generator version.
Related errors
- Invalid ngVersion: " + ngVersion + ". Only Angular v9+ is su
- %s file suffix only allows '.', '-' and alphanumeric charact
- %s class prefix only allows alphanumeric characters.
- %s class suffix only allows alphanumeric characters.
- Invalid query param object format '%s'. Must be one of %s.
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/faf85251de88a413.
Report an issue: GitHub.