{"record":{"id":"e84e16cd4c172545","repo":"OpenAPITools/openapi-generator","slug":"error-oneof-schema-is-not-of-the-type-schema-it","errorCode":null,"errorMessage":"Error! oneOf schema is not of the type Schema: {item}","messagePattern":"Error! oneOf schema is not of the type Schema: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java","lineNumber":1338,"sourceCode":"        // Remove duplicate oneOf entries\n        ModelUtils.deduplicateOneOfSchema(schema);\n\n        schema = processSimplifyOneOfEnum(schema);\n\n        // simplify first as the schema may no longer be a oneOf after processing the rule below\n        schema = processSimplifyOneOf(schema);\n\n        // if it's still a oneOf, loop through the sub-schemas\n        if (schema.getOneOf() != null) {\n            for (int i = 0; i < schema.getOneOf().size(); i++) {\n                // normalize oneOf sub schemas one by one\n                Object item = schema.getOneOf().get(i);\n\n                if (item == null) {\n                    continue;\n                }\n                if (!(item instanceof Schema)) {\n                    throw new RuntimeException(\"Error! oneOf schema is not of the type Schema: \" + item);\n                }\n\n                // update sub-schema with the updated schema\n                schema.getOneOf().set(i, normalizeSchema((Schema) item, visitedSchemas));\n            }\n            schema = processReplaceOneOfByMapping(schema);\n        } else {\n            // normalize it as it's no longer an oneOf\n            schema = normalizeSchema(schema, visitedSchemas);\n        }\n\n        return schema;\n    }\n\n    protected Schema normalizeAnyOf(Schema schema, Set<Schema> visitedSchemas) {\n        //transform anyOf into enums if needed\n        schema = processSimplifyAnyOfEnum(schema);\n        if (schema.getAnyOf() == null) {","sourceCodeStart":1320,"sourceCodeEnd":1356,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java#L1320-L1356","documentation":"normalizeOneOf loops schema.getOneOf() after the simplify-oneOf rules have run; it skips null entries but requires every remaining element to be an instanceof Schema before normalizing it in place. A non-Schema element - scalar, boolean schema, or raw object placed under oneOf - aborts normalization with this error showing the offending item. oneOf is the composition keyword most often populated by hand (polymorphism), which is exactly where malformed entries slip in.","triggerScenarios":"Polymorphic schemas hand-written with a stray scalar or boolean under oneOf ('- true' carried over from JSON Schema semantics); $ref typos that fail to deserialize into a Schema; programmatically built oneOf lists containing Maps or Strings; YAML indentation putting a plain value under oneOf.","commonSituations":"Hand-maintained discriminator/oneOf hierarchies; JSON Schema -> OpenAPI conversions; multi-file merges concatenating lists with separators that become scalars.","solutions":["Use the printed item to find the bad oneOf entry; replace it with a schema object or '$ref: ...'.","Remove boolean-schema members (true/false) from oneOf - not valid in OpenAPI 3.x.","Check every $ref under oneOf resolves to '#/components/schemas/...' exactly.","When building models in code, add Schema instances only, never Maps/scalars/nulls.","Validate the spec with a strict OpenAPI validator to catch composition member types pre-generation."],"exampleFix":"# before\nPet:\n  oneOf:\n    - $ref: '#/components/schemas/Cat'\n    - true\n# after\nPet:\n  oneOf:\n    - $ref: '#/components/schemas/Cat'\n    - $ref: '#/components/schemas/Dog'","handlingStrategy":"validation","validationCode":"// Assert oneOf members are Schema instances and refs resolve\nfor (Schema s : api.getComponents().getSchemas().values()) {\n    if (s.getOneOf() != null) {\n        for (Object m : s.getOneOf()) {\n            if (m == null) continue;\n            if (!(m instanceof Schema)) {\n                throw new IllegalStateException(\"Invalid oneOf member: \" + m);\n            }\n            String ref = ((Schema) m).get$ref();\n            if (ref != null && api.getComponents().getSchemas().get(ref.replace(\"#/components/schemas/\", \"\")) == null) {\n                throw new IllegalStateException(\"Dangling oneOf ref: \" + ref);\n            }\n        }\n    }\n}","typeGuard":"private static boolean oneOfMembersAreSchemas(Schema s) {\n    return s.getOneOf() == null || s.getOneOf().stream()\n            .allMatch(m -> m == null || m instanceof Schema);\n}","tryCatchPattern":"try {\n    generator.opts(input).generate();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"oneOf schema is not of the type Schema\")) {\n        // message prints the member; fix the oneOf list (no booleans/scalars)\n        throw new GenerationFailure(\"Invalid oneOf member\", e);\n    }\n    throw e;\n}","preventionTips":["Use refs to concrete schemas for polymorphic oneOf members and lint for dangling refs.","Reject boolean schemas in OpenAPI documents in your validator config.","Review YAML merges around oneOf lists after multi-file concatenation."],"tags":["openapi-generator","openapi","oneof","schema","normalizer"],"backgroundTag":"malformed-openapi-schema","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}