From 87749a11ee31f9d12e804727e291c70a830cc1af Mon Sep 17 00:00:00 2001 From: Adam Leventhal Date: Mon, 8 May 2023 11:16:48 -0700 Subject: [PATCH] update for new dropshot pagination format (#465) --- progenitor-impl/src/method.rs | 30 ++++++++++++++++++++++-------- sample_openapi/nexus.json | 4 +++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/progenitor-impl/src/method.rs b/progenitor-impl/src/method.rs index 82ad44b..abca9f0 100644 --- a/progenitor-impl/src/method.rs +++ b/progenitor-impl/src/method.rs @@ -89,6 +89,10 @@ struct BuilderImpl { pub struct DropshotPagination { item: TypeId, + // TODO this is going to be used by the SDK and CLI generation to validate + // inputs. + #[allow(unused)] + first_page_params: Vec, } pub struct OperationParameter { @@ -1214,14 +1218,10 @@ impl Generator { parameters: &[OperationParameter], responses: &[OperationResponse], ) -> Option { - if operation - .extensions - .get("x-dropshot-pagination") - .and_then(|v| v.as_bool()) - != Some(true) - { + let Some(value) = operation.extensions.get("x-dropshot-pagination") + else { return None; - } + }; // We expect to see at least "page_token" and "limit" parameters. if parameters @@ -1316,7 +1316,21 @@ impl Generator { .ok()? .details() { - typify::TypeDetails::Vec(item) => Some(DropshotPagination { item }), + typify::TypeDetails::Vec(item) => { + #[derive(serde::Deserialize, Default)] + struct DropshotPaginationFormat { + required: Vec, + } + let first_page_params = serde_json::from_value::< + DropshotPaginationFormat, + >(value.clone()) + .unwrap_or_default() + .required; + Some(DropshotPagination { + item, + first_page_params, + }) + } _ => None, } } diff --git a/sample_openapi/nexus.json b/sample_openapi/nexus.json index 29689c7..3ae33fe 100644 --- a/sample_openapi/nexus.json +++ b/sample_openapi/nexus.json @@ -579,7 +579,9 @@ "$ref": "#/components/responses/Error" } }, - "x-dropshot-pagination": true + "x-dropshot-pagination": { + "required": [] + } } }, "/login": {