I have OpenApi/nswag specification json file, which contains validation/format metadata (only important part is shown):
{
"x-generator": "NSwag v13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v10.0.0.0))",
"swagger": "2.0",
"paths": {
"/api/Public/Register": {
"post": {
"operationId": "Public_Register",
"parameters": [
{
"type": "string",
"name": "email",
"in": "query",
"format": "email",
"x-nullable": true
},
{
"type": "string",
"name": "password",
"in": "query",
"maxLength": 100,
"minLength": 12,
"x-nullable": true
}
],
"responses": {
"200": {}
}
}
}
}
}
Also I have generated typescript proxy class using nswag:
register(email: string | null | undefined, password: string | null | undefined): Promise<void> {
let url_ = this.baseUrl + "/api/Public/Register?";
if (email !== undefined && email !== null)
url_ += "email=" + encodeURIComponent("" + email) + "&";
if (password !== undefined && password !== null)
url_ += "password=" + encodeURIComponent("" + password) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
}
};
return this.transformOptions(options_).then(transformedOptions_ => {
return this.http.fetch(url_, transformedOptions_);
}).then((_response: Response) => {
return this.transformResult(url_, _response, (_response: Response) => this.processRegister(_response));
});
}
And it does not contain any validation code. How can I add it?
May be I can use any other tools to load JSON specification and just execute validation using transformOptions
? Do we have any validation SDKs which supports openAPI/swagger?