epam-cross-platform-lab / swagger-dart-code-generator

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter
Apache License 2.0
268 stars 124 forks source link

Why is different code generated with the same swagger file? I give an example below. #770

Open rym236 opened 1 month ago

rym236 commented 1 month ago

The project was like this from the beginning and everything worked well.

//Login and password authorization
  ///@param username Name
  ///@param password password
  Future<chopper.Response<Object>> loginJsonPost({
    required String? username,
    required String? password,
  }) {
    return _loginJsonPost(username: username, password: password);
  }

///Login and password authorization
  ///@param username Name
  ///@param password password
  @Post(
    path: '/login.json',
    optionalBody: true,
  )
  Future<chopper.Response<Object>> _loginJsonPost({
    @Query('username') required String? username,
    @Query('password') required String? password,
  });

After regenerating the chopper code, it became like this and now an error occurs when trying to log in Error:type 'Response' is not a subtype of type 'Response<LoginJsonPost$Response>' in type cast:

Future<chopper.Response<LoginJsonPost$Response>> loginJsonPost({
    required String? username,
    required String? password,
  }) {
    generatedMapping.putIfAbsent(
        LoginJsonPost$Response, () => LoginJsonPost$Response.fromJsonFactory);

    return _loginJsonPost(username: username, password: password);
  }

  ///Login and password authorization
  ///@param username Name
  ///@param password password
  @Post(
    path: '/login.json',
    optionalBody: true,
  )
  Future<chopper.Response<LoginJsonPost$Response>> _loginJsonPost({
    @Query('username') required String? username,
    @Query('password') required String? password,
  });

However, the swagger code for this method has not changed. Please tell me why this is happening, what needs to be done to return to the previous state?

Vovanella95 commented 1 month ago

Hello!

Old version returned Object as a return type. New version supports responses as models. In your case it's LoginJsonPost$Response. Previously, you had Object and needed to parse it manually.

Regarding your error (Response<LoginJsonPost$Response>' in type cast) I need more details. On which line it's occurs?