You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swagger always suggests parameters using camelCase. This works good on "simple" Models because both CamelCase and snake_case parameters are accepted and treated in the same way after camelCase parameters are normalized to snake_case when treating the input data.
However, this collisions when definining validation request rules which expects parameters to be camel_case in order to link them to Database Fields.
How to reproduce
Having 1 Model:
<?phpnamespaceApp\Models;
useApiPlatform\Metadata\ApiResource;
useApiPlatform\Metadata\Post;
useIlluminate\Database\Eloquent\Model;
#[ApiResource(
operations:[
newPost()
],
)]
class Test extends Model
{
protected$table = 'test';
}
When trying this call, Model is saved properly. GOOD.
If then I add some validation rules on the Model on sur_name field:
...#[ApiResource(
operations:[
newPost()
],
rules: [
'sur_name' => 'required'
]
)]
class Test extends Model
{
...
And calling again POST with the suggested Payload I receive:
I then I swtich the Payload using sur_name instead of surName so:
The Model is persisted properly.
Possible Solution
Maybe one solution would be Swagger always suggesting fields using snake_case, otherwise these confusions may happen.
I am not sure if I am doing something very wrong using camelCase vs snake_case notation on Models but this is something very related to #6927. Maybe some explanations how camelCase vs snake_case parameters/attributes are treated would be useful @soyuka.
The text was updated successfully, but these errors were encountered:
API Platform version(s) affected: 4.0.16
Description
Swagger always suggests parameters using camelCase. This works good on "simple" Models because both CamelCase and snake_case parameters are accepted and treated in the same way after camelCase parameters are normalized to snake_case when treating the input data.
However, this collisions when definining validation request rules which expects parameters to be camel_case in order to link them to Database Fields.
How to reproduce
Having 1 Model:
Created using folliwng migration:
The suggestion/Example on Swagger is:
When trying this call, Model is saved properly. GOOD.
If then I add some validation rules on the Model on
sur_name
field:And calling again POST with the suggested Payload I receive:
I then I swtich the Payload using
sur_name
instead ofsurName
so:The Model is persisted properly.
Possible Solution
Maybe one solution would be Swagger always suggesting fields using snake_case, otherwise these confusions may happen.
I am not sure if I am doing something very wrong using camelCase vs snake_case notation on Models but this is something very related to #6927. Maybe some explanations how camelCase vs snake_case parameters/attributes are treated would be useful @soyuka.
The text was updated successfully, but these errors were encountered: