Question
· Dec 17, 2023

Remove the validation part in the disp class on spec-first approach by default

Hello Community,

Is there any way to avoid generating the built in validation inside the classmethod from the .disp class definition. I've added the resource with path parameter as integer in swagger 2.0 open API.  The class method(in my case getRandom is the class method) inside .disp handles the integer validation by default. Is there a way to avoid/remove by default.

default validations for Integer

If ($number(pmin,"I",-2147483648,2147483647)="") Do ##class(%REST.Impl).%ReportRESTError(..#HTTP400BADREQUEST,$$$ERROR($$$RESTInvalid,"min",pmin)) Quit
        If ($number(pmax,"I",-2147483648,2147483647)="") Do ##class(%REST.Impl).%ReportRESTError(..#HTTP400BADREQUEST,$$$ERROR($$$RESTInvalid,"max",pmax)) Quit
"/random/{min}/{max}":{
    "get": {
        "operationId": "getRandom",
        "parameters": [
            {
                "name": "min",
                "in": "path",
                "description": "Minimal Integer",
                "required": true,
                "type": "integer",
                "format": "int32"
            },
            {
                "name": "max",
                "in": "path",
                "description": "Maximal Integer",
                "required": true,
                "type": "integer",
                "format": "int32"
            }
        ]
    }
}

.disp class 

ClassMethod getRandom(pmin As %String, pmax As %String) As %Status
{
    Try {
        If ($number(pmin,"I",-2147483648,2147483647)="") Do ##class(%REST.Impl).%ReportRESTError(..#HTTP400BADREQUEST,$$$ERROR($$$RESTInvalid,"min",pmin)) Quit
        If ($number(pmax,"I",-2147483648,2147483647)="") Do ##class(%REST.Impl).%ReportRESTError(..#HTTP400BADREQUEST,$$$ERROR($$$RESTInvalid,"max",pmax)) Quit
        Set response=##class(mymath.impl).getRandom(pmin,pmax)
        Do ##class(TestApp.impl).%WriteResponse(response)
    } Catch (ex) {
        Do ##class(%REST.Impl).%ReportRESTError(..#HTTP500INTERNALSERVERERROR,ex.AsStatus(),$parameter("mymath.impl","ExposeServerExceptions"))
    }
    Quit $$$OK
}
Product version: IRIS 2023.2
$ZV: IRIS for Windows (x86-64) 2023.2
Discussion (0)1
Log in or sign up to continue