Search in sources :

Example 1 with RefUtils.computeDefinitionName

use of io.swagger.v3.parser.util.RefUtils.computeDefinitionName in project swagger-parser by swagger-api.

the class SchemaProcessor method changeDiscriminatorMapping.

private void changeDiscriminatorMapping(ComposedSchema composedSchema, String oldRef, String newRef) {
    Discriminator discriminator = composedSchema.getDiscriminator();
    if (!oldRef.equals(newRef) && discriminator != null) {
        String oldName = RefUtils.computeDefinitionName(oldRef);
        String newName = RefUtils.computeDefinitionName(newRef);
        String mappingName = null;
        if (discriminator.getMapping() != null) {
            for (String name : discriminator.getMapping().keySet()) {
                if (oldRef.equals(discriminator.getMapping().get(name))) {
                    mappingName = name;
                    break;
                }
            }
            if (mappingName != null) {
                discriminator.getMapping().put(mappingName, newRef);
            }
        }
        if (mappingName == null && !oldName.equals(newName)) {
            if (discriminator.getMapping() == null) {
                discriminator.setMapping(new HashMap());
            }
            discriminator.getMapping().put(oldName, newRef);
        }
    }
}
Also used : HashMap(java.util.HashMap) Discriminator(io.swagger.v3.oas.models.media.Discriminator)

Aggregations

Discriminator (io.swagger.v3.oas.models.media.Discriminator)1 HashMap (java.util.HashMap)1