ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
141 stars 85 forks source link

Dart ory_kratos_client incompatible with many null safe packages (since 0.7.3-alpha-8) #204

Closed bpar476 closed 1 year ago

bpar476 commented 2 years ago

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

aeneasr commented 2 years ago

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

bpar476 commented 2 years ago

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

aeneasr commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

That would probably be: https://github.com/OpenAPITools/openapi-generator/issues/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 commented 2 years ago

Wrong issue, looksl ike it's: https://github.com/OpenAPITools/openapi-generator/issues/11462

bpar476 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

Looks like spec now generates with type safety, but there are generation errors for which I new ticket here https://github.com/ory/sdk/issues/230

aeneasr commented 1 year ago

Ok, closing this issue then