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

[Bug]: enum_exists(): Argument #1 ($enum) must be of type string, array given #2327

Closed
DipenAVDEVS opened this issue Jul 26, 2024 · 5 comments · Fixed by #2372
Closed

[Bug]: enum_exists(): Argument #1 ($enum) must be of type string, array given #2327

DipenAVDEVS opened this issue Jul 26, 2024 · 5 comments · Fixed by #2372
Labels

Comments

@DipenAVDEVS
Copy link

DipenAVDEVS commented Jul 26, 2024

Version

4.23

Description

Argument #1 ($enum) must be of type string, array given
TRACE: #0 /srv/www/vendor/nelmio/api-doc-bundle/src/ModelDescriber/JMSModelDescriber.php(297): enum_exists()
#1 /srv/www/vendor/nelmio/api-doc-bundle/src/ModelDescriber/JMSModelDescriber.php(180): Nelmio\\ApiDocBundle\\ModelDescriber\\JMSModelDescriber->describeItem()
#2 /srv/www/vendor/nelmio/api-doc-bundle/src/Model/ModelRegistry.php(96): Nelmio\\ApiDocBundle\\ModelDescriber\\JMSModelDescriber->describe()
#3 /srv/www/vendor/nelmio/api-doc-bundle/src/ApiDocGenerator.php(129): Nelmio\\ApiDocBundle\\Model\\ModelRegistry->registerSchemas()
#4 /srv/www/vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php(76): Nelmio\\ApiDocBundle\\ApiDocGenerator->generate()
#5 /srv/www/vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php(61): Nelmio\\ApiDocBundle\\Render\\RenderOpenApi->render()\n#6 /srv/www/vendor/nelmio/api-doc-bundle/src/

When i update version from 4.10 to 4.23 . i am getting above issue

JSON OpenApi

JSON OpenApi
Replace this text with your JSON (`bin/console nelmio:apidoc:dump`)

Additional context

nelmio_api_doc:
models:
use_jms: true

documentation:
    info:
        title: Medikarma API Documentation v1.0.10
        description: >
            ## Overview

            Every request requires headers: `Authorization` and `Content-Type`. These headers are required
            regardless of the method type (GET, POST, PUT, DELETE, PATCH) used.

            * The `Content-Type` describes the data format you are transmitting.

            * The `Authorization` header is where you supply the access token. Application use Bearer Authentication.
        version: 1.0.10
    servers:
        - url: '%env(API_SERVER_URL)%'
          description: API Server
    components:
        schemas:
            version:
                type: string
                enum:
                    - v1
            category:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
            statisticsType:
                type: string
                enum:
                    - !php/const App\Entity\Enum\Class::test
                    - !php/const App\Entity\Enum\Class::test
                    - !php/const App\Entity\Enum\Class::test
            cholesterolType:
                type: string
                enum:
                    - !php/const App\Component\Chart\DTO\Class::test
                    - !php/const App\Component\Chart\DTO\Class::test
                    - !php/const App\Component\Chart\DTO\Class::test
            ClinicStatus:
                type: integer
                enum:
                    - !php/const App\Entity\Enum\Class::test
                    - !php/const App\Entity\Enum\Class::test
                description: >
                    Values:
                     * `0` - Inactive
                     * `1` - Active
            connectionType:
                type: integer
                enum:
                    - !php/const App\Entity\Enum\Class::test
                    - !php/const App\Entity\Enum\Class::test
                description: >
                    Values:
                     * `1` - Direct
                     * `2` - OneUpHealth
            glucoseProviderType:
                type: string
                enum:
                    - !php/const App\Entity\Enum\Class::test
                    - !php/const App\Entity\Enum\Class::test
            diagnosticReportType:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
            dataCategory:
                type: string
                enum:
                    - !php/const App\Component\Patient\Class::test
                    - !php/const App\Component\Patient\Enum\Class::test
            ViewingStatus:
                type: integer
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
                description: >
                    Values:
                     * `0` - Old
                     * `1` - New
            AppName:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
            questionCategory:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
            activityCategory:
                type: string
                enum:
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
            ScoreType:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
            MedicationStatus:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
            DietValue:
                type: integer
                enum:
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                description: >
                    Values:
                     * `1` - Test1
                     * `2` - test2
                     * `3` - Test3
            ExerciseValue:
                type: integer
                enum:
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                description: >
                    Values:
                     * `1` - LOW
                     * `2` - MEDIUM
                     * `3` - HIGH
            StressValue:
                type: integer
                enum:
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                description: >
                    Values:
                     * `1` - LOW
                     * `2` - FAIR
                     * `3` - HIGH
            MoodValue:
                type: integer
                enum:
                    - !php/const App\Component\Class::test
                    - !php/const App\Component\Class::test
                description: >
                    Values:
                     * `1` - Test1
                     * `2` - Test2
            BadRequestResponse:
                type: object
                properties:
                    code:
                        type: integer
                        example: 400
                    message:
                        type: string
                        example: 'Validation Failed'
                    errors:
                        type: array
                        items:
                            type: string
                            example: "Value shouldn't be blank."
            MessageTypeEnum:
                type: string
                enum:
                    - !php/const App\Entity\Class::test
                    - !php/const App\Entity\Class::test
        securitySchemes:
            Bearer:
                type: apiKey
                description: 'Value: Bearer {jwt}'
                name: Authorization
                in: header
        parameters:
            version:
                name: version
                in: path
                required: true
                schema:
                    $ref: '#/components/schemas/version'
    security:
        - Bearer: []
areas: # to filter documented areas
    default:
        path_patterns:
            - ^/api(?!/tech/(.*)|/public/terra/(.*)|/graphql/(.*)|/doc(.*)|/admin(.*)$) # Accepts routes under /api except /api/doc and api/tech
            - ^/_qa
            - ^/auth
        disable_default_routes: true

image_2024_07_26T05_39_44_106Z

@DipenAVDEVS
Copy link
Author

Still facing same issue . i try with sudo composer update and its update version to 4.23.1(nelmio/api-doc-bundle) but then also its show same error
image

@DjordyKoert DjordyKoert changed the title [Bug]: enum_exists(): Argument #1 ($enum) must be of type string, array given\nTRACE: #0 /srv/www/vendor/nelmio/api-doc-bundle/src/ModelDescriber/JMSModelDescriber.php(297): enum_exists()\n#1 /srv/www/vendor/nelmio/api-doc-bundle/src/ModelDescriber/JMSModelDescriber.php(180): Nelmio\\ApiDocBundle\\ModelDescriber\\JMSModelDescriber->describeItem()\n#2 /srv/www/vendor/nelmio/api-doc-bundle/src/Model/ModelRegistry.php(96): Nelmio\\ApiDocBundle\\ModelDescriber\\JMSModelDescriber->describe()\n#3 /srv/www/vendor/nelmio/api-doc-bundle/src/ApiDocGenerator.php(129): Nelmio\\ApiDocBundle\\Model\\ModelRegistry->registerSchemas()\n#4 /srv/www/vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php(76): Nelmio\\ApiDocBundle\\ApiDocGenerator->generate()\n#5 /srv/www/vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php(61): Nelmio\\ApiDocBundle\\Render\\RenderOpenApi->render()\n#6 /srv/www/vendor/nelmio/api-doc-bundle/src/ [Bug]: enum_exists(): Argument #1 ($enum) must be of type string, array given Aug 8, 2024
@DjordyKoert
Copy link
Collaborator

Do you also have this issue with the latest version?

@DipenAVDEVS
Copy link
Author

Yes , when i try with composer update its update to 4.23 and show me same error.

@bobvandevijver
Copy link
Contributor

I'm seeing this when I override the type with JMS to enforce a backed enum to be serialized with its name. This looks as follows:

#[Type('enum<' . ActiveCampaignListStatusEnum::class .', name>')]

This is caused due to the type not being just a string, but an array:

https://github.com/nelmio/NelmioApiDocBundle/blame/9b91d2376888c2dacf4192b103a7ff7f67112bf5/src/ModelDescriber/JMSModelDescriber.php#L331

So, it looks like this:

image

As that comes from JMS and is handled in JMS correctly, I believe it should be handled here as well. PR incoming!

@bobvandevijver
Copy link
Contributor

bobvandevijver commented Oct 11, 2024

It is only partly handled in JMS, because for this particular type annotation you apparently are required to wrap the type with quotes. So, for the example above it should become:

#[Type('enum<\'' . ActiveCampaignListStatusEnum::class .'\', 'name'>')]
or
#[Type("enum<'". ActiveCampaignListStatusEnum::class . "', 'name'>')]

Then it works as it should. Another PR will be made at JMS to solve this inconsistency.

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

Successfully merging a pull request may close this issue.

3 participants