openapi_dart icon indicating copy to clipboard operation
openapi_dart copied to clipboard

Fails on a complex YAML file

Open oravecz opened this issue 5 years ago • 2 comments

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

oravecz avatar Dec 22 '20 19:12 oravecz

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.

chandu0101 avatar Apr 04 '21 10:04 chandu0101

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)

hpoul avatar Aug 07 '21 19:08 hpoul