validation

API Platform returns type error instead of validation error when passing null to a string field

送分小仙女□ 提交于 2021-02-10 19:55:21
问题 I'm using API Platform v2.2.5, and in the process of writing tests for my resources I've discovered that, when null is provided for a field of type string , an error response is being returned during the denormalization process, which includes a non client-friendly message and a stack trace. This is different to if an empty string is provided or the field is omitted completely, which returns a structured validation response. How can I instead return a validation error response as when an

How do you check if an input is a negative number in VB

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 19:46:49
问题 I am trying to do some validation which checks if the value in a textbox is an integer then checks if the the value is negative. It correctly checks if the value is an integer but I can't get it to check if the value is negative. Note: The value being entered is the number of competitions attended so comps = competition etc... Dim comps As Integer Dim value As Double If Integer.TryParse(txtCompsEntered.Text, integer) Then value = txtCompsEntered.Text If value < 0 Then lblcompsatten.ForeColor

Return validation error message as JSON - Laravel 6

懵懂的女人 提交于 2021-02-10 16:51:14
问题 I want to return a failed validation attempt message in JSON. I used something like this before, which was working on Laravel 5, I believe... if ($validator->fails()) { return response()->json($validator->messages(), 200); } However, for our new project we are using Laravel 6 and the above just returns a blank page. In Laravel 6 the following returns the error message successfully, albeit not in JSON... if ($validator->fails()) { $msg = $validator->messages(); dd($msg); } There must be a

Response to missing required Properties in ASP.NET Core

白昼怎懂夜的黑 提交于 2021-02-10 14:17:39
问题 Given the following controller: using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; namespace WebApplication1.Controllers { [Route("api/[controller]")] [ApiController] public class ValuesController : ControllerBase { // POST api/values [HttpPost] public ActionResult<string> Post([FromBody] Model req) { return $"Your name is {req.Name}"; } } public class Model { [Required] public string Name { get; set; } } } if I post an empty body {} , the response is: { "errors": {

Better handling of number format exception in android

 ̄綄美尐妖づ 提交于 2021-02-10 13:26:10
问题 I've got the following code snippet that I'm thinking of refactoring to a more abstract application exception handler but I want to make sure I've got it as tidy as possible first Any suggestions on how to improve this code or make it more resuable int id = -1; final StringBuilder errorMessage = new StringBuilder("Bad Input Value: "); try { id = Integer.parseInt(edtId.getText().toString()); } catch (final NumberFormatException e) { errorMessage.append("Failed to parse id " + e.getMessage());

How to throw an exception when JsonConstructor parameter name doesn't match JSON?

落爺英雄遲暮 提交于 2021-02-10 07:09:09
问题 I'm deserializing a bunch of C# readonly structures (which have their constructors marked by [JsonConstructor] ), and I'm trying to fail early if any JSON that I receive is malformed. Unfortunately, if there is a naming discrepancy between the constructor parameter and the input JSON, the parameter just gets assigned a default value. Is there a way that I could get an exception instead, so these defaults don't accidentally "pollute" the rest of my business logic? I have tried playing with

How to throw an exception when JsonConstructor parameter name doesn't match JSON?

ε祈祈猫儿з 提交于 2021-02-10 07:08:33
问题 I'm deserializing a bunch of C# readonly structures (which have their constructors marked by [JsonConstructor] ), and I'm trying to fail early if any JSON that I receive is malformed. Unfortunately, if there is a naming discrepancy between the constructor parameter and the input JSON, the parameter just gets assigned a default value. Is there a way that I could get an exception instead, so these defaults don't accidentally "pollute" the rest of my business logic? I have tried playing with

Nested validation in Django Rest Framework

倖福魔咒の 提交于 2021-02-10 06:54:41
问题 Using django rest framework I want to validate fields. Correct input request: { test_field_a: {test_field_c: 25}, test_field_b: {} } My serializers.py (I don't have any associated models and the models.py itself): from rest_framework import serializers class TestSerializer(serializers.Serializer): test_field_a = serializers.JSONField(label='test_field_a', allow_null=False, required=True) test_field_b = serializers.JSONField(label='test_field_b', required=True) test_field_c = serializers

Joi: Automatic validation of function arguments

佐手、 提交于 2021-02-10 05:36:47
问题 I saw a codebase which was using joi library like this: function f(a, b) { // ... } f.schema = { a: Joi.string().uuid().required(), b: Joi.number() } And then the f.schema property wasn't referenced anywhere else. Is there some framework which performs automatic validation of function arguments using the schema property? Googling this didn't bring up anything. 回答1: I don't think it is possible to do exactly what you are showing here, since overloading of function call is impossible in

Spreadsheet Script Validation: The data validation rule argument “=Employees!B1:B1000” is invalid

冷暖自知 提交于 2021-02-10 05:17:18
问题 I'm trying to validate employees based on another spreadsheet with the following code: function validation() { var globals = SpreadsheetApp.openByUrl('https://docs.google.com/myurl'); var globalsheet = globals.getSheetByName('Employees'); var validate = SpreadsheetApp.newDataValidation(); var cell = SpreadsheetApp.getActive().getRange('A1:A'); var range = globalsheet.getRange('B1:B'); var rule = SpreadsheetApp.newDataValidation().requireValueInRange(range).build() cell.setDataValidation(rule)