All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.reprezen.kaizen.oasparser.val3.SecurityRequirementValidator Maven / Gradle / Ivy

/*******************************************************************************
 *  Copyright (c) 2017 ModelSolv, Inc. and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *     ModelSolv, Inc. - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.reprezen.kaizen.oasparser.val3;

import static com.reprezen.kaizen.oasparser.ovl3.SecurityRequirementImpl.F_requirements;
import static com.reprezen.kaizen.oasparser.val.msg.Messages.msg;
import static com.reprezen.kaizen.oasparser.val3.OpenApi3Messages.UnkSecScheme;

import java.util.Map;
import java.util.Set;

import com.reprezen.jsonoverlay.MapOverlay;
import com.reprezen.jsonoverlay.Overlay;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import com.reprezen.kaizen.oasparser.model3.SecurityParameter;
import com.reprezen.kaizen.oasparser.model3.SecurityRequirement;
import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase;

public class SecurityRequirementValidator extends ObjectValidatorBase {

	@Override
	public void runObjectValidations() {
		Overlay> requirements = validateMapField(F_requirements, false, false,
				SecurityParameter.class, new SecurityParameterValidator());
		checkAllSchemesDefined(requirements);
	}

	public void checkAllSchemesDefined(Overlay> requirements) {
		OpenApi3 model = value.getModel();
		Set definedSchemes = model.getSecuritySchemes().keySet();
		MapOverlay mapOverlay = Overlay.getMapOverlay(requirements);
		for (String name : mapOverlay.keySet()) {
			if (!definedSchemes.contains(name)) {
				results.addError(msg(UnkSecScheme, name), Overlay.of(mapOverlay, name));
			}
		}

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy