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

[PHP] Codegen generates models for schemas that are not objects #12450

Open
javaDeveloperKid opened this issue Aug 18, 2024 · 0 comments
Open

Comments

@javaDeveloperKid
Copy link

javaDeveloperKid commented Aug 18, 2024

Description

I have an endpoint that returns a User object:

paths:
  /users/{id}:
      # ...
      responses:
        200:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'

And models:

components:
  schemas:
    User:
      type: object
      properties:
        id: 
          $ref: '#/components/schemas/UserId'
        # other properties
    UserId:
      type: string
      format: uuid

This tool generates an empty model class for UserId, i.e. a class without properties. This makes things unusable because when deserializing API response to User object it sets id property to empty UserId object.
IMO we should not generate classes for models that are not objects. If a property is a reference to the model that is not an object then we should inherit a type from this model.

Example from PHP:
Current behaviour

class User implements ModelInterface, ArrayAccess
{
    protected static $swaggerTypes = [
        'id' => '\Example\Model\UserId'
    ];

    // ...
}

class UserId implements ModelInterface, ArrayAccess
{
    protected static $attributeMap = [
    ];

    public function __construct(array $data = null)
    {
    }

    // ...
}

Expected behaviour

class User implements ModelInterface, ArrayAccess
{
    protected static $swaggerTypes = [
        'id' => 'string'
    ];

    // ...
}
Swagger-codegen version

swaggerapi/swagger-codegen-cli-v3:3.0.61

Swagger declaration file content or url
Command line used for generation
docker run --rm -v "${PWD}" swaggerapi/swagger-codegen-cli-v3:3.0.61 generate -i /swagger.yml -l php
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
@javaDeveloperKid javaDeveloperKid changed the title Codegen generates models for schemas that are not objects [PHP] Codegen generates models for schemas that are not objects Aug 18, 2024
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

No branches or pull requests

1 participant