Skip to content

Error: "discriminator: mapping is not supported" #334

Description

@Danphillipz

Issue

The following release seems to have introduced this error: #321

Since the upgrade to version 1.6.0 I have been seeing the following error message when trying to process my OAS with discriminator mappings.

{
  "error": {
    "message": "discriminator: mapping is not supported"
  }
}

Attached is a sample file which triggers the above error during processing:
discriminator-mapping-error-example.yaml

Research

From testing I can see that this removal seems to have triggered the issue as we are no longer deleting disciminator.mapping on subschemas.

Before, collectReferences was being called on the subschema which was tidying up discriminators on the subschema too. Now with that cleanup logic moved out of collectReferences and into cleanupDiscriminators it is no longer being applied at the subschema level, only on the main schema object

I believe this should fix the error in the src/transform/minimumSchema.ts file:

const minimumSchema = (originalSchema, oas) => {
    const refToAdd = [];
    const refAdded = [];
    const collectReferences = (s) => {
        if (s.$ref && !refToAdd.includes(s.$ref) && !refAdded.includes(s.$ref)) {
            refToAdd.push(s.$ref);
        }
    };
    const handleNullableSchema = (s) => {
        if (s.$ref) {
            if (s.nullable && !s.type) {
                s.type = dereferenceOas(s, oas).type;
            }
            return;
        }
        if (s.nullable && !s.type) {
            s.type = "object";
        }
        if (s.nullable && !Array.isArray(s.type)) {
            s.type = [s.type, "null"];
        }
    };
    const schema = cloneDeep(originalSchema);
    delete schema.description;
    delete schema.example;
    traverse(schema, cleanupDiscriminators);
    traverse(schema, collectReferences);
    traverse(schema, handleNullableSchema);
    traverse(schema, convertExclusiveMinMax);
    while (refToAdd.length) {
        const ref = refToAdd.shift();
        const path = splitPath(ref);
        refAdded.push(ref);
        const subschema = cloneDeep(get$1(oas, path, {}));
        delete subschema.description;
        delete subschema.example;
        traverse(subschema, cleanupDiscriminators);  <<------- Adding this line to cleanup discriminators on subschemas
        traverse(subschema, collectReferences);
        traverse(subschema, handleNullableSchema);
        traverse(subschema, convertExclusiveMinMax);
        set(schema, path, subschema);
    }
    return schema;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    smartbear-supportedSmartBear engineering team will support this issue. See https://docs.pact.io/help/smartbear

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions