{"record":{"id":"733f254f9d78653e","repo":"OpenAPITools/openapi-generator","slug":"the-blob-and-json-data-types-cannot-be-assigned-a","errorCode":null,"errorMessage":"The BLOB and JSON data types cannot be assigned a default value","messagePattern":"The BLOB and JSON data types cannot be assigned a default value","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KtormSchemaCodegen.java","lineNumber":990,"sourceCode":"        if (defaultValue == null || defaultValue.toUpperCase(Locale.ROOT).equals(\"NULL\")) {\n            sqlType = \"null\";\n        }\n        //special case for keywords if needed\n        switch (sqlType) {\n            case SqlType.Boolean:\n            case SqlType.Int:\n            case SqlType.Long:\n            case SqlType.Float:\n            case SqlType.Double:\n            case SqlType.Decimal:\n            case SqlType.Text:\n            case SqlType.Varchar:\n            case SqlType.Date:\n            case SqlType.DateTime:\n                sqlDefault = defaultValue;\n            case SqlType.Blob:\n            case SqlType.Json:\n                throw new RuntimeException(\"The BLOB and JSON data types cannot be assigned a default value\");\n            default:\n                sqlDefault = \"NULL\";\n        }\n        Map<String, Object> args = new HashMap<String, Object>();\n        processTypeArgs(sqlType, null, null, null, args);\n        args.put(\"defaultValue\", sqlDefault);\n        return args;\n    }\n\n    /**\n     * Converts name to valid database name\n     * Produced name must be used with backticks only, eg. `database_name`\n     *\n     * @param name source name\n     * @return database name\n     */\n    public String toDatabaseName(String name) {\n        String identifier = toIdentifier(name, databaseNamePrefix, databaseNameSuffix);","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KtormSchemaCodegen.java#L972-L1008","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Remove the `default` keyword from the offending object/binary property in the OpenAPI spec (the error is raised per-property while building column args).","If a default is functionally required, enforce it in application code or a hand-written migration instead of the generated DDL.","Alternatively change the property type (e.g. to varchar with a serialized default) if the column semantics allow it."],"exampleFix":"# before (api.yaml)\ncomponents:\n  schemas:\n    User:\n      properties:\n        metadata:\n          type: object\n          default: {\"theme\": \"light\"}\n# after\ncomponents:\n  schemas:\n    User:\n      properties:\n        metadata:\n          type: object","handlingStrategy":"validation","validationCode":"// ktorm: reject defaults on types that map to BLOB/JSON columns\nfor (var e : openAPI.getComponents().getSchemas().entrySet()) {\n  Map<String, Schema> props = e.getValue().getProperties();\n  if (props == null) continue;\n  for (var p : props.entrySet()) {\n    Schema s = p.getValue();\n    boolean blobOrJson = \"object\".equals(s.getType())\n        || (\"string\".equals(s.getType()) && \"binary\".equals(s.getFormat()));\n    if (blobOrJson && s.getDefault() != null) {\n      throw new IllegalArgumentException(\"Default not allowed on BLOB/JSON property '\"\n          + p.getKey() + \"' in schema '\" + e.getKey() + \"'\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n    new DefaultGenerator().opts(clientOptInput).generate();\n} catch (RuntimeException e) {\n    // message names the restriction; locate the offending property's default in the spec\n    throw new BuildException(\"Ktorm schema generation failed: \" + e.getMessage(), e);\n}","preventionTips":["Keep API sample defaults out of schema-as-database specs; separate 'example' (safe) from 'default' (DDL-affecting).","Use `example:` instead of `default:` when the value is documentation-only.","Run a spec lint that flags defaults on object/binary properties before DDL generation."],"tags":["ktorm","database-schema","default-value","blob","json","openapi-spec","openapi-generator","spec-validation"],"backgroundTag":"default-value-on-blob-column","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}