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

PostgreSQL does not allow DEFAULT values on BYTEA, TEXT, GEOMETRY, JSON and JSONB columns (expression defaults like DEFAULT '{}'::jsonb are a separate SQL feature the generator does not emit). When PostgresqlSchemaCodegen's default-processing switch is handed a `default` for any of those types, it throws a RuntimeException (PostgresqlSchemaCodegen.java:1176) rather than generate invalid DDL; all other types fall through and record the default.

Source

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

                    defaultMap.put("isNumeric", false);
                    defaultMap.put("isKeyword", true);

                } else {
                    defaultMap.put("defaultValue", defaultValue);
                    defaultMap.put("isString", true);
                    defaultMap.put("isNumeric", false);
                    defaultMap.put("isKeyword", false);

                }
                return defaultMap;
            case "BYTEA":
            case "TEXT":
            case "GEOMETRY":
            case "JSON":
            case "JSONB":
                // 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 PostgreSQL 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

View on GitHub (pinned to fcec517be3)

Solutions

  1. Remove the `default` from the offending property in the spec.
  2. Add expression defaults (e.g. DEFAULT '{}'::jsonb) via a hand-maintained migration on top of the generated schema.
  3. Or change the column type to one permitting defaults (bounded string → VARCHAR with default).

Example fix

# before (api.yaml)
components:
  schemas:
    Profile:
      properties:
        prefs:
          type: object
          default: {"newsletter": true}
# after
components:
  schemas:
    Profile:
      properties:
        prefs:
          type: object
Defensive patterns

Strategy: validation

Validate before calling

// postgresql: reject defaults on properties mapping to BYTEA/TEXT/JSON/JSONB/GEOMETRY
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 bytea = "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 && (bytea || json || text)) {
      throw new IllegalArgumentException("PostgreSQL DEFAULT not allowed on BYTEA/TEXT/JSON property '"
          + p.getKey() + "' in '" + e.getKey() + "'");
    }
  }
}

Try / catch

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

Prevention

When it happens

Trigger: Generating SQL with the postgresql generator from a spec where a property mapped to BYTEA (format: binary), TEXT (long unbounded string), JSON/JSONB (type: object, or string with x-postgres-type json/jsonb), or GEOMETRY has a non-null `default`.

Common situations: Designing the API spec and DB schema from one source; carrying sample/default payload values from API docs into schema generation; migrating from a generator that ignored unsupported defaults to one that fails fast.

Related errors


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