Files
codeql/javascript/ql/test/tutorials/Validating RAML-based APIs/MissingResponseSpecification.ql
Anders Schack-Mulligen e58094c732 Javascript: Autoformat.
2019-01-11 11:02:42 +01:00

27 lines
835 B
Plaintext

/**
* @name Missing status code specification
* @description Using undocumented status codes in REST API methods may confuse client applications.
* @kind problem
* @problem.severity warning
*/
import javascript
import Osprey
import RAML
RAMLMethod getSpecification(OspreyMethod om) {
exists(RAMLResource rr, File f, string rPath |
rr.getLocation().getFile() = f and
f = om.getDefinition().getAPI().getSpecFile() and
rPath = om.getResourcePath() and
rr.getPath() = rPath.regexpReplaceAll("/:([^/]+)/", "/{$1}/") and
result = rr.getMethod(om.getVerb())
)
}
from MethodResponseSetStatus mrss, RAMLMethod rm
where
rm = getSpecification(mrss.getMethod()) and
not exists(rm.getResponse(mrss.getStatusCode()))
select mrss, "Response " + mrss.getStatusCode() + " is not specified by $@.", rm, rm.toString()