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

Consider allowing int for number type #776

Open
jseparovic1 opened this issue Dec 19, 2023 · 0 comments
Open

Consider allowing int for number type #776

jseparovic1 opened this issue Dec 19, 2023 · 0 comments
Labels

Comments

@jseparovic1
Copy link

jseparovic1 commented Dec 19, 2023

Jane version(s) affected: 7.5 using open-api-2

Description
Given following path in OpenAPI 2.0 schema:

{
    "/v1/accounts": {
      "get": {
        "summary": "List accounts",
        "operationId": "getV1Accounts",
        "description": "Lists registered accounts",
        "parameters": [
          {
            "type": "number",
            "description": "Page number (zero indexed, so use 0 for first page)",
            "default": 0,
            "minimum": 0,
            "maximum": 1048576,
            "name": "page",
            "in": "query"
          },
          {
            "type": "number",
            "description": "How many entries per page",
            "default": 20,
            "minimum": 1,
            "maximum": 1000,
            "name": "pageSize",
            "in": "query"
          },
        ]
    }
}

Result

  1. It creates following query options resolver:
protected function getQueryOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
    {
        $optionsResolver = parent::getQueryOptionsResolver();
        $optionsResolver->setDefined(['page', 'pageSize']);
        $optionsResolver->setRequired([]);
        $optionsResolver->setDefaults(['page' => 0, 'pageSize' => 20]);
        $optionsResolver->addAllowedTypes('page', ['float']);
        $optionsResolver->addAllowedTypes('pageSize', ['float']);
        return $optionResolver;
}

Using the client results in bad DX:

$client->getV1Accounts(); // Exception `int` provided but `float` is expected.
$client->getV1Accounts(queryParameters: ['page'=> 0.0, ''pageSize' => 20.0]); // Works fine.

Possible Solution
Allow to use int in case of number and then cast it.

Additional context
According to OpenAPI specification [1] OpenAPI has two numeric types, number and integer, where number includes both integer and floating-point numbers.

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