legion-labs / legion

Legion monorepo, contains the legion engine, the tools, source control, build system etc...
https://book.legionengine.com
Other
16 stars 2 forks source link

Api codegen: Full support of additional properties #2045

Closed kevin-legion closed 2 years ago

kevin-legion commented 2 years ago

In the end of the day this pr fully supports the additionalProperties feature and not just some cases.

Here is what the codegen does when the value of additionalProperties is

@kirdaybov The support for the Python is rather limited for now as I wasn't too sure what you'd like to generate.

@ereOn I had to compromise in Rust to find a type that could feat the "any" type. There are many constraints (Clone, Hash, Deserialize, PartialEq/Ord, etc...) and unfortunately a supertrait that'd require all the above constraints would not work (since Deserialize requires Self to be Sized). We could almost use serde_json::Value but it doesn't implement Hash (https://github.com/serde-rs/json/issues/720 and https://github.com/serde-rs/json/issues/747). So instead I created a new JsonValue newtype that wraps serde_json::Value and implements Hash (it's fine except for null).

What do you think?

kevin-legion commented 2 years ago

@ereOn I applied the changes discusses here and offline: