diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 85f3c28c1..456f05335 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -39804,7 +39804,9 @@ components: nullable: true type: string has_submitted: - description: Whether the current user has already submitted this form. Only present for forms with `single_response` set to `true`. + description: |- + Whether the current user has already submitted this form. Only present for forms with + `single_response` set to `true`. nullable: true type: boolean idp_survey: @@ -40119,6 +40121,10 @@ components: example: b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d nullable: true type: string + has_ever_been_published: + description: Whether this version number has ever appeared in the form's publication history. + example: true + type: boolean id: description: The ID of the form version. example: "126" @@ -40175,6 +40181,15 @@ components: - type - attributes type: object + FormVersionListType: + default: form_version_lists + description: The resource type for a list of form versions. + enum: + - form_version_lists + example: form_version_lists + type: string + x-enum-varnames: + - FORM_VERSION_LISTS FormVersionResponse: description: A response containing a single form version. properties: @@ -58917,6 +58932,41 @@ components: - data - meta type: object + ListFormVersionsData: + description: A list-of-form-versions resource object. + properties: + attributes: + $ref: "#/components/schemas/ListFormVersionsDataAttributes" + id: + description: The ID of the form. + example: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + type: string + type: + $ref: "#/components/schemas/FormVersionListType" + required: + - id + - type + - attributes + type: object + ListFormVersionsDataAttributes: + description: The attributes for a list of form versions. + properties: + versions: + description: The list of versions for the form. + items: + $ref: "#/components/schemas/FormVersionAttributes" + type: array + required: + - versions + type: object + ListFormVersionsResponse: + description: A response containing the list of versions for a form. + properties: + data: + $ref: "#/components/schemas/ListFormVersionsData" + required: + - data + type: object ListHistoricalJobsResponse: description: List of historical jobs. properties: @@ -139534,7 +139584,9 @@ paths: **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). post: - description: Create a new form. The form is created in draft mode and must be published before it can be used. This also creates a new datastore for form responses and links it to the form. + description: |- + Create a new form. The form is created in draft mode and must be published before it can be used. This + also creates a new datastore for form responses and links it to the form. operationId: CreateForm requestBody: content: @@ -139608,7 +139660,9 @@ paths: If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). /api/v2/forms/create_and_publish: post: - description: Creates a new form and immediately publishes its initial version. This also creates a new datastore for form responses and links it to the form. + description: |- + Creates a new form and immediately publishes its initial version. This also creates a new datastore for + form responses and links it to the form. operationId: CreateAndPublishForm requestBody: content: @@ -139738,7 +139792,9 @@ paths: schema: format: uuid type: string - - description: The version of the form to retrieve. Use 'latest' for the most recent draft, 'published' for the last published version, or a specific version number. + - description: |- + The version of the form to retrieve. Use 'latest' for the most recent draft, 'published' for the + last published version, or a specific version number. in: query name: version required: false @@ -140045,6 +140101,72 @@ paths: **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). /api/v2/forms/{form_id}/versions: + get: + description: List all versions of a form. + operationId: ListFormVersions + parameters: + - description: The ID of the form. + example: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + in: path + name: form_id + required: true + schema: + format: uuid + type: string + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + versions: + - created_at: "2026-05-29T20:06:14.895921Z" + data_definition: {} + definition_signature: >- + {"signature":"b7f312957a80cea2c8c9950532b205a90a3f8a7ebb7e52fc25437a25d903d545", "version":1} + etag: b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d + has_ever_been_published: true + id: "126" + modified_at: "2026-05-29T20:06:14.949163Z" + state: draft + ui_definition: {} + user_id: 10001 + user_uuid: 1fc709aa-be19-4539-a47d-52a30d78a978 + version: 2 + id: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + type: form_version_lists + schema: + $ref: "#/components/schemas/ListFormVersionsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: List form versions + tags: + - Forms + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). post: description: |- Create or update the latest draft version of a form. The `upsert_params` field controls @@ -140088,7 +140210,8 @@ paths: created_at: "2026-05-29T20:06:14.895921Z" data_definition: $ref: "#/components/schemas/FormDataDefinition" - definition_signature: '{"signature":"b7f312957a80cea2c8c9950532b205a90a3f8a7ebb7e52fc25437a25d903d545","version":1}' + definition_signature: >- + {"signature":"b7f312957a80cea2c8c9950532b205a90a3f8a7ebb7e52fc25437a25d903d545", "version":1} etag: b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d modified_at: "2026-05-29T20:06:14.949163Z" state: draft @@ -140127,6 +140250,85 @@ paths: x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/forms/{form_id}/versions/revert: + post: + description: Revert a form to a prior version by creating a new draft version copied from it. + operationId: RevertFormVersion + parameters: + - description: The ID of the form. + example: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + in: path + name: form_id + required: true + schema: + format: uuid + type: string + - description: The version number to revert to. + example: 1 + in: query + name: version + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + created_at: "2026-05-29T20:10:14.895921Z" + data_definition: + $ref: "#/components/schemas/FormDataDefinition" + definition_signature: >- + {"signature":"c8f312957a80cea2c8c9950532b205a90a3f8a7ebb7e52fc25437a25d903d545", "version":1} + etag: c61f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d + modified_at: "2026-05-29T20:10:14.949163Z" + state: draft + ui_definition: {} + user_id: 10001 + user_uuid: 1fc709aa-be19-4539-a47d-52a30d78a978 + version: 3 + id: "127" + type: form_versions + schema: + $ref: "#/components/schemas/FormVersionResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "409": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Conflict + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Revert a form to a prior version + tags: + - Forms + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). /api/v2/forms/{form_id}/versions/upsert_and_publish: post: description: Upsert the latest form version and publish it in a single atomic transaction. diff --git a/examples/v2_forms_ListFormVersions.rs b/examples/v2_forms_ListFormVersions.rs new file mode 100644 index 000000000..edc8d0d97 --- /dev/null +++ b/examples/v2_forms_ListFormVersions.rs @@ -0,0 +1,21 @@ +// List form versions returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; +use uuid::Uuid; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListFormVersions", true); + let api = FormsAPI::with_config(configuration); + let resp = api + .list_form_versions( + Uuid::parse_str("00000000-0000-0000-0000-000000000000").expect("invalid UUID"), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_forms_RevertFormVersion.rs b/examples/v2_forms_RevertFormVersion.rs new file mode 100644 index 000000000..abf5b5ca8 --- /dev/null +++ b/examples/v2_forms_RevertFormVersion.rs @@ -0,0 +1,22 @@ +// Revert a form to a prior version returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; +use uuid::Uuid; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.RevertFormVersion", true); + let api = FormsAPI::with_config(configuration); + let resp = api + .revert_form_version( + Uuid::parse_str("00000000-0000-0000-0000-000000000000").expect("invalid UUID"), + 9223372036854775807, + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index abd6cc733..4eb80ea02 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -537,7 +537,9 @@ impl Default for Configuration { ("v2.delete_form".to_owned(), false), ("v2.get_form".to_owned(), false), ("v2.list_forms".to_owned(), false), + ("v2.list_form_versions".to_owned(), false), ("v2.publish_form".to_owned(), false), + ("v2.revert_form_version".to_owned(), false), ("v2.update_form".to_owned(), false), ("v2.upsert_and_publish_form_version".to_owned(), false), ("v2.upsert_form_version".to_owned(), false), diff --git a/src/datadogV2/api/api_forms.rs b/src/datadogV2/api/api_forms.rs index b500a0e68..1daf31144 100644 --- a/src/datadogV2/api/api_forms.rs +++ b/src/datadogV2/api/api_forms.rs @@ -15,12 +15,14 @@ use std::io::Write; #[non_exhaustive] #[derive(Clone, Default, Debug)] pub struct GetFormOptionalParams { - /// The version of the form to retrieve. Use 'latest' for the most recent draft, 'published' for the last published version, or a specific version number. + /// The version of the form to retrieve. Use 'latest' for the most recent draft, 'published' for the + /// last published version, or a specific version number. pub version: Option, } impl GetFormOptionalParams { - /// The version of the form to retrieve. Use 'latest' for the most recent draft, 'published' for the last published version, or a specific version number. + /// The version of the form to retrieve. Use 'latest' for the most recent draft, 'published' for the + /// last published version, or a specific version number. pub fn version(mut self, value: String) -> Self { self.version = Some(value); self @@ -72,6 +74,15 @@ pub enum GetFormError { UnknownValue(serde_json::Value), } +/// ListFormVersionsError is a struct for typed errors of method [`FormsAPI::list_form_versions`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListFormVersionsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// ListFormsError is a struct for typed errors of method [`FormsAPI::list_forms`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -90,6 +101,15 @@ pub enum PublishFormError { UnknownValue(serde_json::Value), } +/// RevertFormVersionError is a struct for typed errors of method [`FormsAPI::revert_form_version`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RevertFormVersionError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// UpdateFormError is a struct for typed errors of method [`FormsAPI::update_form`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -352,7 +372,8 @@ impl FormsAPI { } } - /// Creates a new form and immediately publishes its initial version. This also creates a new datastore for form responses and links it to the form. + /// Creates a new form and immediately publishes its initial version. This also creates a new datastore for + /// form responses and links it to the form. pub async fn create_and_publish_form( &self, body: crate::datadogV2::model::CreateFormRequest, @@ -372,7 +393,8 @@ impl FormsAPI { } } - /// Creates a new form and immediately publishes its initial version. This also creates a new datastore for form responses and links it to the form. + /// Creates a new form and immediately publishes its initial version. This also creates a new datastore for + /// form responses and links it to the form. pub async fn create_and_publish_form_with_http_info( &self, body: crate::datadogV2::model::CreateFormRequest, @@ -511,7 +533,8 @@ impl FormsAPI { } } - /// Create a new form. The form is created in draft mode and must be published before it can be used. This also creates a new datastore for form responses and links it to the form. + /// Create a new form. The form is created in draft mode and must be published before it can be used. This + /// also creates a new datastore for form responses and links it to the form. pub async fn create_form( &self, body: crate::datadogV2::model::CreateFormRequest, @@ -530,7 +553,8 @@ impl FormsAPI { } } - /// Create a new form. The form is created in draft mode and must be published before it can be used. This also creates a new datastore for form responses and links it to the form. + /// Create a new form. The form is created in draft mode and must be published before it can be used. This + /// also creates a new datastore for form responses and links it to the form. pub async fn create_form_with_http_info( &self, body: crate::datadogV2::model::CreateFormRequest, @@ -902,6 +926,123 @@ impl FormsAPI { } } + /// List all versions of a form. + pub async fn list_form_versions( + &self, + form_id: uuid::Uuid, + ) -> Result< + crate::datadogV2::model::ListFormVersionsResponse, + datadog::Error, + > { + match self.list_form_versions_with_http_info(form_id).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// List all versions of a form. + pub async fn list_form_versions_with_http_info( + &self, + form_id: uuid::Uuid, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_form_versions"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.list_form_versions' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/forms/{form_id}/versions", + local_configuration.get_operation_host(operation_id), + form_id = datadog::urlencode(form_id.to_string()) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } + /// Get all forms for the authenticated user's organization. pub async fn list_forms( &self, @@ -1173,6 +1314,128 @@ impl FormsAPI { } } + /// Revert a form to a prior version by creating a new draft version copied from it. + pub async fn revert_form_version( + &self, + form_id: uuid::Uuid, + version: i64, + ) -> Result> + { + match self + .revert_form_version_with_http_info(form_id, version) + .await + { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Revert a form to a prior version by creating a new draft version copied from it. + pub async fn revert_form_version_with_http_info( + &self, + form_id: uuid::Uuid, + version: i64, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.revert_form_version"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.revert_form_version' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/forms/{form_id}/versions/revert", + local_configuration.get_operation_host(operation_id), + form_id = datadog::urlencode(form_id.to_string()) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, local_uri_str.as_str()); + + local_req_builder = local_req_builder.query(&[("version", &version.to_string())]); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } + /// Update a form's properties such as its name, description, or datastore configuration. pub async fn update_form( &self, diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index e84f50498..889345d51 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -4254,6 +4254,14 @@ pub mod model_form_publication_response; pub use self::model_form_publication_response::FormPublicationResponse; pub mod model_form_publication_data; pub use self::model_form_publication_data::FormPublicationData; +pub mod model_list_form_versions_response; +pub use self::model_list_form_versions_response::ListFormVersionsResponse; +pub mod model_list_form_versions_data; +pub use self::model_list_form_versions_data::ListFormVersionsData; +pub mod model_list_form_versions_data_attributes; +pub use self::model_list_form_versions_data_attributes::ListFormVersionsDataAttributes; +pub mod model_form_version_list_type; +pub use self::model_form_version_list_type::FormVersionListType; pub mod model_upsert_form_version_request; pub use self::model_upsert_form_version_request::UpsertFormVersionRequest; pub mod model_upsert_form_version_data; diff --git a/src/datadogV2/model/model_form_data_attributes.rs b/src/datadogV2/model/model_form_data_attributes.rs index bbb155318..1fa585501 100644 --- a/src/datadogV2/model/model_form_data_attributes.rs +++ b/src/datadogV2/model/model_form_data_attributes.rs @@ -33,7 +33,8 @@ pub struct FormDataAttributes { with = "::serde_with::rust::double_option" )] pub end_date: Option>>, - /// Whether the current user has already submitted this form. Only present for forms with `single_response` set to `true`. + /// Whether the current user has already submitted this form. Only present for forms with + /// `single_response` set to `true`. #[serde( rename = "has_submitted", default, diff --git a/src/datadogV2/model/model_form_version_attributes.rs b/src/datadogV2/model/model_form_version_attributes.rs index 1cae8bced..0ed1b150a 100644 --- a/src/datadogV2/model/model_form_version_attributes.rs +++ b/src/datadogV2/model/model_form_version_attributes.rs @@ -24,6 +24,9 @@ pub struct FormVersionAttributes { #[serialize_always] #[serde(rename = "etag")] pub etag: Option, + /// Whether this version number has ever appeared in the form's publication history. + #[serde(rename = "has_ever_been_published")] + pub has_ever_been_published: Option, /// The ID of the form version. #[serde(rename = "id")] pub id: Option, @@ -70,6 +73,7 @@ impl FormVersionAttributes { data_definition, definition_signature, etag, + has_ever_been_published: None, id: None, modified_at, state, @@ -82,6 +86,11 @@ impl FormVersionAttributes { } } + pub fn has_ever_been_published(mut self, value: bool) -> Self { + self.has_ever_been_published = Some(value); + self + } + pub fn id(mut self, value: String) -> Self { self.id = Some(value); self @@ -117,6 +126,7 @@ impl<'de> Deserialize<'de> for FormVersionAttributes { let mut data_definition: Option = None; let mut definition_signature: Option = None; let mut etag: Option> = None; + let mut has_ever_been_published: Option = None; let mut id: Option = None; let mut modified_at: Option> = None; let mut state: Option = None; @@ -146,6 +156,13 @@ impl<'de> Deserialize<'de> for FormVersionAttributes { "etag" => { etag = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } + "has_ever_been_published" => { + if v.is_null() { + continue; + } + has_ever_been_published = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } "id" => { if v.is_null() { continue; @@ -209,6 +226,7 @@ impl<'de> Deserialize<'de> for FormVersionAttributes { data_definition, definition_signature, etag, + has_ever_been_published, id, modified_at, state, diff --git a/src/datadogV2/model/model_form_version_list_type.rs b/src/datadogV2/model/model_form_version_list_type.rs new file mode 100644 index 000000000..cd6af1c89 --- /dev/null +++ b/src/datadogV2/model/model_form_version_list_type.rs @@ -0,0 +1,48 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum FormVersionListType { + FORM_VERSION_LISTS, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for FormVersionListType { + fn to_string(&self) -> String { + match self { + Self::FORM_VERSION_LISTS => String::from("form_version_lists"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for FormVersionListType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for FormVersionListType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "form_version_lists" => Self::FORM_VERSION_LISTS, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_list_form_versions_data.rs b/src/datadogV2/model/model_list_form_versions_data.rs new file mode 100644 index 000000000..8269b3da5 --- /dev/null +++ b/src/datadogV2/model/model_list_form_versions_data.rs @@ -0,0 +1,126 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A list-of-form-versions resource object. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ListFormVersionsData { + /// The attributes for a list of form versions. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::ListFormVersionsDataAttributes, + /// The ID of the form. + #[serde(rename = "id")] + pub id: String, + /// The resource type for a list of form versions. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::FormVersionListType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ListFormVersionsData { + pub fn new( + attributes: crate::datadogV2::model::ListFormVersionsDataAttributes, + id: String, + type_: crate::datadogV2::model::FormVersionListType, + ) -> ListFormVersionsData { + ListFormVersionsData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ListFormVersionsData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ListFormVersionsDataVisitor; + impl<'a> Visitor<'a> for ListFormVersionsDataVisitor { + type Value = ListFormVersionsData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::ListFormVersionsDataAttributes, + > = None; + let mut id: Option = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::FormVersionListType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ListFormVersionsData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ListFormVersionsDataVisitor) + } +} diff --git a/src/datadogV2/model/model_list_form_versions_data_attributes.rs b/src/datadogV2/model/model_list_form_versions_data_attributes.rs new file mode 100644 index 000000000..f8c2bf956 --- /dev/null +++ b/src/datadogV2/model/model_list_form_versions_data_attributes.rs @@ -0,0 +1,95 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes for a list of form versions. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ListFormVersionsDataAttributes { + /// The list of versions for the form. + #[serde(rename = "versions")] + pub versions: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ListFormVersionsDataAttributes { + pub fn new( + versions: Vec, + ) -> ListFormVersionsDataAttributes { + ListFormVersionsDataAttributes { + versions, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ListFormVersionsDataAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ListFormVersionsDataAttributesVisitor; + impl<'a> Visitor<'a> for ListFormVersionsDataAttributesVisitor { + type Value = ListFormVersionsDataAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut versions: Option> = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "versions" => { + versions = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let versions = versions.ok_or_else(|| M::Error::missing_field("versions"))?; + + let content = ListFormVersionsDataAttributes { + versions, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ListFormVersionsDataAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_list_form_versions_response.rs b/src/datadogV2/model/model_list_form_versions_response.rs new file mode 100644 index 000000000..ed547c6fc --- /dev/null +++ b/src/datadogV2/model/model_list_form_versions_response.rs @@ -0,0 +1,92 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A response containing the list of versions for a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ListFormVersionsResponse { + /// A list-of-form-versions resource object. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::ListFormVersionsData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ListFormVersionsResponse { + pub fn new(data: crate::datadogV2::model::ListFormVersionsData) -> ListFormVersionsResponse { + ListFormVersionsResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ListFormVersionsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ListFormVersionsResponseVisitor; + impl<'a> Visitor<'a> for ListFormVersionsResponseVisitor { + type Value = ListFormVersionsResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = ListFormVersionsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ListFormVersionsResponseVisitor) + } +} diff --git a/tests/scenarios/features/v2/forms.feature b/tests/scenarios/features/v2/forms.feature index eb380d0f8..26c3af40d 100644 --- a/tests/scenarios/features/v2/forms.feature +++ b/tests/scenarios/features/v2/forms.feature @@ -143,6 +143,30 @@ Feature: Forms And the response "data.type" is equal to "forms" And the response "data.attributes.name" is equal to "{{ unique }}" + @generated @skip @team:DataDog/app-builder-backend + Scenario: List form versions returns "Bad Request" response + Given operation "ListFormVersions" enabled + And new "ListFormVersions" request + And request contains "form_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/app-builder-backend + Scenario: List form versions returns "Not Found" response + Given operation "ListFormVersions" enabled + And new "ListFormVersions" request + And request contains "form_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/app-builder-backend + Scenario: List form versions returns "OK" response + Given operation "ListFormVersions" enabled + And new "ListFormVersions" request + And request contains "form_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/app-builder-backend Scenario: List forms returns "Bad Request" response Given operation "ListForms" enabled @@ -189,6 +213,42 @@ Feature: Forms When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/app-builder-backend + Scenario: Revert a form to a prior version returns "Bad Request" response + Given operation "RevertFormVersion" enabled + And new "RevertFormVersion" request + And request contains "form_id" parameter from "REPLACE.ME" + And request contains "version" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Revert a form to a prior version returns "Conflict" response + Given operation "RevertFormVersion" enabled + And new "RevertFormVersion" request + And request contains "form_id" parameter from "REPLACE.ME" + And request contains "version" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 409 Conflict + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Revert a form to a prior version returns "Not Found" response + Given operation "RevertFormVersion" enabled + And new "RevertFormVersion" request + And request contains "form_id" parameter from "REPLACE.ME" + And request contains "version" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Revert a form to a prior version returns "OK" response + Given operation "RevertFormVersion" enabled + And new "RevertFormVersion" request + And request contains "form_id" parameter from "REPLACE.ME" + And request contains "version" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/app-builder-backend Scenario: Update a form returns "Bad Request" response Given operation "UpdateForm" enabled diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 10ae8ac71..096337148 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2810,12 +2810,24 @@ "type": "idempotent" } }, + "ListFormVersions": { + "tag": "Forms", + "undo": { + "type": "safe" + } + }, "UpsertFormVersion": { "tag": "Forms", "undo": { "type": "idempotent" } }, + "RevertFormVersion": { + "tag": "Forms", + "undo": { + "type": "unsafe" + } + }, "UpsertAndPublishFormVersion": { "tag": "Forms", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 2edd4714e..84d5fd260 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -4922,9 +4922,15 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { world .function_mappings .insert("v2.PublishForm".into(), test_v2_publish_form); + world + .function_mappings + .insert("v2.ListFormVersions".into(), test_v2_list_form_versions); world .function_mappings .insert("v2.UpsertFormVersion".into(), test_v2_upsert_form_version); + world + .function_mappings + .insert("v2.RevertFormVersion".into(), test_v2_revert_form_version); world.function_mappings.insert( "v2.UpsertAndPublishFormVersion".into(), test_v2_upsert_and_publish_form_version, @@ -37617,6 +37623,31 @@ fn test_v2_publish_form(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_forms + .as_ref() + .expect("api instance not found"); + let form_id = serde_json::from_value(_parameters.get("form_id").unwrap().clone()).unwrap(); + let response = match block_on(api.list_form_versions_with_http_info(form_id)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_upsert_form_version(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances @@ -37643,6 +37674,32 @@ fn test_v2_upsert_form_version(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_forms + .as_ref() + .expect("api instance not found"); + let form_id = serde_json::from_value(_parameters.get("form_id").unwrap().clone()).unwrap(); + let version = serde_json::from_value(_parameters.get("version").unwrap().clone()).unwrap(); + let response = match block_on(api.revert_form_version_with_http_info(form_id, version)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_upsert_and_publish_form_version( world: &mut DatadogWorld, _parameters: &HashMap,