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

feat: add new classes for PassageUser, CreateUserArgs, and UpdateUserArgs #90

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

ctran88
Copy link
Contributor

@ctran88 ctran88 commented Dec 10, 2024

What's New?

Screenshots (if appropriate):

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have manually tested my code thoroughly
  • I have added/updated inline documentation for public facing interfaces if relevant
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing integration and unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional context


use OpenAPI\Client\Model\CreateUserRequest;

class CreateUserArgs extends CreateUserRequest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't get class_alias to resolve the imports correctly, so just went with creating new classes. These are only used with the new function signatures. All of the old ones still use the same codegen'd classes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

use OpenAPI\Client\Model\CreateUserRequest as CreateUserArgs; wasn't working in the Passage.php file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class CreateUserArgs extends CreateUserRequest creates a new class with the name, which is available to be imported/used by any dev external to this file

use OpenAPI\Client\Model\CreateUserRequest as CreateUserArgs; only allows the CreateUserArgs name to be used within the file the line is written in

@@ -263,4 +267,15 @@ public function revokeRefreshTokens(string $userId): void
throw PassageError::fromApiException($e);
}
}

private function castUserInfoToPassageUser(UserInfo $userInfo): PassageUser
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated just to keep this function private and to not have to create a whole base class to inherit from just for this.

@ctran88 ctran88 marked this pull request as ready for review December 10, 2024 21:20
@ctran88 ctran88 force-pushed the PSG-5536-fix-class-aliasing branch from 4836636 to 837fae4 Compare December 11, 2024 17:21
} catch (PassageError $e) {
throw $e->getPrevious();
}
}

private function cast(object $object, string $class): mixed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this. Why is it was expecting one class but receiving another? For instance, why would createUser not expect CreateUserRequest? This is the class that is genreated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's because of the class aliasing. the new functions take a different class name. in the other languages it was as easy as type aliasing but i tried php's class_alias, which didn't seem to work to allow an end user to use the aliased class names. so i had to create new classes that are just copies of the generated classes with different names. because of that, it was necessary to cast the classes otherwise it threw an error at runtime

Comment on lines -10 to -12
use OpenAPI\Client\Model\UserInfo as PassageUser;
use OpenAPI\Client\Model\UpdateUserRequest as UpdateUserArgs;
use OpenAPI\Client\Model\CreateUserRequest as CreateUserArgs;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't working in the Passage.php file so you created the workaround?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was working, but only within the scope of this file. it didn't actually alias the class names for an external dev

@ctran88 ctran88 merged commit 7afac85 into main Dec 11, 2024
4 checks passed
@ctran88 ctran88 deleted the PSG-5536-fix-class-aliasing branch December 11, 2024 19:13
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 this pull request may close these issues.

3 participants