Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String property validator constraint always min length >=0 #737

Open
leumatt opened this issue Jul 6, 2023 · 0 comments
Open

String property validator constraint always min length >=0 #737

leumatt opened this issue Jul 6, 2023 · 0 comments
Labels

Comments

@leumatt
Copy link

leumatt commented Jul 6, 2023

Jane version(s) affected: 7.5.1

Description

Generated validator constraints for string properties always contain minlength >=0 . I don't understand why .
It's a problem with special formats (binary for example) because of charset validation made in symfony minlength.

How to reproduce

OpenAPI file

{
  "openapi": "3.0.1",
  "info": {
    "title": "API Test",
    "version": "1.0"
  },
  "paths": {
    "/File": {
      "post": {
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "fichier": {
                    "type": "string",
                    "format": "binary"
                  },
                  "valid": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "description",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}

$apiClient = \Vendor\Library\Generated\ApiName\Client::create();

$object = new \Vendor\Library\Generated\ApiName\Model\FilePostBody();
$object->setFichier( file_get_contents("test.pdf",'r'));
$object->setValid(true);

$apiClient->postFile($object));

Failed on validation =>

Array[fichier]:
    This value does not match the expected UTF-8 charset

Possible Solution

\jane-php\json-schema\Guesser\Validator\String_\MinLengthValidator.php line 21

((\is_array($object->getType()) ? \in_array('string', $object->getType()) : 'string' === $object->getType()) || null === $object->getType()) &&
            null !== $object->getMinLength();

Perhaps add a test to add minLength only if needed

((\is_array($object->getType()) ? \in_array('string', $object->getType()) : 'string' === $object->getType()) || null === $object->getType()) &&
            null !== $object->getMinLength() && $object->getMinLength()>0 ;
@leumatt leumatt added the bug label Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant