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

jeaf.OpenAPIChecks.chk Maven / Gradle / Ivy

There is a newer version: 1.24.1
Show newest version
import uml;
import JMM;

extension java::Naming;
extension java::GeneratorCommons;
extension java::OpenAPIFunctions;
extension jeaf::RESTFunctions;
extension functions::ClassifierTemplateParameter;
extension functions::RESTOperation;
extension functions::RESTResource;
extension functions::NamedElement;
extension functions::Property;
extension functions::OpenAPIType;
extension functions::OpenAPISpecification;

// Checks for stereotype RESTResource
context RESTResource if runChecks("RESTResource") && ignore() == false ERROR this.getErrorMessage("9104", {name}): this.hasValidRESTResourcePath() == true;
context RESTResource if runChecks("RESTResource") && ignore() == false ERROR	this.getErrorMessage("9130", {"RESTResource", name}): ownedOperation.forAll( e | e.hasOnlySupportedParamaterTypes());


// Checks for stereotype RESTOperation
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9105", {owner.asNamedElement().name + "." + name}): this.hasValidRESTResourcePath() == true;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9106", {owner.asNamedElement().name + "." + name}): this.hasValidOperationPath() == true;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9107", {owner.asNamedElement().name + "." + name}): httpMethods.size > 0;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9108", {this.getStatusCodeName()}): isJAXRSStatusCode(this.getStatusCodeName()) == true;
context RESTOperation if runChecks("RESTOperation") && ignore() == false && owner.isRESTResource() ERROR   this.getErrorMessage("9109", {owner.asNamedElement().name + "." + name}): unifyMediaTypes(((JMM::RESTResource)this.owner).consumes, this.consumes).size > 0;
context RESTOperation if runChecks("RESTOperation") && ignore() == false && owner.isRESTResource() ERROR   this.getErrorMessage("9110", {owner.asNamedElement().name + "." + name}): unifyMediaTypes(((JMM::RESTResource)this.owner).produces, this.produces).size > 0;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9111", {owner.asNamedElement().name + "." + name}): this.areAllInputParametersNamed() == true;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9112", {owner.asNamedElement().name + "." + name, this.getBodyParamNames().toString()}): this.getBodyParamNames().size < 2 ;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9113", {owner.asNamedElement().name + "." + name, httpMethods.toString()}): this.hasUnsupportedRequestBody() == false ;
context RESTOperation if runChecks("RESTOperation") && ignore() == false ERROR   this.getErrorMessage("9165", {this.detectMissingRESTPathParams().toString(", "), this.getRESTOperationPath(), owner.asNamedElement().name + "." + name}): this.detectMissingRESTPathParams().isEmpty == true ;


context RESTOperation if runChecks("RESTOperation") && ignore() == false && owner.isRESTResource() WARNING this.getWarningMessage("9101", {owner.asNamedElement().name + "." + name, this.getOpenAPIIncomaptibleParameterTypes().asParamErrorMessage().toString()}): this.getOpenAPIIncomaptibleParameterTypes().size == 0;

context RESTOperation if runChecks("RESTOperation") && ignore() == false WARNING this.getWarningMessage("9166", {owner.asNamedElement().name + "." + name, this.getRESTOperationPath(), this.detectDeadRESTPathParams().toString(", ")}): this.detectDeadRESTPathParams().isEmpty == true ;


// Global checks for OpenAPI3Specification
context Model if runChecks() ERROR this.getErrorMessage("9114", {}): this.hasValidOneGlobalDefaultErrorResponse() == false;
// Check is no longer correct
//context OpenAPI3Specification if runChecks("OpenAPI3Specification") ERROR "Error: <> " + this.name + " has " + this.getCustomResponses().size + " error responses.": this.getCustomResponses().size < 2;


// Checks for stereotype OpenAPIResponse
context OpenAPIResponse if runChecks("OpenAPIResponse") && ignore() == false ERROR this.getErrorMessage("9115", {name}): this.getResponseTypes().size == 1;

// Checks for stereotype OpenAPIType
context OpenAPIType if runChecks("OpenAPIType") && ignore() == false ERROR this.getErrorMessage("9124", {"OpenAPIType", name}): ownedAttribute.select(e|e.isPropertySuppressed() == false).forAll( a | a.type != null);
context OpenAPIType if runChecks("OpenAPIType") && ignore() == false ERROR this.getErrorMessage("9125", {"OpenAPIType", name}): ownedAttribute.select(e|e.isPropertySuppressed() == false).forAll( a | a.name.length > 0);

context OpenAPIType if runChecks("OpenAPIType") && ignore() == false WARNING this.getWarningMessage("9122", {"OpenAPIType", name}): ownedComment.size  > 0;


// Checks for stereotype OpenAPIDataType
context OpenAPIDataType if runChecks("OpenDataAPIType") && ignore() == false ERROR this.getErrorMessage("9124", {"OpenAPIDataType", name}): ownedAttribute.select(e|e.isPropertySuppressed() == false).forAll( a | a.type != null);
context OpenAPIDataType if runChecks("OpenAPIDataType") && ignore() == false && this.compositeDataType == false ERROR this.getErrorMessage("9116", {name}): this.ownedAttribute.select(e|e.isStatic == false && e.isDerived == false).size == 1;
context OpenAPIDataType if runChecks("OpenAPIDataType") && ignore() == false && this.compositeDataType == false ERROR this.getErrorMessage("9117", {name}): this.ownedAttribute.get(0).type.isBasicOpenAPIType() == true;
context OpenAPIDataType if runChecks("OpenAPIDataType") && ignore() == false && this.compositeDataType == false ERROR this.getErrorMessage("9118", {name}): this.ownedAttribute.get(0).isMultivalued() == false;
context OpenAPIDataType if runChecks("OpenAPIDataType") && ignore() == false ERROR this.getErrorMessage("9119", {name}): this.superClass.size == 0;

context OpenAPIDataType if runChecks("OpenAPIDataType") && ignore() == false WARNING this.getWarningMessage("9122", {"OpenAPIDataType", name}): ownedComment.size  > 0;
context OpenAPIDataType if runChecks("OpenAPIDataType") && ignore() == false WARNING this.getWarningMessage("9159", {name}): attribute.select(e|e.isReadOnly()) == 0;


// Checks for stereotype PathParam
context PathParam if runChecks("PathParam") && ignore() == false ERROR this.getErrorMessage("9120", {this.fqn()}): this.lower == 1;
context PathParam if runChecks("PathParam") && ignore() == false ERROR this.getErrorMessage("9120", {this.fqn()}): this.isMultivalued() == false;

// Checks for stereotype HeaderParam
context HeaderParam if runChecks("HeaderParam") && ignore() == false WARNING this.getWarningMessage("9153", {owner.asNamedElement().fqn(), this.getRESTHeaderParamName(), name}): this.isIgnoredHeaderParam() == false;
context HeaderParam if runChecks("HeaderParam") && ignore() == false ERROR this.getErrorMessage("9155", {owner.asNamedElement().fqn(), this.getRESTHeaderParamName(), name}): !(isRESTLibraryJAXRS() && generateRESTResources() && this.isMultivalued() && this.getCollectionType() == "java.util.Collection");

// Checks for stereotype QueryParam
context QueryParam if runChecks("QueryParam") && ignore() == false ERROR this.getErrorMessage("9156", {owner.asNamedElement().fqn(), this.getRESTQueryParamName(), name}): !(isRESTLibraryJAXRS() && generateRESTResources() && this.isMultivalued() && this.getCollectionType() == "java.util.Collection");

// Checks for stereotype BeanParam
context BeanParam if runChecks("RESTOperation") && ignore() == false WARNING this.getWarningMessage("9103", {this.fqn(), this.getOpenAPIIncompatibleBeanProperties().asPropertyErrorMessage().toString()}): this.getOpenAPIIncompatibleBeanProperties().size == 0;

// Checks for deprecations that are not supported by OpenAPI
context Property if owner.asNamedElement().runChecks("OpenAPIType") && ignore() == false WARNING this.getWarningMessage("9154", {owner.asNamedElement().name + "." + name}): !(this.isMultivalued() == false && this.type.isClassifierTemplateParameter()== true  && this.type.isBasicOpenAPIType() == false && this.isDeprecated() && owner.isStereotypeApplied("OpenAPIType"));

// Check for missing dependencies between OpenAPI specs
context Property if owner.asNamedElement().runChecks("OpenAPIType") && runOpenAPIDependencyCheck () && ignore() == false ERROR this.getErrorMessage("9171", {name, owner.asNamedElement().name, type.name, this.getOwnOpenAPISpecification().name, this.getReferencedOpenAPISpecification().name}): this.checkOpenAPIDependencies();

// Check for types that do not belong to an openAPI specification at all.
context Property if owner.asNamedElement().runChecks("OpenAPIType") && owner.isOpenAPIType() && runOpenAPIDependencyCheck () && ignore() == false ERROR this.getErrorMessage("9172", {name, owner.asNamedElement().name, type.name}): this.checkForOrphanedOpenAPITypes();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy