Swagger-codegen: [PHP] String length validation in models

Created on 15 Mar 2018  路  9Comments  路  Source: swagger-api/swagger-codegen

Description

When generating models with string properties having maxLength or minLength, strlen is used for validating max/min length of the string. While this works for English language it will not work properly for other languages such as German, since strlen returns number of bytes not number of character.

Swagger-codegen version

2.3.0

Swagger declaration file content or url

Any swagger declaration file having models with string properties and maxLength or minLength.
For example:

definitions:
  Person:
    Name:
      type: "string"
      maxLength: 4
Command line used for generation

See command line for php code generation

Steps to reproduce
  1. Generate client
  2. Query api that returns models with string properties within min/max range with characters 枚眉盲
  3. Model validation should fail despite having number of characters in required range
Related issues/PRs
Suggest a fix/enhancement

Use mb_strlen instead of strlen. Also add option to define encoding to use for mb_strlen.

PHP Bug

Most helpful comment

@wing328 I can confirm that it works in my case.

All 9 comments

@dParadiz Nice catch! Can you attach a PR for this?

@ackintosh What do yo mean by PR? I could not fund any similar or related reported issues.

@dParadiz I'm sorry for my poor English. 馃挦
Could you create a PR which fixes this issue?

@ackintosh Sorry, it's just my understanding of abbreviation PR. Do you mean that I add proposal for this issue or is PR something else?

Ah, PR is Pull Request 馃挕

I'll submit the Pull Request which fixes this issue later.

@dParadiz the issue has been fixed by the PR filed by @ackintosh

Please pull the latest master to give it another try.

@wing328 I can confirm that it works in my case.

@dParadiz thanks for the confirmation

Was this page helpful?
0 / 5 - 0 ratings