I am using WebApiContrib.Formatting.Jsonp within a Web API 2 service, plus Swagger for API documentation and testing.
When I trigger any JSONP method through Swagger, my service crashes in file JsonpMediaTypeFormatter.cs on the following line:
throw new InvalidOperationException(Properties.Resources.NoCallback);
// NoCallback = The name 'NoCallback' does not exist in the current context
For one thing, I don't understand why Swagger doesn't allow specifying a callback name for JSONP requests. But more importantly, I don't want the service to crash because of it.
Questions:
PM> Install-Package Newtonsoft.Json.Schema
Or you can down load the source at https://github.com/JamesNK/Newtonsoft.Json.Schema/releases
JSchema schema = JSchema.Parse(request.Schema);
JToken json = JToken.Parse(request.Json);
// validate json
IList<ValidationError> errors;
bool valid = json.IsValid(schema, out errors);
// return error messages and line info to the browser
return new ValidateResponse
{
Valid = valid,
Errors = errors
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With