hpoul / openapi_dart

Dart implementation to generate (dart) server stubs and client libraries from OpenAPI 3.0 yaml files.
38 stars 18 forks source link

Fails on a complex YAML file #1

Open oravecz opened 3 years ago

oravecz commented 3 years ago

The sample yaml in the README file works fine, but when I run the code generator against the rather large YAML file found as part of the Open Banking API, it crashes.

% pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script completed, took 529ms
[INFO] Reading cached asset graph completed, took 186ms
[INFO] Checking for updates since last build completed, took 1.6s
[SEVERE] openapi_code_builder:openapi_code_builder on lib/account-info.openapi.yaml:

Converting object to an encodable object failed: Instance of 'YamlMap'
[INFO] Running build completed, took 483ms
[INFO] Caching finalized dependency graph completed, took 53ms
[SEVERE] Failed after 559ms

The YAML file I am using can be found at this URL: https://raw.githubusercontent.com/OpenBankingUK/read-write-api-specs/master/dist/openapi/account-info-openapi.yaml

chandu0101 commented 3 years ago

code is failing at https://github.com/hpoul/openapi_dart/blob/f1970e6cf9fbac0c9cb55933ba146e3c12194f6d/packages/openapi_code_builder/lib/src/openapi_code_builder.dart#L1231

 final dynamic tmp = loadYaml(source);
    final content = json.encode(tmp)); // error 

this should be fixed in yaml package itself! , or this lib should support json file inputs so that user can use service like https://onlineyamltools.com/convert-yaml-to-json , to convert to json and then use it as input.

hpoul commented 3 years ago

sorry for the late response.. but imho that yaml schema is not valid..

The keys (status codes) of responses must be strings.. because in JSON all keys must be strings. This is probably the reason why json.encode jokes at this point.

Screen Shot 2021-08-07 at 21 14 13

Although to be honest, I've developed the generator to generate a simple server/client pair, not necessary generate the client for existing complicated schemas.. but i'll see if I can get it to work.. still interesting.. But I think the best use case is using it for client AND server.. (there are a lot of client side dart generators already out there)