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

[8.1] No serialization of the enum values for path parameters #113

Closed
curious-teapot opened this issue Jun 3, 2024 · 1 comment · Fixed by #114
Closed

[8.1] No serialization of the enum values for path parameters #113

curious-teapot opened this issue Jun 3, 2024 · 1 comment · Fixed by #114

Comments

@curious-teapot
Copy link

Hello. I'm having trouble using enums as path parameters.
The issue arises when making a request.

Error:

Object of class Group\SomeApiClient\Schema\ResourceTypeEnum could not be converted to string

As far I can tell the problem is that the strtr function cannot accept enum value as an argument

strtr('v1/{resource-type}/resource', ['{resource-type}' => $this->resourceType]);

Example schema

openapi: 3.0.0
info:
  version: 1.0.0
  title: Example API
paths:
  '/v1/{resource-type}/resource':
    parameters:
      - $ref: '#/components/parameters/ResourceType'
    get:
      operationId: getResource
      responses:
        '201':
          description: OK

components:
  parameters:
    ResourceType:
      name: resource-type
      in: path
      required: true
      schema:
        type: string
        enum:
          - one
          - two

client generation parameters

docker run -it \
-v ./openapi.yaml:/openapi.yaml:ro \
-v ./client:/client \
-e NAMESPACE=Group\\SomeApiClient \
-e OPENAPI=/openapi.yaml \
-e OUTPUT_DIR=/client \
-e PACKAGE=group/some-api-client \
-e CLIENT_PHP_VERSION=8.1 \
dhlabs/api-client-generator:10.8

Generated request

<?php

declare(strict_types=1);

/*
 * This file was generated by docler-labs/api-client-generator.
 *
 * Do not edit it manually.
 */

namespace Group\SomeApiClient\Request;

use Group\SomeApiClient\Schema\ResourceTypeEnum;

class GetResourceRequest implements RequestInterface
{
    private string $contentType = '';

    public function __construct(private readonly ResourceTypeEnum $resourceType)
    {
    }

    public function getContentType(): string
    {
        return $this->contentType;
    }

    public function getMethod(): string
    {
        return 'GET';
    }

    public function getRoute(): string
    {
        return strtr('v1/{resource-type}/resource', ['{resource-type}' => $this->resourceType]);
    }

    public function getQueryParameters(): array
    {
        return [];
    }

    public function getRawQueryParameters(): array
    {
        return [];
    }

    public function getCookies(): array
    {
        return [];
    }

    public function getHeaders(): array
    {
        return [];
    }

    public function getBody()
    {
        return null;
    }
}

@vsouz4 vsouz4 linked a pull request Jun 4, 2024 that will close this issue
@vsouz4
Copy link
Collaborator

vsouz4 commented Jun 4, 2024

thx @curious-teapot for reporting the issue, fix is released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants