swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.02k stars 6.03k forks source link

RUST url-encode adding None valued keys to generated URL's #9232

Closed unixunion closed 5 years ago

unixunion commented 5 years ago
Description

Some API's don't like to receive a key with a value of None on the URL example of producer URL where "cursor" should be left out as it is None.

http://URL/API/msgVpns?count=10&cursor=&where=msgVpnName==testvpn&select=*

The problem stems from that the generated API appends all query parameters regardless of value, not allowing me to omit ones which the upstream integration wants a key with value, or no key at all.

      fn get_msg_vpn_acl_profiles(&self, msg_vpn_name: &str, count: i32, cursor: &str, _where: Vec<String>, select: Vec<String>) -> Box<Future<Item = ::models::MsgVpnAclProfilesResponse, Error = Error<serde_json::Value>>> {
        let mut query = ::url::form_urlencoded::Serializer::new(String::new());
        query.append_pair("count", &count.to_string());
        query.append_pair("cursor", &cursor.to_string());
        query.append_pair("where", &_where.join(",").to_string());
        query.append_pair("select", &select.join(",").to_string());

The above query.append_pair should allow me to NOT serialise None or empty strings. The python generator solves this by using kwargs, which are obviously not serialised if not present, but with Rust, each generated API function requires all the arguments, so we need a way to ignore None or "" args.

Swagger-codegen version

2.4.2

Command line used for generation
docker run -v `pwd`:/src swaggerapi/swagger-codegen-cli:2.4.2 generate \
--config /src/config-${target}.json \
-l ${target} \
-i /src/config/${version}/semp-v2-swagger-config.yaml \
-o /src/output/${target}
unixunion commented 5 years ago

Closing this and combining with #9223