diff --git a/README.md b/README.md index c3eb391..705da4d 100644 --- a/README.md +++ b/README.md @@ -81,15 +81,37 @@ let images = client.images().image_list_libpod(None).await.unwrap(); ## Swagger file modifications The official swagger file generated by the podman project has a number of -issues and needs to be manually massaged. +issues and needs to be manually massaged. You can see the changes by comparing +[swagger/swagger-v5.1.0.yaml](swagger/swagger-v5.1.0.yaml) against +[swagger/swagger-v5.1.0.modified.yaml](swagger/swagger-v5.1.0.modified.yaml) + +### Renamed fields * `definitions/Mount/properties/Target` renamed to `Destination` + +### Missing type info + * `definitions/ListContainer/properties/ExposedPorts` type set to `object` -* `definitions/InspectNetworkSettings/properties/Ports/additionalProperties` type set to `nullable` -* `definitions/InspectPodInfraConfig/properties/PortBindings/additionalProperties` type set to `nullable` -* `definitions/PodRmReport/properties/RemovedCtrs/additionalProperties` type set to `nullable` -More adjustments likely to come. +### Nullable fields + +It turns out golang is a bit loosey goosey with nils. The following fields were +set to nullable: + +* `definitions/InspectNetworkSettings/properties/Ports/additionalProperties` +* `definitions/InspectPodInfraConfig/properties/PortBindings/additionalProperties` +* `definitions/PodRmReport/properties/RemovedCtrs/additionalProperties` + +### Client side defaults + +Some requests return extra streaming data with their responses by default. Our +client doesn't support this, so we set up some client side overrides to set the +`quiet` parameters on these requests to true + +* `responses//libpod/images/pull/post/parameters` +* `responses//libpod/images/scp/{name}/post/parameters` + +More adjustments likely to come as we run into issues and should be documented here ## Changelog @@ -99,7 +121,7 @@ More adjustments likely to come. #### Breaking Changes -* Query and Header parameters are now provided through structs in `params` module +* Query and Header parameters are now provided through structs from the `params` module * Body parameters are no longer optional. * Some i32/u32 fields became i16/u16 * API functions no longer have the _api suffix diff --git a/openapi-client-gen/src/generate/rust_hyper_legacy/templates/apis.rs b/openapi-client-gen/src/generate/rust_hyper_legacy/templates/apis.rs index badea77..5a46698 100644 --- a/openapi-client-gen/src/generate/rust_hyper_legacy/templates/apis.rs +++ b/openapi-client-gen/src/generate/rust_hyper_legacy/templates/apis.rs @@ -1,7 +1,9 @@ use proc_macro2::TokenStream; use quote::quote; -use crate::lang::rust::{model_type, parameter_to_str, struct_name, to_doc_comment, var_name}; +use crate::lang::rust::{ + model_type, or_default, parameter_to_str, struct_name, to_doc_comment, var_name, +}; use crate::{error::Error, spec::Spec, tag::Tag}; pub fn api(spec: &Spec, tag: &Tag) -> Result { @@ -110,9 +112,10 @@ pub fn operations(spec: &Spec, tag: &Tag) -> Result, Error> { let to_string = parameter_to_str("e! { params.#var_name }, param); quote! { query_pairs.append_pair(#name, #to_string); } } else { + let or_default = or_default(¶m.x_client_default); let to_string = parameter_to_str("e! { #var_name }, param); quote! { - if let Some(#var_name) = params.#var_name { + if let Some(#var_name) = params.#var_name #or_default { query_pairs.append_pair(#name, #to_string); } } @@ -136,8 +139,9 @@ pub fn operations(spec: &Spec, tag: &Tag) -> Result, Error> { if param.required { quote! { req_builder = req_builder.header(#name, params.#var_name); } } else { + let or_default = or_default(¶m.x_client_default); quote! { - if let Some(#var_name) = params.#var_name { + if let Some(#var_name) = params.#var_name #or_default { req_builder = req_builder.header(#name, #var_name); } } diff --git a/openapi-client-gen/src/generate/rust_hyper_legacy/templates/config.rs b/openapi-client-gen/src/generate/rust_hyper_legacy/templates/config.rs index 3db3075..0ab656e 100644 --- a/openapi-client-gen/src/generate/rust_hyper_legacy/templates/config.rs +++ b/openapi-client-gen/src/generate/rust_hyper_legacy/templates/config.rs @@ -1,4 +1,3 @@ -use proc_macro2::TokenStream; use quote::quote; use crate::{error::Error, spec::Spec}; diff --git a/openapi-client-gen/src/lang/rust.rs b/openapi-client-gen/src/lang/rust.rs index b7eaedb..dc5f04b 100644 --- a/openapi-client-gen/src/lang/rust.rs +++ b/openapi-client-gen/src/lang/rust.rs @@ -12,6 +12,7 @@ use crate::model::Model; use crate::model::ModelData; use crate::operation; use crate::parameter; +use crate::parameter::XClientDefault; use crate::parse; /// Format name to a conventional upper camel rust ident for struct and trait names @@ -167,3 +168,15 @@ pub fn model_type(model: &Model, models: &BTreeMap) -> Result) -> TokenStream { + if let Some(default) = default { + match default { + XClientDefault::String(string) => quote! { .or(Some(#string)) }, + XClientDefault::Boolean(bool) => quote! { .or(Some(#bool)) }, + XClientDefault::Integer(int) => quote! { .or(Some(#int)) }, + } + } else { + TokenStream::new() + } +} diff --git a/openapi-client-gen/src/spec.rs b/openapi-client-gen/src/spec.rs index 965f1ba..0a71e5d 100644 --- a/openapi-client-gen/src/spec.rs +++ b/openapi-client-gen/src/spec.rs @@ -190,15 +190,14 @@ mod tests { #[test] fn builds_base_path() { - let spec = Spec::from_yaml_string( - indoc! {r#" + let spec = Spec::from_yaml_string(indoc! {r#" basePath: / host: example.com schemes: - http - https - "#} - ).unwrap(); + "#}) + .unwrap(); assert_eq!(spec.base_path, "http://example.com/"); } } diff --git a/podman-autogen-api/src/apis/images.rs b/podman-autogen-api/src/apis/images.rs index 47a63f0..58f8202 100644 --- a/podman-autogen-api/src/apis/images.rs +++ b/podman-autogen-api/src/apis/images.rs @@ -650,7 +650,7 @@ pub trait Images: HasConfig + Send + Sync { if let Some(reference) = params.reference { query_pairs.append_pair("reference", reference); } - if let Some(quiet) = params.quiet { + if let Some(quiet) = params.quiet.or(Some(true)) { query_pairs.append_pair("quiet", &quiet.to_string()); } if let Some(compat_mode) = params.compat_mode { @@ -750,7 +750,7 @@ pub trait Images: HasConfig + Send + Sync { if let Some(destination) = params.destination { query_pairs.append_pair("destination", destination); } - if let Some(quiet) = params.quiet { + if let Some(quiet) = params.quiet.or(Some(true)) { query_pairs.append_pair("quiet", &quiet.to_string()); } } diff --git a/swagger/swagger-v5.1.0.modified.yaml b/swagger/swagger-v5.1.0.modified.yaml index 96e2090..28b9fe1 100644 --- a/swagger/swagger-v5.1.0.modified.yaml +++ b/swagger/swagger-v5.1.0.modified.yaml @@ -15077,6 +15077,7 @@ paths: in: query name: quiet type: boolean + x-client-default: true - default: false description: Return the same JSON payload as the Docker-compat endpoint. in: query @@ -15182,6 +15183,7 @@ paths: in: query name: quiet type: boolean + x-client-default: true produces: - application/json responses: diff --git a/tests/common.rs b/tests/common.rs index 24632f9..780ecab 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -58,7 +58,6 @@ pub async fn pull_nginx_image(client: &PodmanRestClient) { .images() .image_pull_libpod(Some(params::ImagePullLibpod { reference: Some("docker.io/library/nginx:latest"), - quiet: Some(true), ..Default::default() })) .await diff --git a/tests/test.rs b/tests/test.rs index 45c1a21..310f03d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -70,7 +70,6 @@ async fn it_can_pull_images() { .images() .image_pull_libpod(Some(params::ImagePullLibpod { reference: Some("docker.io/library/nginx:latest"), - quiet: Some(true), ..Default::default() })) .await