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

Dart client is not working #2240

Open
vcampitelli opened this issue May 2, 2023 · 2 comments
Open

Dart client is not working #2240

vcampitelli opened this issue May 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working client-library

Comments

@vcampitelli
Copy link

vcampitelli commented May 2, 2023

Dart client is not working

Description

As stated in FusionAuth/fusionauth-dart-client#13, our Dart client library is throwing a lot of errors.

I tried fixing it by changing the char type to String as it was complaining that char doesn't even exist and I solved all Error: The parameter '...' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null' errors by making a lot of parameters nullable.

I still received a bunch of Error: A value of type 'Future<ClientResponse<dynamic, dynamic>>' can't be returned from a function with return type 'Future<ClientResponse<ActionResponse, Errors>>' that I tried solving by changing a few things in how we use Generics but couldn't get anywhere.

Finally, I tried downgrading Dart SDK from 2.19 to 2.7 (which was the last SDK change introduced by FusionAuth/fusionauth-dart-client@b8496c5) and our lib to 1.21.0 (which is mentioned in README) and I still got errors, so I gave up.

I then tried using OpenAPI Dart Generator but got other errors. There's an open PR OpenAPITools/openapi-generator#12574 that tries to fix some of them, so I built from source and tried using it but still no luck. Finally, I tried using the OpenAPI Dart Dio Generator (that uses dio HTTP client) and it finally worked, but I still need to tweak a lot of settings to generate correct docs (that are currently wrong).

Affects versions

  • Tried a lot of client versions from 1.21.0 to 1.45.1 (latest)

Community guidelines

All issues filed in this repository must abide by the FusionAuth community guidelines.

@vcampitelli vcampitelli added bug Something isn't working client-library labels May 2, 2023
@vcampitelli
Copy link
Author

vcampitelli commented May 4, 2023

Here's how I used the OpenAPI Dart Dio Generator to build a library from our OpenAPI spec:

docker run --rm \
  -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
  -i /local/openapi.yaml \
  -g dart-dio \
  -o fusionauth_dart_client \
  -c openapi-generator-dart-dio-config.yaml

I started building an example client to be added to the fusionauth-example-client-libraries repo, but I'm waiting for any suggestions on what we should do with the Dart library itself to finish this.

import 'package:dio/dio.dart';
import 'package:fusionauth_dart_client/fusionauth_dart_client.dart';

Future<Tenant> getTenant(DefaultApi api) async {
  final response = await api.retrieveTenantWithId(tenantId: "");
  final Tenant? tenant = response.data?.tenants?[0];
  if (tenant == null) {
    throw Exception("Couldn't find any tenants");
  }
  return tenant;
}

Future<void> patchTenant(DefaultApi api, Tenant tenant, String issuer) async {
  final patched = new Tenant((b) => b..issuer = issuer);
  await api.patchTenantWithId(
      tenantId: tenant.id!,
      tenantRequest: new TenantRequest((b) => b..tenant = patched.toBuilder())
  );
}

void main() async {
  final client = FusionauthDartClient();
  client.setApiKey('ApiKeyAuth', 'Api-Key Here'); // Change this

  final api = client.getDefaultApi();
  final issuer = "http://localhost:9011";

  try {
    print('Searching Tenant...');
    final Tenant tenant = await getTenant(api);
    print(' [ ] Found: ${tenant.id}');
    print('Updating Tenant issuer: ${issuer}');
    await patchTenant(api, tenant, issuer);
  } on DioError catch (e) {
    print(e);
    print(e.response);
  }
}

@mooreds
Copy link
Collaborator

mooreds commented May 4, 2023

So I think we should definitely replace the dart client library with the one you've generated, especially after FusionAuth/fusionauth-client-builder#68 is merged.

The question is, how. Options I see are:

  • create a new repository called fusionauth-dart-client-openapi or fusionauth-dart-client-new or fusionauth-dart-client-generated or fusionauth-dart-client-v2 or fusionauth-dart-openapi-client. This is good because it sets a pattern if we want to do the same with other client libraries that work. (php, go, etc). In those cases, we'll be maintaining two versions of the client library for a substantial period of time. Any suggestions on good names?
  • because dart is totally busted, we could push this new version into the fusionauth-dart-client. That kicks the can down the road in the case of the go/php/etc, but lets us get the dart client working quickly.
  • we could I suppose have two branches inside the fusionauth-dart-client repo.
  • something else.

@andrewpai @robotdan any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client-library
Projects
None yet
Development

No branches or pull requests

2 participants