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

Having Role enum name in createUser from swagger fails with error. #8

Open
NoWhereMan1979 opened this issue Mar 12, 2024 · 0 comments

Comments

@NoWhereMan1979
Copy link

NoWhereMan1979 commented Mar 12, 2024

Hi dear Leo.
I have problem with enum in DTO_FIELD in createUser api execution.
If i remove the role from request, it works. couldn't figure it out why.
Also my db encoding is UTF8
Thanks in advance.

Request body:

{
  "username": "string2",
  "email": "string2",
  "password": "string2",
  "role": "ROLE_GUEST"
}

Response:

{
  "status": "ERROR",
  "code": 500,
  "message": "ERROR:  invalid byte sequence for encoding \"UTF8\": 0xdd 0xdd\nCONTEXT:  unnamed portal parameter $4\n"
}

And this is my DTO:

#include OATPP_CODEGEN_BEGIN(DTO)

ENUM(Role, v_int32,
     VALUE(GUEST, 0, "ROLE_GUEST"),
     VALUE(ADMIN, 1, "ROLE_ADMIN")
)

class UserDto : public oatpp::DTO {
  
  DTO_INIT(UserDto, DTO)

  DTO_FIELD(String, id);
  DTO_FIELD(String, userName, "username");
  DTO_FIELD(String, email, "email");
  DTO_FIELD(String, password, "password");
  DTO_FIELD(Enum<Role>::AsString, role, "role");

};

#include OATPP_CODEGEN_END(DTO)

UserDb:

  QUERY(createUser,
        "INSERT INTO AppUser"
        "(id, username, email, password, role) VALUES "
        "(uuid_generate_v4(), :user.username, :user.email, :user.password, :user.role)"
        "RETURNING *;",
        PREPARE(true), // user prepared statement!
        PARAM(oatpp::Object<UserDto>, user))
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