All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.openapi4j.parser.validation.v3.HeaderValidator Maven / Gradle / Ivy
package org.openapi4j.parser.validation.v3;
import org.openapi4j.core.validation.ValidationResult;
import org.openapi4j.core.validation.ValidationResults;
import org.openapi4j.parser.model.v3.Header;
import org.openapi4j.parser.model.v3.OpenApi3;
import org.openapi4j.parser.validation.ValidationContext;
import org.openapi4j.parser.validation.Validator;
import java.util.regex.Pattern;
import static org.openapi4j.core.validation.ValidationSeverity.ERROR;
import static org.openapi4j.parser.validation.v3.OAI3Keywords.*;
class HeaderValidator extends Validator3Base {
private static final ValidationResult CONTENT_ONY_ONE_ERR = new ValidationResult(ERROR, 113, "Content can only contain one media type.");
private static final ValidationResult CONTENT_SCHEMA_EXCLUSIVE_ERR = new ValidationResult(ERROR, 114, "Content and schema are mutually exclusive.");
private static final Validator INSTANCE = new HeaderValidator();
private HeaderValidator() {
}
public static Validator instance() {
return INSTANCE;
}
@Override
public void validate(ValidationContext context, OpenApi3 api, Header header, ValidationResults results) {
// VALIDATION EXCLUSIONS :
// allowReserved, deprecated, description, example, examples, explode, required
if (header.isRef()) {
validateReference(context, api, header, results, CRUMB_$REF, HeaderValidator.instance(), Header.class);
} else {
validateString(header.getStyle(), results, false, Pattern.compile("simple"), CRUMB_STYLE); // Only simple is allowed.
validateField(context, api, header.getSchema(), results, false, CRUMB_SCHEMA, SchemaValidator.instance());
validateMap(context, api, header.getContentMediaTypes(), results, false, CRUMB_CONTENT, Regexes.NOEXT_REGEX, MediaTypeValidator.instance());
validateMap(context, api, header.getExtensions(), results, false, CRUMB_EXTENSIONS, Regexes.EXT_REGEX, null);
// Content or schema, not both
if (header.getContentMediaTypes() != null && header.getSchema() != null) {
results.add(CONTENT_SCHEMA_EXCLUSIVE_ERR);
}
// only one content type
if (header.getContentMediaTypes() != null && header.getContentMediaTypes().size() > 1) {
results.add(CONTENT_ONY_ONE_ERR);
}
}
}
}