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 ory_kratos_client incompatible with many null safe packages (since 0.7.3-alpha-8) #204

Closed
4 of 6 tasks
bpar476 opened this issue Jul 28, 2022 · 14 comments
Closed
4 of 6 tasks
Labels
bug Something is not working.

Comments

@bpar476
Copy link

bpar476 commented Jul 28, 2022

Preflight checklist

Describe the bug

When importing the dart ory_kratos_client https://pub.dev/packages/ory_kratos_client, it fails to resolve dependencies when using many other packages with null-safety features. For example the latest http package https://pub.dev/packages/http or the google_fonts package https://pub.dev/packages/google_fonts. This basically makes the SDK unusable for modern flutter projects where null-safety is the default.

When trying to resolve the dependencies, we see the culprit is a dependency of the ory_kratos_client package itself which depends on a version of the dio library which in turn depends on a non-null-safe version of the http_parser package.

Reproducing the bug

  1. Generate an empty flutter project: flutter create helloworld
  2. Add the http package: flutter pub add http
  3. Manually add the latest ory_kratos_client package to pubspec.yaml: ory_kratos_client: ^0.10.1
  4. Run flutter pub get

Resultant pubspec.yaml:

name: helloworld
description: A new Flutter project.

publish_to: 'none' 

version: 1.0.0+1

environment:
  sdk: ">=2.16.1 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  http: ^0.13.4
  ory_kratos_client: ^0.10.1

dev_dependencies:
  flutter_test:
    sdk: flutter

Relevant log output

flutter pub get

➜ helloworld flutter pub get
Because ory_kratos_client >=0.7.5-alpha.2 depends on dio ^3.0.9 which depends on http_parser >=0.0.1 <4.0.0, ory_kratos_client >=0.7.5-alpha.2 requires http_parser >=0.0.1 <4.0.0.
And because http 0.13.4 depends on http_parser ^4.0.0 and no versions of http match >0.13.4 <0.14.0, ory_kratos_client >=0.7.5-alpha.2 is incompatible with http ^0.13.4.
So, because helloworld depends on both http ^0.13.4 and ory_kratos_client ^0.10.1, version solving failed.
Running "flutter pub get" in helloworld...
pub get failed (1; So, because helloworld depends on both http ^0.13.4 and ory_kratos_client ^0.10.1, version solving failed.)

Relevant configuration

No response

Version

0.10.1

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

No response

Additional Context

No response

@bpar476 bpar476 added the bug Something is not working. label Jul 28, 2022
@aeneasr
Copy link
Member

aeneasr commented Jul 28, 2022

Try https://pub.dev/packages/ory_client instead!

@bpar476
Copy link
Author

bpar476 commented Jul 28, 2022

Oh that one resolves just fine, thanks! Are both packages needed? Should the ory_kratos_client be deprecated?

@aeneasr
Copy link
Member

aeneasr commented Jul 28, 2022

We will eventually deprecate them. ory_client is always ahead because it is in sync with Ory Cloud. The other SDKs need an open source release to be updated

@bpar476
Copy link
Author

bpar476 commented Jul 28, 2022

Hmm, so I was able to resolve dependencies, but my app does not compile. You can see the same errors in the "Pass Static Analysis" section of https://pub.dev/packages/ory_client/score, pasted below for convenience:

../../Library/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/ory_client-0.2.0-alpha.4/lib/model/generic_error.dart:186:22: Error: Member not found:
    'Map.listFromJson'.
            details: Map.listFromJson(json[r'details']) ?? const [],
                         ^^^^^^^^^^^^
    ../../Library/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/ory_client-0.2.0-alpha.4/lib/model/identity.dart:205:42: Warning: Operand of null-aware
    operation '??' has type 'Map<String, IdentityCredentials>' which excludes null.
     - 'Map' is from 'dart:core'.
     - 'IdentityCredentials' is from 'package:ory_client/api.dart'
     ('../../Library/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/ory_client-0.2.0-alpha.4/lib/api.dart').
            credentials: IdentityCredentials.mapFromJson(json[r'credentials']) ?? const {},

@aeneasr
Copy link
Member

aeneasr commented Jul 28, 2022

That would probably be: OpenAPITools/openapi-generator#4887

Looks like this is resolved but not yet released. Once it's released, we can upgrade the dart generator to resolve this bug. Sorry but it's out of our hands :(

@aeneasr
Copy link
Member

aeneasr commented Jul 28, 2022

Wrong issue, looksl ike it's: OpenAPITools/openapi-generator#11462

@bpar476
Copy link
Author

bpar476 commented Jul 28, 2022

Should I open a separate issue for the ory_client build issues?

Also there's another issue besides the Map listFromJson method: the bill coalescing operator being used on non-nullable type. I'll have a look at the generator some time and see if there's an issue for that and maybe if there's a quick fix.

@aeneasr
Copy link
Member

aeneasr commented Jul 29, 2022

We can use this one to track this :)

Any fixes you're able to make towards openapi generator would highly be appreciated! Unfortunately I don't know Dart/Flutter which is why I can't really help to fix it :)

@bpar476
Copy link
Author

bpar476 commented Aug 2, 2022

After a bit of digging, it looks like the issue for both packages is resolved for the latest version of open-api-generator 6.0.1 when using the dart-dio generator. Looks like we're currently using 5.2.1. Is it possible to upgrade?

@Nihildum
Copy link

Nihildum commented Aug 2, 2022

I have the same problem and generated a version for myself with dart-dio and open-api-generator 6.0.1. I have now the problem that the serialization is not working. When doing:

    String basePath = "http://10.10.20.20:4433";
    OryClient client = OryClient(basePathOverride: basePath);
    V0alpha2Api apiV2 = client.getV0alpha2Api();

    try {
      final response = await apiV2.initializeSelfServiceLoginFlowWithoutBrowser();
      print(response);
    } catch (e) {
      print("Exception when calling MetadataApi->getVersion: $e\n");
    }

I get the error:

I/flutter (15686): Exception when calling MetadataApi->getVersion: DioError [DioErrorType.other]: Deserializing '[id, ddc45483-fccb-4940-af32-05722db008c9, type, api, expires_at, 2022-08-02T...' to 'SelfServiceLoginFlow' failed due to: Deserializing '[action, http://127.0.0.1:4433/self-service/login?flow=ddc45483-fccb-4940-af3...' to 'UiContainer' failed due to: Deserializing '[{type: input, group: default, attributes: {name: csrf_token, type: hidden, v...' to 'BuiltList<UiNode>' failed due to: Deserializing '[type, input, group, default, attributes, {name: csrf_token, type: hidden, va...' to 'UiNode' failed due to: Deserializing '[name, csrf_token, type, hidden, value, , required, true, disabled, false, no...' to 'UiNodeAttributes' failed due to: Tried to build class "UiNodeAttributes" but nested builder for field "text" threw: Tried to construct class "UiText" with null field "id". This is forbidden; to allow it, mark "id" with @nullable.

As a kratos server I am using the one from the quickstart (https://www.ory.sh/docs/kratos/quickstart). Do I need to use a different version?

@bpar476
Copy link
Author

bpar476 commented Aug 4, 2022

Hmm, I've just tried using the kratos sdk generated with the dart-dio exporter I couldn't get it to compile. I think I'm just going to have to continue with a manually implemented client for now.

@bpar476
Copy link
Author

bpar476 commented Aug 4, 2022

When trying with the newest version of OpenAPIGenerator and the dart exporter this also failed. Looks like the dart tooling for open-api-generator is maybe not mature enough.

@AllenKaplan
Copy link
Contributor

Looks like spec now generates with type safety, but there are generation errors for which I new ticket here #230

@aeneasr
Copy link
Member

aeneasr commented Dec 6, 2022

Ok, closing this issue then

@aeneasr aeneasr closed this as completed Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

No branches or pull requests

4 participants