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] Problem with underscore (_) in form field names #269

Closed
dJani97 opened this issue Oct 29, 2021 · 0 comments · Fixed by #270
Closed

[BUG] Problem with underscore (_) in form field names #269

dJani97 opened this issue Oct 29, 2021 · 0 comments · Fixed by #270
Assignees
Labels
bug Something isn't working

Comments

@dJani97
Copy link

dJani97 commented Oct 29, 2021

Describe the bug
When generating formData requests, the generator doesn't handle underscore (_) in form field names well.

To Reproduce
I have the following request in our API definition:

{
  "/register":{
    "post":{
      "consumes":[
        "application/x-www-form-urlencoded"
      ],
      "produces":[
        "application/json"
      ],
      "parameters":[
        {
          "name":"name",
          "in":"formData",
          "required":true,
          "type":"string"
        },
        {
          "name":"email",
          "in":"formData",
          "required":true,
          "type":"string"
        },
        {
          "name":"password",
          "in":"formData",
          "required":true,
          "type":"string"
        },
        {
          "name":"password_confirmation",
          "in":"formData",
          "required":true,
          "type":"string"
        }
      ],
      "responses": ...
    }
  }
}

When generating the client, the output is the following Dart code:

  ///@param name name of user
  ///@param email email of user
  ///@param password password of user
  ///@param password_confirmation password confirmation of user
  @Post(path: '/register', optionalBody: true)
  Future<chopper.Response<User>> registerPost(
      {@Field() required String? name,
      @Field() required String? email,
      @Field() required String? password,
      @Field() required String? passwordConfirmation});

As you can see, the field password_confirmation appears as camel case in the code. This does not get processed by the API and the request fails.

Expected behavior

The proper output should include the password_confirmation field as follows:

      @Field('password_confirmation') required String? passwordConfirmation});

Library version used:

swagger_dart_code_generator: ^2.2.2
json_annotation: ^4.3.0
chopper_generator: ^4.0.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants