OpenAPITools/openapi-generator · error · RuntimeException

The BLOB and JSON data types cannot be assigned a default va

Error message

The BLOB and JSON data types cannot be assigned a default value

What it means

The Ktorm schema generator maps OpenAPI `type: object` properties to SQL JSON columns and binary-format strings to BLOB columns. SQL/Ktorm does not permit column DEFAULT values on BLOB or JSON types, so when a property mapped to SqlType.Blob or SqlType.Json carries a `default`, the default-value switch throws a RuntimeException (KtormSchemaCodegen.java:990). Numeric, text, varchar and date types accept defaults and fall through normally.

Source

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

        if (defaultValue == null || defaultValue.toUpperCase(Locale.ROOT).equals("NULL")) {
            sqlType = "null";
        }
        //special case for keywords if needed
        switch (sqlType) {
            case SqlType.Boolean:
            case SqlType.Int:
            case SqlType.Long:
            case SqlType.Float:
            case SqlType.Double:
            case SqlType.Decimal:
            case SqlType.Text:
            case SqlType.Varchar:
            case SqlType.Date:
            case SqlType.DateTime:
                sqlDefault = defaultValue;
            case SqlType.Blob:
            case SqlType.Json:
                throw new RuntimeException("The BLOB and JSON data types cannot be assigned a default value");
            default:
                sqlDefault = "NULL";
        }
        Map<String, Object> args = new HashMap<String, Object>();
        processTypeArgs(sqlType, null, null, null, args);
        args.put("defaultValue", sqlDefault);
        return args;
    }

    /**
     * Converts name to valid database name
     * Produced name must be used with backticks only, eg. `database_name`
     *
     * @param name source name
     * @return database name
     */
    public String toDatabaseName(String name) {
        String identifier = toIdentifier(name, databaseNamePrefix, databaseNameSuffix);

View on GitHub (pinned to fcec517be3)

Solutions

  1. Remove the `default` keyword from the offending object/binary property in the OpenAPI spec (the error is raised per-property while building column args).
  2. If a default is functionally required, enforce it in application code or a hand-written migration instead of the generated DDL.
  3. Alternatively change the property type (e.g. to varchar with a serialized default) if the column semantics allow it.

Example fix

# before (api.yaml)
components:
  schemas:
    User:
      properties:
        metadata:
          type: object
          default: {"theme": "light"}
# after
components:
  schemas:
    User:
      properties:
        metadata:
          type: object
Defensive patterns

Strategy: validation

Validate before calling

// ktorm: reject defaults on types that map to BLOB/JSON columns
for (var e : openAPI.getComponents().getSchemas().entrySet()) {
  Map<String, Schema> props = e.getValue().getProperties();
  if (props == null) continue;
  for (var p : props.entrySet()) {
    Schema s = p.getValue();
    boolean blobOrJson = "object".equals(s.getType())
        || ("string".equals(s.getType()) && "binary".equals(s.getFormat()));
    if (blobOrJson && s.getDefault() != null) {
      throw new IllegalArgumentException("Default not allowed on BLOB/JSON property '"
          + p.getKey() + "' in schema '" + e.getKey() + "'");
    }
  }
}

Try / catch

try {
    new DefaultGenerator().opts(clientOptInput).generate();
} catch (RuntimeException e) {
    // message names the restriction; locate the offending property's default in the spec
    throw new BuildException("Ktorm schema generation failed: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Generating a Ktorm schema (`-g ktorm-schema` by way of the ktorm generator) from a spec where a property is `type: object` or `type: string, format: binary` AND has a non-null `default` (e.g. `default: {}`, `default: {"a":1}`, or a default byte string).

Common situations: Specs authored for REST semantics where object defaults are natural; converting an existing API spec into a database schema generator without stripping defaults; defaults added by upstream API teams that the schema generator then rejects.

Related errors


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