OpenAPITools/openapi-generator · error · RuntimeException

The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assi

Error message

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

What it means

MySQL itself forbids literal DEFAULT values on BLOB, TEXT, GEOMETRY and JSON columns (MySQL 8 only allows expression defaults on JSON, which the generator does not emit). When MysqlSchemaCodegen maps a `default` onto one of those column types — TINYBLOB/BLOB/MEDIUMBLOB/LONGBLOB, the TEXT family, GEOMETRY, JSON — the default-processing switch throws a RuntimeException (MysqlSchemaCodegen.java:915) instead of emitting invalid DDL.

Source

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

                } else {
                    defaultMap.put("defaultValue", defaultValue);
                    defaultMap.put("isString", true);
                    defaultMap.put("isNumeric", false);
                    defaultMap.put("isKeyword", false);
                }
                return defaultMap;
            case "TINYBLOB":
            case "BLOB":
            case "MEDIUMBLOB":
            case "LONGBLOB":
            case "TINYTEXT":
            case "TEXT":
            case "MEDIUMTEXT":
            case "LONGTEXT":
            case "GEOMETRY":
            case "JSON":
                // The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value.
                throw new RuntimeException("The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value");
            default:
                defaultMap.put("defaultValue", defaultValue);
                defaultMap.put("isString", true);
                defaultMap.put("isNumeric", false);
                defaultMap.put("isKeyword", false);
                return defaultMap;
        }
    }

    /**
     * Finds best fitted MySQL data type for integer variable based on minimum and maximum properties
     *
     * @param minimum  (optional) codegen property
     * @param maximum  (optional) codegen property
     * @param unsigned (optional) whether variable is unsigned or not
     * @return MySQL integer data type
     */
    public String getMysqlMatchedIntegerDataType(Long minimum, Long maximum, Boolean unsigned) {

View on GitHub (pinned to fcec517be3)

Solutions

  1. Delete the `default` from the offending property in the spec (the message is thrown per offending column).
  2. For JSON columns needing a default, add an explicit expression default (DEFAULT (JSON_OBJECT())) in a hand-written migration — the generator cannot emit it.
  3. Or tighten the property type so it maps to a type that allows defaults (e.g. bounded string → VARCHAR).

Example fix

# before (api.yaml)
components:
  schemas:
    Account:
      properties:
        bio:
          type: string
          maxLength: 100000
          default: "n/a"
# after
components:
  schemas:
    Account:
      properties:
        bio:
          type: string
          maxLength: 100000
Defensive patterns

Strategy: validation

Validate before calling

// mysql: reject defaults on properties that map to BLOB/TEXT/GEOMETRY/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 binary = "string".equals(s.getType()) && "binary".equals(s.getFormat());
    boolean json = "object".equals(s.getType());
    boolean text = "string".equals(s.getType()) && s.getMaxLength() == null;
    if (s.getDefault() != null && (binary || json || text)) {
      throw new IllegalArgumentException("MySQL DEFAULT not allowed on BLOB/TEXT/JSON property '"
          + p.getKey() + "' in '" + e.getKey() + "'");
    }
  }
}

Try / catch

try {
    new DefaultGenerator().opts(clientOptInput).generate();
} catch (RuntimeException e) {
    throw new BuildException("MySQL schema generation failed: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Generating SQL schema with the mysql generator from a spec where a property mapped to one of those types has a `default`: object properties (JSON), long unbounded strings (TEXT), or format: binary properties (BLOB).

Common situations: Reusing an API spec as the source of truth for DDL generation; specs where object/free-text fields carry sample defaults; teams moving from generators that silently drop such defaults to ones that fail fast.

Related errors


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