OpenAPITools/openapi-generator · error · IllegalArgumentException

Invalid dateLibrary. Must be 'java8' or 'joda'

Error message

Invalid dateLibrary. Must be 'java8' or 'joda'

What it means

AbstractScalaCodegen.setDateLibrary matches the given string against the DateLibraries enum — java8, joda, legacy — where legacy is only honored when the caller passes withLegacy=true. A no-match throws IllegalArgumentException('Invalid dateLibrary. Must be java8 or joda'). The message is stale: 'legacy' is also valid on generators that opt in, and matching is exact and case-sensitive.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java:263

            this.importMapping.put("LocalTime", "org.joda.time.LocalTime");
            this.typeMapping.put("date", "LocalDate");
            this.typeMapping.put("DateTime", "DateTime");
            additionalProperties.put("joda", "true");
        }
    }

    public void setDateLibrary(String dateLibrary, boolean withLegacy) {
        if (withLegacy && dateLibrary.equals(DateLibraries.legacy.name())) {
            this.dateLibrary = dateLibrary;
            return;
        }
        for (DateLibraries dateLib : DateLibraries.values()) {
            if (dateLib.name().equals(dateLibrary)) {
                this.dateLibrary = dateLibrary;
                return;
            }
        }
        throw new IllegalArgumentException("Invalid dateLibrary. Must be 'java8' or 'joda'");
    }

    public void setModelPropertyNaming(String naming) {
        try {
            this.modelPropertyNaming = CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.valueOf(naming).name();
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("Invalid model property naming '" +
                    naming + "'. Must be 'original', 'camelCase', " +
                    "'PascalCase' or 'snake_case'");
        }
    }


    @Override
    public String toVarName(String name) {
        // obtain the name from nameMapping directly if provided
        if (nameMapping.containsKey(name)) {
            return nameMapping.get(name);

View on GitHub (pinned to fcec517be3)

Solutions

  1. Use exactly java8 (the default) or joda, all lowercase
  2. For the deprecated backport, use legacy only on generators whose setDateLibrary call passes withLegacy=true (e.g. -g scala)
  3. Check that generator's README option table for its supported dateLibrary values before setting it

Example fix

# before
java -jar openapi-generator-cli.jar generate -g akka-scala -i api.yaml -p dateLibrary=threetenbp

# after
java -jar openapi-generator-cli.jar generate -g akka-scala -i api.yaml -p dateLibrary=java8
Defensive patterns

Strategy: validation

Validate before calling

// Java/bash: whitelist before setting the option
// allowed (Scala base): java8, joda, legacy (only where the generator opts in)
Set<String> allowed = Set.of("java8", "joda", "legacy");
if (!allowed.contains(dateLibrary)) throw new IllegalArgumentException("bad dateLibrary: " + dateLibrary);

Try / catch

try { generator.generate(); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Invalid dateLibrary")) { /* use exact lowercase java8/joda (or opted-in legacy) */ } throw e; }

Prevention

When it happens

Trigger: -p dateLibrary=<bad> on any Scala-based generator (akka-scala, scala-finch, scala-gatling, scalatra, play-scala, http4s, ...) with a value that is not exactly 'java8', 'joda', or an opted-in 'legacy': 'Java8', 'java-8', 'threetenbp', 'java.time' all throw.

Common situations: Copying dateLibrary values from Java-generator docs (threetenbp does not exist here); case typos; trusting the stale message as the complete option list.

Related errors


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