diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 2d470c8f2f..a50a7d5077 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -23241,6 +23241,60 @@ components: required: - data type: object + CreateFormData: + description: The data for creating a form. + properties: + attributes: + $ref: "#/components/schemas/CreateFormDataAttributes" + type: + $ref: "#/components/schemas/FormType" + required: + - attributes + - type + type: object + CreateFormDataAttributes: + description: The attributes for creating a form. + properties: + anonymous: + default: false + description: Whether the form accepts anonymous submissions. + example: false + type: boolean + data_definition: + $ref: "#/components/schemas/FormDataDefinition" + description: + description: The description of the form. + example: A form to collect user feedback. + type: string + idp_survey: + default: false + description: Whether the form is an IDP survey. + example: false + type: boolean + name: + description: The name of the form. + example: User Feedback Form + type: string + single_response: + default: false + description: Whether each user can only submit one response. + example: false + type: boolean + ui_definition: + $ref: "#/components/schemas/FormUiDefinition" + required: + - data_definition + - name + - ui_definition + type: object + CreateFormRequest: + description: A request to create a form. + properties: + data: + $ref: "#/components/schemas/CreateFormData" + required: + - data + type: object CreateIncidentNotificationRuleRequest: description: Create request for a notification rule. properties: @@ -29056,6 +29110,26 @@ components: required: - data type: object + DeleteFormData: + description: The data returned when a form is deleted. + properties: + id: + description: The ID of the deleted form. + example: 844dfd88-aa84-4db4-8979-e7bdbb9c1dc3 + format: uuid + type: string + type: + $ref: "#/components/schemas/FormType" + required: + - id + - type + type: object + DeleteFormResponse: + description: A response returned after deleting a form. + properties: + data: + $ref: "#/components/schemas/DeleteFormData" + type: object DeletedSuiteResponseData: description: Data object for a deleted Synthetic test suite. properties: @@ -36762,6 +36836,233 @@ components: - type - attributes type: object + FormData: + description: A form resource object. + properties: + attributes: + $ref: "#/components/schemas/FormDataAttributes" + id: + description: The ID of the form. + example: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + format: uuid + type: string + type: + $ref: "#/components/schemas/FormType" + required: + - id + - type + - attributes + type: object + FormDataAttributes: + description: The attributes of a form. + properties: + active: + description: Whether the form is currently active. + example: true + type: boolean + anonymous: + description: Whether the form accepts anonymous submissions. + example: false + type: boolean + created_at: + description: The time at which the form was created. + example: "2026-05-29T20:06:13.677353Z" + format: date-time + type: string + datastore_config: + $ref: "#/components/schemas/FormDatastoreConfigAttributes" + description: + description: The description of the form. + example: A form to collect user feedback. + type: string + end_date: + description: The date and time at which the form stops accepting responses. + example: + format: date-time + 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`. + nullable: true + type: boolean + idp_survey: + description: Whether the form is an IDP survey. + example: false + type: boolean + modified_at: + description: The time at which the form was last modified. + example: "2026-05-29T20:06:13.677353Z" + format: date-time + type: string + name: + description: The name of the form. + example: User Feedback Form + type: string + org_id: + description: The ID of the organization that owns this form. + example: 2 + format: int64 + type: integer + publication: + $ref: "#/components/schemas/FormPublicationAttributes" + self_service: + description: Whether the form is available in the self-service catalog. + example: false + type: boolean + single_response: + description: Whether each user can only submit one response. + example: false + type: boolean + user_id: + description: The ID of the user who created this form. + example: 10001 + format: int64 + type: integer + user_uuid: + description: The UUID of the user who created this form. + example: 1fc709aa-be19-4539-a47d-52a30d78a978 + format: uuid + type: string + version: + $ref: "#/components/schemas/FormVersionAttributes" + required: + - active + - anonymous + - created_at + - datastore_config + - description + - idp_survey + - modified_at + - name + - org_id + - self_service + - single_response + - user_id + - user_uuid + type: object + FormDataDefinition: + additionalProperties: {} + description: A JSON Schema definition that describes the form's data fields. + properties: + description: + description: A description shown to form respondents. + example: Welcome to the Engineering Experience Survey. + type: string + properties: + additionalProperties: {} + description: A map of field names to their JSON Schema definitions. + type: object + required: + description: List of field names that must be answered. + items: + type: string + type: array + title: + description: The title of the form schema. + example: Developer Experience Survey + type: string + type: + $ref: "#/components/schemas/FormDataDefinitionType" + type: object + FormDataDefinitionType: + default: object + description: The root schema type. + enum: + - object + type: string + x-enum-varnames: + - OBJECT + FormDataList: + description: A list of form resource objects. + items: + $ref: "#/components/schemas/FormData" + type: array + FormDatastoreConfigAttributes: + description: The datastore configuration for a form. + properties: + datastore_id: + description: The ID of the datastore. + example: 5108ea24-dd83-4696-9caa-f069f73d0fad + format: uuid + type: string + primary_column_name: + description: The name of the primary column in the datastore. + example: id + type: string + primary_key_generation_strategy: + description: The strategy used to generate primary keys in the datastore. + example: none + type: string + required: + - datastore_id + - primary_column_name + - primary_key_generation_strategy + type: object + FormPublicationAttributes: + description: The attributes of a form publication. + properties: + created_at: + description: The time at which the publication was created. + example: "2026-05-29T20:06:13.677353Z" + format: date-time + type: string + form_id: + description: The ID of the form. + example: afc67600-0511-43b1-9b18-578fb4979bd3 + format: uuid + type: string + form_version: + description: The version number that was published. + example: 1 + format: int64 + type: integer + id: + description: The ID of the form publication. + example: "42" + type: string + modified_at: + description: The time at which the publication was last modified. + example: "2026-05-29T20:06:13.677353Z" + format: date-time + type: string + org_id: + description: The ID of the organization that owns this publication. + example: 2 + format: int64 + type: integer + publish_seq: + description: The sequential publication number for this form. + example: 1 + format: int64 + type: integer + user_id: + description: The ID of the user who created this publication. + example: 10001 + format: int64 + type: integer + user_uuid: + description: The UUID of the user who created this publication. + example: 1fc709aa-be19-4539-a47d-52a30d78a978 + format: uuid + type: string + required: + - created_at + - form_id + - form_version + - modified_at + - org_id + - publish_seq + - user_id + - user_uuid + type: object + FormResponse: + description: A response containing a single form. + properties: + data: + $ref: "#/components/schemas/FormData" + required: + - data + type: object FormTrigger: description: "Trigger a workflow from a Form." properties: @@ -36780,6 +37081,133 @@ components: required: - formTrigger type: object + FormType: + default: forms + description: The resource type for a form. + enum: + - forms + example: forms + type: string + x-enum-varnames: + - FORMS + FormUiDefinition: + additionalProperties: {} + description: UI configuration for rendering form fields, including widget overrides, field ordering, and themes. + properties: + "ui:order": + description: The order in which form fields are displayed. + items: + type: string + type: array + "ui:theme": + $ref: "#/components/schemas/FormUiDefinitionUiTheme" + type: object + FormUiDefinitionUiTheme: + description: The visual theme applied to the form. + properties: + primaryColor: + $ref: "#/components/schemas/FormUiDefinitionUiThemePrimaryColor" + type: object + FormUiDefinitionUiThemePrimaryColor: + description: The primary color of the form theme. + enum: + - gray + - red + - orange + - yellow + - green + - light-blue + - dark-blue + - magenta + - indigo + type: string + x-enum-varnames: + - GRAY + - RED + - ORANGE + - YELLOW + - GREEN + - LIGHT_BLUE + - DARK_BLUE + - MAGENTA + - INDIGO + FormVersionAttributes: + description: The attributes of a form version. + properties: + created_at: + description: The time at which the version was created. + example: "2026-05-29T20:06:14.895921Z" + format: date-time + type: string + data_definition: + $ref: "#/components/schemas/FormDataDefinition" + definition_signature: + description: The signature of the version definition. + example: '{"signature":"b7f312957a80cea2c8c9950532b205a90a3f8a7ebb7e52fc25437a25d903d545","version":1}' + type: string + etag: + description: The ETag for optimistic concurrency control. + example: b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d + nullable: true + type: string + id: + description: The ID of the form version. + example: "126" + type: string + modified_at: + description: The time at which the version was last modified. + example: "2026-05-29T20:06:14.949163Z" + format: date-time + type: string + state: + $ref: "#/components/schemas/FormVersionState" + ui_definition: + $ref: "#/components/schemas/FormUiDefinition" + user_id: + description: The ID of the user who created this version. + example: 10001 + format: int64 + type: integer + user_uuid: + description: The UUID of the user who created this version. + example: 1fc709aa-be19-4539-a47d-52a30d78a978 + format: uuid + type: string + version: + description: The sequential version number. + example: 1 + format: int64 + type: integer + required: + - created_at + - data_definition + - definition_signature + - etag + - modified_at + - state + - ui_definition + - user_id + - user_uuid + - version + type: object + FormVersionState: + description: The state of a form version. + enum: + - draft + - frozen + example: frozen + type: string + x-enum-varnames: + - DRAFT + - FROZEN + FormsResponse: + description: A response containing a list of forms. + properties: + data: + $ref: "#/components/schemas/FormDataList" + required: + - data + type: object FormulaLimit: description: |- Message for specifying limits to the number of values returned by a query. @@ -125241,6 +125669,330 @@ paths: permissions: - feature_flag_config_write - feature_flag_environment_config_read + /api/v2/forms: + get: + description: Get all forms for the authenticated user's organization. + operationId: ListForms + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + active: true + anonymous: false + created_at: "2026-05-29T20:06:14.895284Z" + datastore_config: + datastore_id: 00000000-0000-0000-0000-000000000000 + primary_column_name: "" + primary_key_generation_strategy: "" + description: A form to collect user feedback. + end_date: + idp_survey: false + modified_at: "2026-05-29T20:06:14.895285Z" + name: User Feedback Form + org_id: 2 + self_service: false + single_response: false + user_id: 10001 + user_uuid: 1fc709aa-be19-4539-a47d-52a30d78a978 + id: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + type: forms + schema: + $ref: "#/components/schemas/FormsResponse" + 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 + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: List forms + 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 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: + application/json: + examples: + default: + value: + data: + attributes: + anonymous: false + data_definition: {} + description: A form to collect user feedback. + idp_survey: false + name: User Feedback Form + single_response: false + ui_definition: {} + type: forms + schema: + $ref: "#/components/schemas/CreateFormRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + active: true + anonymous: false + created_at: "2026-05-29T20:06:14.895284Z" + datastore_config: + datastore_id: 5108ea24-dd83-4696-9caa-f069f73d0fad + primary_column_name: id + primary_key_generation_strategy: none + description: A form to collect user feedback. + end_date: + idp_survey: false + modified_at: "2026-05-29T20:06:14.895285Z" + name: User Feedback Form + org_id: 2 + self_service: false + single_response: false + user_id: 10001 + user_uuid: 1fc709aa-be19-4539-a47d-52a30d78a978 + id: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + type: forms + schema: + $ref: "#/components/schemas/FormResponse" + 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 + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Create a form + 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/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. + operationId: CreateAndPublishForm + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + anonymous: false + data_definition: {} + description: A form to collect user feedback. + idp_survey: false + name: User Feedback Form + single_response: false + ui_definition: {} + type: forms + schema: + $ref: "#/components/schemas/CreateFormRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + active: true + anonymous: false + created_at: "2026-05-29T20:06:14.895284Z" + datastore_config: + datastore_id: 5108ea24-dd83-4696-9caa-f069f73d0fad + primary_column_name: id + primary_key_generation_strategy: none + description: A form to collect user feedback. + end_date: + idp_survey: false + modified_at: "2026-05-29T20:06:14.895285Z" + name: User Feedback Form + org_id: 2 + self_service: false + single_response: false + user_id: 10001 + user_uuid: 1fc709aa-be19-4539-a47d-52a30d78a978 + id: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + type: forms + schema: + $ref: "#/components/schemas/FormResponse" + 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 + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Create and publish a form + 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}: + delete: + description: Delete a form by its ID. This will also try to delete the associated datastore. + operationId: DeleteForm + parameters: + - description: The ID of the form. + example: 844dfd88-aa84-4db4-8979-e7bdbb9c1dc3 + in: path + name: form_id + required: true + schema: + format: uuid + type: string + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + id: 844dfd88-aa84-4db4-8979-e7bdbb9c1dc3 + type: forms + schema: + $ref: "#/components/schemas/DeleteFormResponse" + 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 + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Delete a form + 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/). + get: + description: Get a form definition by its ID. + operationId: GetForm + 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 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 + schema: + default: latest + type: string + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + active: true + anonymous: false + created_at: "2026-05-29T20:06:14.895284Z" + datastore_config: + datastore_id: 5108ea24-dd83-4696-9caa-f069f73d0fad + primary_column_name: id + primary_key_generation_strategy: none + description: A form to collect user feedback. + end_date: + idp_survey: false + modified_at: "2026-05-29T20:06:14.895285Z" + name: User Feedback Form + org_id: 2 + self_service: false + single_response: false + user_id: 10001 + user_uuid: 1fc709aa-be19-4539-a47d-52a30d78a978 + id: 22f6006a-2302-4926-9396-d2dfcf7b0b34 + type: forms + schema: + $ref: "#/components/schemas/FormResponse" + 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: Get a form + 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/hamr: get: description: |- @@ -181249,6 +182001,9 @@ tags: Package Upgrade Deployments (`/upgrade`): - Upgrade the Datadog Agent to specific versions name: Fleet Automation + - description: |- + The Datadog Forms API lets you create and manage forms within the App Builder platform. You can configure form settings, manage versions, publish forms, and handle sharing configurations. + name: Forms - description: |- Configure your Datadog-Google Cloud Platform (GCP) integration directly through the Datadog API. Read more about the [Datadog-Google Cloud Platform integration](https://docs.datadoghq.com/integrations/google_cloud_platform). diff --git a/examples/v2_forms_CreateAndPublishForm.rs b/examples/v2_forms_CreateAndPublishForm.rs new file mode 100644 index 0000000000..aa264a2d4e --- /dev/null +++ b/examples/v2_forms_CreateAndPublishForm.rs @@ -0,0 +1,34 @@ +// Create and publish a form returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; +use datadog_api_client::datadogV2::model::CreateFormData; +use datadog_api_client::datadogV2::model::CreateFormDataAttributes; +use datadog_api_client::datadogV2::model::CreateFormRequest; +use datadog_api_client::datadogV2::model::FormDataDefinition; +use datadog_api_client::datadogV2::model::FormType; +use datadog_api_client::datadogV2::model::FormUiDefinition; + +#[tokio::main] +async fn main() { + let body = CreateFormRequest::new(CreateFormData::new( + CreateFormDataAttributes::new( + FormDataDefinition::new(), + "User Feedback Form".to_string(), + FormUiDefinition::new(), + ) + .anonymous(false) + .description("A form to collect user feedback.".to_string()) + .idp_survey(false) + .single_response(false), + FormType::FORMS, + )); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.CreateAndPublishForm", true); + let api = FormsAPI::with_config(configuration); + let resp = api.create_and_publish_form(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_forms_CreateForm.rs b/examples/v2_forms_CreateForm.rs new file mode 100644 index 0000000000..868672f54d --- /dev/null +++ b/examples/v2_forms_CreateForm.rs @@ -0,0 +1,34 @@ +// Create a form returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; +use datadog_api_client::datadogV2::model::CreateFormData; +use datadog_api_client::datadogV2::model::CreateFormDataAttributes; +use datadog_api_client::datadogV2::model::CreateFormRequest; +use datadog_api_client::datadogV2::model::FormDataDefinition; +use datadog_api_client::datadogV2::model::FormType; +use datadog_api_client::datadogV2::model::FormUiDefinition; + +#[tokio::main] +async fn main() { + let body = CreateFormRequest::new(CreateFormData::new( + CreateFormDataAttributes::new( + FormDataDefinition::new(), + "User Feedback Form".to_string(), + FormUiDefinition::new(), + ) + .anonymous(false) + .description("A form to collect user feedback.".to_string()) + .idp_survey(false) + .single_response(false), + FormType::FORMS, + )); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.CreateForm", true); + let api = FormsAPI::with_config(configuration); + let resp = api.create_form(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_forms_DeleteForm.rs b/examples/v2_forms_DeleteForm.rs new file mode 100644 index 0000000000..e7bc76535f --- /dev/null +++ b/examples/v2_forms_DeleteForm.rs @@ -0,0 +1,19 @@ +// Delete a form returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; + +#[tokio::main] +async fn main() { + // there is a valid "form" in the system + let form_data_id = + uuid::Uuid::parse_str(&std::env::var("FORM_DATA_ID").unwrap()).expect("Invalid UUID"); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.DeleteForm", true); + let api = FormsAPI::with_config(configuration); + let resp = api.delete_form(form_data_id.clone()).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_forms_GetForm.rs b/examples/v2_forms_GetForm.rs new file mode 100644 index 0000000000..006707b9a3 --- /dev/null +++ b/examples/v2_forms_GetForm.rs @@ -0,0 +1,22 @@ +// Get a form returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; +use datadog_api_client::datadogV2::api_forms::GetFormOptionalParams; + +#[tokio::main] +async fn main() { + // there is a valid "form" in the system + let form_data_id = + uuid::Uuid::parse_str(&std::env::var("FORM_DATA_ID").unwrap()).expect("Invalid UUID"); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetForm", true); + let api = FormsAPI::with_config(configuration); + let resp = api + .get_form(form_data_id.clone(), GetFormOptionalParams::default()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_forms_ListForms.rs b/examples/v2_forms_ListForms.rs new file mode 100644 index 0000000000..1cb0ffd59d --- /dev/null +++ b/examples/v2_forms_ListForms.rs @@ -0,0 +1,16 @@ +// List forms returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_forms::FormsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListForms", true); + let api = FormsAPI::with_config(configuration); + let resp = api.list_forms().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 77317e5213..5a8e2ea7c6 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -449,6 +449,11 @@ impl Default for Configuration { ("v2.trigger_deployment_gates_evaluation".to_owned(), false), ("v2.update_deployment_gate".to_owned(), false), ("v2.update_deployment_rule".to_owned(), false), + ("v2.create_and_publish_form".to_owned(), false), + ("v2.create_form".to_owned(), false), + ("v2.delete_form".to_owned(), false), + ("v2.get_form".to_owned(), false), + ("v2.list_forms".to_owned(), false), ("v2.create_hamr_org_connection".to_owned(), false), ("v2.get_hamr_org_connection".to_owned(), false), ("v2.delete_entity_integration_config".to_owned(), false), diff --git a/src/datadogV2/api/api_forms.rs b/src/datadogV2/api/api_forms.rs new file mode 100644 index 0000000000..4fa7d8a1c2 --- /dev/null +++ b/src/datadogV2/api/api_forms.rs @@ -0,0 +1,806 @@ +// 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 crate::datadog; +use flate2::{ + write::{GzEncoder, ZlibEncoder}, + Compression, +}; +use log::warn; +use reqwest::header::{HeaderMap, HeaderValue}; +use serde::{Deserialize, Serialize}; +use std::io::Write; + +/// GetFormOptionalParams is a struct for passing parameters to the method [`FormsAPI::get_form`] +#[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. + 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. + pub fn version(mut self, value: String) -> Self { + self.version = Some(value); + self + } +} + +/// CreateAndPublishFormError is a struct for typed errors of method [`FormsAPI::create_and_publish_form`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateAndPublishFormError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// CreateFormError is a struct for typed errors of method [`FormsAPI::create_form`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateFormError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// DeleteFormError is a struct for typed errors of method [`FormsAPI::delete_form`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteFormError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetFormError is a struct for typed errors of method [`FormsAPI::get_form`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetFormError { + 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)] +pub enum ListFormsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// The Datadog Forms API lets you create and manage forms within the App Builder platform. You can configure form settings, manage versions, publish forms, and handle sharing configurations. +#[derive(Debug, Clone)] +pub struct FormsAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for FormsAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl FormsAPI { + pub fn new() -> Self { + Self::default() + } + pub fn with_config(config: datadog::Configuration) -> Self { + let reqwest_client_builder = { + let builder = reqwest::Client::builder(); + #[cfg(not(target_arch = "wasm32"))] + let builder = if let Some(proxy_url) = &config.proxy_url { + builder.proxy(reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL")) + } else { + builder + }; + builder + }; + + let middleware_client_builder = { + let builder = + reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap()); + #[cfg(feature = "retry")] + let builder = if config.enable_retry { + struct RetryableStatus; + impl reqwest_retry::RetryableStrategy for RetryableStatus { + fn handle( + &self, + res: &Result, + ) -> Option { + match res { + Ok(success) => reqwest_retry::default_on_request_success(success), + Err(_) => None, + } + } + } + let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder() + .build_with_max_retries(config.max_retries); + + let retry_middleware = + reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy( + backoff_policy, + RetryableStatus, + ); + + builder.with(retry_middleware) + } else { + builder + }; + builder + }; + + let client = middleware_client_builder.build(); + + Self { config, client } + } + + pub fn with_client_and_config( + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, + ) -> Self { + Self { config, client } + } + + /// 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, + ) -> Result> + { + match self.create_and_publish_form_with_http_info(body).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), + } + } + + /// 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, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_and_publish_form"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.create_and_publish_form' 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/create_and_publish", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + 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"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + #[cfg(feature = "zstd")] + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + 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)) + } + } + + /// 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, + ) -> Result> { + match self.create_form_with_http_info(body).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), + } + } + + /// 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, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_form"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.create_form' 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", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + 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"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + #[cfg(feature = "zstd")] + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + 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)) + } + } + + /// Delete a form by its ID. This will also try to delete the associated datastore. + pub async fn delete_form( + &self, + form_id: uuid::Uuid, + ) -> Result> { + match self.delete_form_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), + } + } + + /// Delete a form by its ID. This will also try to delete the associated datastore. + pub async fn delete_form_with_http_info( + &self, + form_id: uuid::Uuid, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.delete_form"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.delete_form' 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}", + 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::DELETE, 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 a form definition by its ID. + pub async fn get_form( + &self, + form_id: uuid::Uuid, + params: GetFormOptionalParams, + ) -> Result> { + match self.get_form_with_http_info(form_id, params).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), + } + } + + /// Get a form definition by its ID. + pub async fn get_form_with_http_info( + &self, + form_id: uuid::Uuid, + params: GetFormOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_form"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.get_form' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let version = params.version; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/forms/{form_id}", + 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()); + + if let Some(ref local_query_param) = version { + local_req_builder = + local_req_builder.query(&[("version", &local_query_param.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)) + } + } + + /// Get all forms for the authenticated user's organization. + pub async fn list_forms( + &self, + ) -> Result> { + match self.list_forms_with_http_info().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), + } + } + + /// Get all forms for the authenticated user's organization. + pub async fn list_forms_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_forms"; + 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_forms' 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", + local_configuration.get_operation_host(operation_id) + ); + 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)) + } + } +} diff --git a/src/datadogV2/api/mod.rs b/src/datadogV2/api/mod.rs index 95caad2d55..eaac19f2ed 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -52,6 +52,7 @@ pub mod api_events; pub mod api_fastly_integration; pub mod api_feature_flags; pub mod api_fleet_automation; +pub mod api_forms; pub mod api_gcp_integration; pub mod api_google_chat_integration; pub mod api_high_availability_multi_region; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index 86e3734f4b..60fbc391da 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -53,6 +53,7 @@ pub use self::api::api_events; pub use self::api::api_fastly_integration; pub use self::api::api_feature_flags; pub use self::api::api_fleet_automation; +pub use self::api::api_forms; pub use self::api::api_gcp_integration; pub use self::api::api_google_chat_integration; pub use self::api::api_high_availability_multi_region; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index dc9baf5f5c..fbd044b92d 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -3922,6 +3922,44 @@ pub mod model_overwrite_allocations_request; pub use self::model_overwrite_allocations_request::OverwriteAllocationsRequest; pub mod model_list_allocations_response; pub use self::model_list_allocations_response::ListAllocationsResponse; +pub mod model_forms_response; +pub use self::model_forms_response::FormsResponse; +pub mod model_form_data; +pub use self::model_form_data::FormData; +pub mod model_form_data_attributes; +pub use self::model_form_data_attributes::FormDataAttributes; +pub mod model_form_datastore_config_attributes; +pub use self::model_form_datastore_config_attributes::FormDatastoreConfigAttributes; +pub mod model_form_publication_attributes; +pub use self::model_form_publication_attributes::FormPublicationAttributes; +pub mod model_form_version_attributes; +pub use self::model_form_version_attributes::FormVersionAttributes; +pub mod model_form_data_definition; +pub use self::model_form_data_definition::FormDataDefinition; +pub mod model_form_data_definition_type; +pub use self::model_form_data_definition_type::FormDataDefinitionType; +pub mod model_form_version_state; +pub use self::model_form_version_state::FormVersionState; +pub mod model_form_ui_definition; +pub use self::model_form_ui_definition::FormUiDefinition; +pub mod model_form_ui_definition_ui_theme; +pub use self::model_form_ui_definition_ui_theme::FormUiDefinitionUiTheme; +pub mod model_form_ui_definition_ui_theme_primary_color; +pub use self::model_form_ui_definition_ui_theme_primary_color::FormUiDefinitionUiThemePrimaryColor; +pub mod model_form_type; +pub use self::model_form_type::FormType; +pub mod model_create_form_request; +pub use self::model_create_form_request::CreateFormRequest; +pub mod model_create_form_data; +pub use self::model_create_form_data::CreateFormData; +pub mod model_create_form_data_attributes; +pub use self::model_create_form_data_attributes::CreateFormDataAttributes; +pub mod model_form_response; +pub use self::model_form_response::FormResponse; +pub mod model_delete_form_response; +pub use self::model_delete_form_response::DeleteFormResponse; +pub mod model_delete_form_data; +pub use self::model_delete_form_data::DeleteFormData; pub mod model_hamr_org_connection_response; pub use self::model_hamr_org_connection_response::HamrOrgConnectionResponse; pub mod model_hamr_org_connection_data_response; diff --git a/src/datadogV2/model/model_create_form_data.rs b/src/datadogV2/model/model_create_form_data.rs new file mode 100644 index 0000000000..5eaae93573 --- /dev/null +++ b/src/datadogV2/model/model_create_form_data.rs @@ -0,0 +1,114 @@ +// 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 data for creating a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct CreateFormData { + /// The attributes for creating a form. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::CreateFormDataAttributes, + /// The resource type for a form. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::FormType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl CreateFormData { + pub fn new( + attributes: crate::datadogV2::model::CreateFormDataAttributes, + type_: crate::datadogV2::model::FormType, + ) -> CreateFormData { + CreateFormData { + attributes, + 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 CreateFormData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct CreateFormDataVisitor; + impl<'a> Visitor<'a> for CreateFormDataVisitor { + type Value = CreateFormData; + + 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 = + 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)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::FormType::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 type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = CreateFormData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(CreateFormDataVisitor) + } +} diff --git a/src/datadogV2/model/model_create_form_data_attributes.rs b/src/datadogV2/model/model_create_form_data_attributes.rs new file mode 100644 index 0000000000..6cbb946b9d --- /dev/null +++ b/src/datadogV2/model/model_create_form_data_attributes.rs @@ -0,0 +1,190 @@ +// 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 creating a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct CreateFormDataAttributes { + /// Whether the form accepts anonymous submissions. + #[serde(rename = "anonymous")] + pub anonymous: Option, + /// A JSON Schema definition that describes the form's data fields. + #[serde(rename = "data_definition")] + pub data_definition: crate::datadogV2::model::FormDataDefinition, + /// The description of the form. + #[serde(rename = "description")] + pub description: Option, + /// Whether the form is an IDP survey. + #[serde(rename = "idp_survey")] + pub idp_survey: Option, + /// The name of the form. + #[serde(rename = "name")] + pub name: String, + /// Whether each user can only submit one response. + #[serde(rename = "single_response")] + pub single_response: Option, + /// UI configuration for rendering form fields, including widget overrides, field ordering, and themes. + #[serde(rename = "ui_definition")] + pub ui_definition: crate::datadogV2::model::FormUiDefinition, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl CreateFormDataAttributes { + pub fn new( + data_definition: crate::datadogV2::model::FormDataDefinition, + name: String, + ui_definition: crate::datadogV2::model::FormUiDefinition, + ) -> CreateFormDataAttributes { + CreateFormDataAttributes { + anonymous: None, + data_definition, + description: None, + idp_survey: None, + name, + single_response: None, + ui_definition, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn anonymous(mut self, value: bool) -> Self { + self.anonymous = Some(value); + self + } + + pub fn description(mut self, value: String) -> Self { + self.description = Some(value); + self + } + + pub fn idp_survey(mut self, value: bool) -> Self { + self.idp_survey = Some(value); + self + } + + pub fn single_response(mut self, value: bool) -> Self { + self.single_response = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for CreateFormDataAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct CreateFormDataAttributesVisitor; + impl<'a> Visitor<'a> for CreateFormDataAttributesVisitor { + type Value = CreateFormDataAttributes; + + 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 anonymous: Option = None; + let mut data_definition: Option = None; + let mut description: Option = None; + let mut idp_survey: Option = None; + let mut name: Option = None; + let mut single_response: Option = None; + let mut ui_definition: 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() { + "anonymous" => { + if v.is_null() { + continue; + } + anonymous = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "data_definition" => { + data_definition = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "description" => { + if v.is_null() { + continue; + } + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "idp_survey" => { + if v.is_null() { + continue; + } + idp_survey = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "name" => { + name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "single_response" => { + if v.is_null() { + continue; + } + single_response = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "ui_definition" => { + ui_definition = + 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_definition = + data_definition.ok_or_else(|| M::Error::missing_field("data_definition"))?; + let name = name.ok_or_else(|| M::Error::missing_field("name"))?; + let ui_definition = + ui_definition.ok_or_else(|| M::Error::missing_field("ui_definition"))?; + + let content = CreateFormDataAttributes { + anonymous, + data_definition, + description, + idp_survey, + name, + single_response, + ui_definition, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(CreateFormDataAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_create_form_request.rs b/src/datadogV2/model/model_create_form_request.rs new file mode 100644 index 0000000000..5c97c1b0f0 --- /dev/null +++ b/src/datadogV2/model/model_create_form_request.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 request to create a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct CreateFormRequest { + /// The data for creating a form. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::CreateFormData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl CreateFormRequest { + pub fn new(data: crate::datadogV2::model::CreateFormData) -> CreateFormRequest { + CreateFormRequest { + 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 CreateFormRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct CreateFormRequestVisitor; + impl<'a> Visitor<'a> for CreateFormRequestVisitor { + type Value = CreateFormRequest; + + 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 = CreateFormRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(CreateFormRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_delete_form_data.rs b/src/datadogV2/model/model_delete_form_data.rs new file mode 100644 index 0000000000..119e776570 --- /dev/null +++ b/src/datadogV2/model/model_delete_form_data.rs @@ -0,0 +1,110 @@ +// 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 data returned when a form is deleted. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DeleteFormData { + /// The ID of the deleted form. + #[serde(rename = "id")] + pub id: uuid::Uuid, + /// The resource type for a form. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::FormType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DeleteFormData { + pub fn new(id: uuid::Uuid, type_: crate::datadogV2::model::FormType) -> DeleteFormData { + DeleteFormData { + 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 DeleteFormData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DeleteFormDataVisitor; + impl<'a> Visitor<'a> for DeleteFormDataVisitor { + type Value = DeleteFormData; + + 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 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() { + "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::FormType::UnparsedObject(_type_) => { + _unparsed = true; + } + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = DeleteFormData { + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DeleteFormDataVisitor) + } +} diff --git a/src/datadogV2/model/model_delete_form_response.rs b/src/datadogV2/model/model_delete_form_response.rs new file mode 100644 index 0000000000..0dab7a1b1a --- /dev/null +++ b/src/datadogV2/model/model_delete_form_response.rs @@ -0,0 +1,105 @@ +// 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 returned after deleting a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DeleteFormResponse { + /// The data returned when a form is deleted. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DeleteFormResponse { + pub fn new() -> DeleteFormResponse { + DeleteFormResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::DeleteFormData) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for DeleteFormResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DeleteFormResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DeleteFormResponseVisitor; + impl<'a> Visitor<'a> for DeleteFormResponseVisitor { + type Value = DeleteFormResponse; + + 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" => { + if v.is_null() { + continue; + } + 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 content = DeleteFormResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DeleteFormResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_form_data.rs b/src/datadogV2/model/model_form_data.rs new file mode 100644 index 0000000000..3357f77ab7 --- /dev/null +++ b/src/datadogV2/model/model_form_data.rs @@ -0,0 +1,124 @@ +// 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 form resource object. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormData { + /// The attributes of a form. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::FormDataAttributes, + /// The ID of the form. + #[serde(rename = "id")] + pub id: uuid::Uuid, + /// The resource type for a form. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::FormType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormData { + pub fn new( + attributes: crate::datadogV2::model::FormDataAttributes, + id: uuid::Uuid, + type_: crate::datadogV2::model::FormType, + ) -> FormData { + FormData { + 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 FormData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormDataVisitor; + impl<'a> Visitor<'a> for FormDataVisitor { + type Value = FormData; + + 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 = 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::FormType::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 = FormData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormDataVisitor) + } +} diff --git a/src/datadogV2/model/model_form_data_attributes.rs b/src/datadogV2/model/model_form_data_attributes.rs new file mode 100644 index 0000000000..bbb1553189 --- /dev/null +++ b/src/datadogV2/model/model_form_data_attributes.rs @@ -0,0 +1,314 @@ +// 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 of a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormDataAttributes { + /// Whether the form is currently active. + #[serde(rename = "active")] + pub active: bool, + /// Whether the form accepts anonymous submissions. + #[serde(rename = "anonymous")] + pub anonymous: bool, + /// The time at which the form was created. + #[serde(rename = "created_at")] + pub created_at: chrono::DateTime, + /// The datastore configuration for a form. + #[serde(rename = "datastore_config")] + pub datastore_config: crate::datadogV2::model::FormDatastoreConfigAttributes, + /// The description of the form. + #[serde(rename = "description")] + pub description: String, + /// The date and time at which the form stops accepting responses. + #[serde( + rename = "end_date", + default, + 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`. + #[serde( + rename = "has_submitted", + default, + with = "::serde_with::rust::double_option" + )] + pub has_submitted: Option>, + /// Whether the form is an IDP survey. + #[serde(rename = "idp_survey")] + pub idp_survey: bool, + /// The time at which the form was last modified. + #[serde(rename = "modified_at")] + pub modified_at: chrono::DateTime, + /// The name of the form. + #[serde(rename = "name")] + pub name: String, + /// The ID of the organization that owns this form. + #[serde(rename = "org_id")] + pub org_id: i64, + /// The attributes of a form publication. + #[serde(rename = "publication")] + pub publication: Option, + /// Whether the form is available in the self-service catalog. + #[serde(rename = "self_service")] + pub self_service: bool, + /// Whether each user can only submit one response. + #[serde(rename = "single_response")] + pub single_response: bool, + /// The ID of the user who created this form. + #[serde(rename = "user_id")] + pub user_id: i64, + /// The UUID of the user who created this form. + #[serde(rename = "user_uuid")] + pub user_uuid: uuid::Uuid, + /// The attributes of a form version. + #[serde(rename = "version")] + pub version: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormDataAttributes { + pub fn new( + active: bool, + anonymous: bool, + created_at: chrono::DateTime, + datastore_config: crate::datadogV2::model::FormDatastoreConfigAttributes, + description: String, + idp_survey: bool, + modified_at: chrono::DateTime, + name: String, + org_id: i64, + self_service: bool, + single_response: bool, + user_id: i64, + user_uuid: uuid::Uuid, + ) -> FormDataAttributes { + FormDataAttributes { + active, + anonymous, + created_at, + datastore_config, + description, + end_date: None, + has_submitted: None, + idp_survey, + modified_at, + name, + org_id, + publication: None, + self_service, + single_response, + user_id, + user_uuid, + version: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn end_date(mut self, value: Option>) -> Self { + self.end_date = Some(value); + self + } + + pub fn has_submitted(mut self, value: Option) -> Self { + self.has_submitted = Some(value); + self + } + + pub fn publication( + mut self, + value: crate::datadogV2::model::FormPublicationAttributes, + ) -> Self { + self.publication = Some(value); + self + } + + pub fn version(mut self, value: crate::datadogV2::model::FormVersionAttributes) -> Self { + self.version = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for FormDataAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormDataAttributesVisitor; + impl<'a> Visitor<'a> for FormDataAttributesVisitor { + type Value = FormDataAttributes; + + 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 active: Option = None; + let mut anonymous: Option = None; + let mut created_at: Option> = None; + let mut datastore_config: Option< + crate::datadogV2::model::FormDatastoreConfigAttributes, + > = None; + let mut description: Option = None; + let mut end_date: Option>> = None; + let mut has_submitted: Option> = None; + let mut idp_survey: Option = None; + let mut modified_at: Option> = None; + let mut name: Option = None; + let mut org_id: Option = None; + let mut publication: Option = + None; + let mut self_service: Option = None; + let mut single_response: Option = None; + let mut user_id: Option = None; + let mut user_uuid: Option = None; + let mut version: 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() { + "active" => { + active = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "anonymous" => { + anonymous = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "created_at" => { + created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "datastore_config" => { + datastore_config = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "description" => { + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "end_date" => { + end_date = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "has_submitted" => { + has_submitted = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "idp_survey" => { + idp_survey = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_at" => { + modified_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "name" => { + name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "org_id" => { + org_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "publication" => { + if v.is_null() { + continue; + } + publication = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "self_service" => { + self_service = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "single_response" => { + single_response = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_id" => { + user_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_uuid" => { + user_uuid = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "version" => { + if v.is_null() { + continue; + } + version = 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 active = active.ok_or_else(|| M::Error::missing_field("active"))?; + let anonymous = anonymous.ok_or_else(|| M::Error::missing_field("anonymous"))?; + let created_at = created_at.ok_or_else(|| M::Error::missing_field("created_at"))?; + let datastore_config = + datastore_config.ok_or_else(|| M::Error::missing_field("datastore_config"))?; + let description = + description.ok_or_else(|| M::Error::missing_field("description"))?; + let idp_survey = idp_survey.ok_or_else(|| M::Error::missing_field("idp_survey"))?; + let modified_at = + modified_at.ok_or_else(|| M::Error::missing_field("modified_at"))?; + let name = name.ok_or_else(|| M::Error::missing_field("name"))?; + let org_id = org_id.ok_or_else(|| M::Error::missing_field("org_id"))?; + let self_service = + self_service.ok_or_else(|| M::Error::missing_field("self_service"))?; + let single_response = + single_response.ok_or_else(|| M::Error::missing_field("single_response"))?; + let user_id = user_id.ok_or_else(|| M::Error::missing_field("user_id"))?; + let user_uuid = user_uuid.ok_or_else(|| M::Error::missing_field("user_uuid"))?; + + let content = FormDataAttributes { + active, + anonymous, + created_at, + datastore_config, + description, + end_date, + has_submitted, + idp_survey, + modified_at, + name, + org_id, + publication, + self_service, + single_response, + user_id, + user_uuid, + version, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormDataAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_form_data_definition.rs b/src/datadogV2/model/model_form_data_definition.rs new file mode 100644 index 0000000000..3adbbbac17 --- /dev/null +++ b/src/datadogV2/model/model_form_data_definition.rs @@ -0,0 +1,186 @@ +// 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 JSON Schema definition that describes the form's data fields. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormDataDefinition { + /// A description shown to form respondents. + #[serde(rename = "description")] + pub description: Option, + /// A map of field names to their JSON Schema definitions. + #[serde(rename = "properties")] + pub properties: Option>, + /// List of field names that must be answered. + #[serde(rename = "required")] + pub required: Option>, + /// The title of the form schema. + #[serde(rename = "title")] + pub title: Option, + /// The root schema type. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormDataDefinition { + pub fn new() -> FormDataDefinition { + FormDataDefinition { + description: None, + properties: None, + required: None, + title: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn description(mut self, value: String) -> Self { + self.description = Some(value); + self + } + + pub fn properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.properties = Some(value); + self + } + + pub fn required(mut self, value: Vec) -> Self { + self.required = Some(value); + self + } + + pub fn title(mut self, value: String) -> Self { + self.title = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::FormDataDefinitionType) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for FormDataDefinition { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for FormDataDefinition { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormDataDefinitionVisitor; + impl<'a> Visitor<'a> for FormDataDefinitionVisitor { + type Value = FormDataDefinition; + + 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 description: Option = None; + let mut properties: Option> = + None; + let mut required: Option> = None; + let mut title: 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() { + "description" => { + if v.is_null() { + continue; + } + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "properties" => { + if v.is_null() { + continue; + } + properties = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "required" => { + if v.is_null() { + continue; + } + required = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "title" => { + if v.is_null() { + continue; + } + title = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::FormDataDefinitionType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = FormDataDefinition { + description, + properties, + required, + title, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormDataDefinitionVisitor) + } +} diff --git a/src/datadogV2/model/model_form_data_definition_type.rs b/src/datadogV2/model/model_form_data_definition_type.rs new file mode 100644 index 0000000000..5193e139da --- /dev/null +++ b/src/datadogV2/model/model_form_data_definition_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 FormDataDefinitionType { + OBJECT, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for FormDataDefinitionType { + fn to_string(&self) -> String { + match self { + Self::OBJECT => String::from("object"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for FormDataDefinitionType { + 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 FormDataDefinitionType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "object" => Self::OBJECT, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_form_datastore_config_attributes.rs b/src/datadogV2/model/model_form_datastore_config_attributes.rs new file mode 100644 index 0000000000..a39003df5a --- /dev/null +++ b/src/datadogV2/model/model_form_datastore_config_attributes.rs @@ -0,0 +1,122 @@ +// 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 datastore configuration for a form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormDatastoreConfigAttributes { + /// The ID of the datastore. + #[serde(rename = "datastore_id")] + pub datastore_id: uuid::Uuid, + /// The name of the primary column in the datastore. + #[serde(rename = "primary_column_name")] + pub primary_column_name: String, + /// The strategy used to generate primary keys in the datastore. + #[serde(rename = "primary_key_generation_strategy")] + pub primary_key_generation_strategy: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormDatastoreConfigAttributes { + pub fn new( + datastore_id: uuid::Uuid, + primary_column_name: String, + primary_key_generation_strategy: String, + ) -> FormDatastoreConfigAttributes { + FormDatastoreConfigAttributes { + datastore_id, + primary_column_name, + primary_key_generation_strategy, + 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 FormDatastoreConfigAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormDatastoreConfigAttributesVisitor; + impl<'a> Visitor<'a> for FormDatastoreConfigAttributesVisitor { + type Value = FormDatastoreConfigAttributes; + + 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 datastore_id: Option = None; + let mut primary_column_name: Option = None; + let mut primary_key_generation_strategy: 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() { + "datastore_id" => { + datastore_id = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "primary_column_name" => { + primary_column_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "primary_key_generation_strategy" => { + primary_key_generation_strategy = + 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 datastore_id = + datastore_id.ok_or_else(|| M::Error::missing_field("datastore_id"))?; + let primary_column_name = primary_column_name + .ok_or_else(|| M::Error::missing_field("primary_column_name"))?; + let primary_key_generation_strategy = primary_key_generation_strategy + .ok_or_else(|| M::Error::missing_field("primary_key_generation_strategy"))?; + + let content = FormDatastoreConfigAttributes { + datastore_id, + primary_column_name, + primary_key_generation_strategy, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormDatastoreConfigAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_form_publication_attributes.rs b/src/datadogV2/model/model_form_publication_attributes.rs new file mode 100644 index 0000000000..6f06a72c6e --- /dev/null +++ b/src/datadogV2/model/model_form_publication_attributes.rs @@ -0,0 +1,194 @@ +// 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 of a form publication. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormPublicationAttributes { + /// The time at which the publication was created. + #[serde(rename = "created_at")] + pub created_at: chrono::DateTime, + /// The ID of the form. + #[serde(rename = "form_id")] + pub form_id: uuid::Uuid, + /// The version number that was published. + #[serde(rename = "form_version")] + pub form_version: i64, + /// The ID of the form publication. + #[serde(rename = "id")] + pub id: Option, + /// The time at which the publication was last modified. + #[serde(rename = "modified_at")] + pub modified_at: chrono::DateTime, + /// The ID of the organization that owns this publication. + #[serde(rename = "org_id")] + pub org_id: i64, + /// The sequential publication number for this form. + #[serde(rename = "publish_seq")] + pub publish_seq: i64, + /// The ID of the user who created this publication. + #[serde(rename = "user_id")] + pub user_id: i64, + /// The UUID of the user who created this publication. + #[serde(rename = "user_uuid")] + pub user_uuid: uuid::Uuid, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormPublicationAttributes { + pub fn new( + created_at: chrono::DateTime, + form_id: uuid::Uuid, + form_version: i64, + modified_at: chrono::DateTime, + org_id: i64, + publish_seq: i64, + user_id: i64, + user_uuid: uuid::Uuid, + ) -> FormPublicationAttributes { + FormPublicationAttributes { + created_at, + form_id, + form_version, + id: None, + modified_at, + org_id, + publish_seq, + user_id, + user_uuid, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for FormPublicationAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormPublicationAttributesVisitor; + impl<'a> Visitor<'a> for FormPublicationAttributesVisitor { + type Value = FormPublicationAttributes; + + 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 created_at: Option> = None; + let mut form_id: Option = None; + let mut form_version: Option = None; + let mut id: Option = None; + let mut modified_at: Option> = None; + let mut org_id: Option = None; + let mut publish_seq: Option = None; + let mut user_id: Option = None; + let mut user_uuid: 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() { + "created_at" => { + created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "form_id" => { + form_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "form_version" => { + form_version = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + if v.is_null() { + continue; + } + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_at" => { + modified_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "org_id" => { + org_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "publish_seq" => { + publish_seq = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_id" => { + user_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_uuid" => { + user_uuid = 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 created_at = created_at.ok_or_else(|| M::Error::missing_field("created_at"))?; + let form_id = form_id.ok_or_else(|| M::Error::missing_field("form_id"))?; + let form_version = + form_version.ok_or_else(|| M::Error::missing_field("form_version"))?; + let modified_at = + modified_at.ok_or_else(|| M::Error::missing_field("modified_at"))?; + let org_id = org_id.ok_or_else(|| M::Error::missing_field("org_id"))?; + let publish_seq = + publish_seq.ok_or_else(|| M::Error::missing_field("publish_seq"))?; + let user_id = user_id.ok_or_else(|| M::Error::missing_field("user_id"))?; + let user_uuid = user_uuid.ok_or_else(|| M::Error::missing_field("user_uuid"))?; + + let content = FormPublicationAttributes { + created_at, + form_id, + form_version, + id, + modified_at, + org_id, + publish_seq, + user_id, + user_uuid, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormPublicationAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_form_response.rs b/src/datadogV2/model/model_form_response.rs new file mode 100644 index 0000000000..dabf6e408a --- /dev/null +++ b/src/datadogV2/model/model_form_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 a single form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormResponse { + /// A form resource object. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::FormData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormResponse { + pub fn new(data: crate::datadogV2::model::FormData) -> FormResponse { + FormResponse { + 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 FormResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormResponseVisitor; + impl<'a> Visitor<'a> for FormResponseVisitor { + type Value = FormResponse; + + 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 = FormResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_form_type.rs b/src/datadogV2/model/model_form_type.rs new file mode 100644 index 0000000000..1385652125 --- /dev/null +++ b/src/datadogV2/model/model_form_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 FormType { + FORMS, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for FormType { + fn to_string(&self) -> String { + match self { + Self::FORMS => String::from("forms"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for FormType { + 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 FormType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "forms" => Self::FORMS, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_form_ui_definition.rs b/src/datadogV2/model/model_form_ui_definition.rs new file mode 100644 index 0000000000..a9e8a3c7a0 --- /dev/null +++ b/src/datadogV2/model/model_form_ui_definition.rs @@ -0,0 +1,122 @@ +// 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}; + +/// UI configuration for rendering form fields, including widget overrides, field ordering, and themes. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormUiDefinition { + /// The order in which form fields are displayed. + #[serde(rename = "ui:order")] + pub ui_order: Option>, + /// The visual theme applied to the form. + #[serde(rename = "ui:theme")] + pub ui_theme: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormUiDefinition { + pub fn new() -> FormUiDefinition { + FormUiDefinition { + ui_order: None, + ui_theme: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn ui_order(mut self, value: Vec) -> Self { + self.ui_order = Some(value); + self + } + + pub fn ui_theme(mut self, value: crate::datadogV2::model::FormUiDefinitionUiTheme) -> Self { + self.ui_theme = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for FormUiDefinition { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for FormUiDefinition { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormUiDefinitionVisitor; + impl<'a> Visitor<'a> for FormUiDefinitionVisitor { + type Value = FormUiDefinition; + + 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 ui_order: Option> = None; + let mut ui_theme: 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() { + "ui:order" => { + if v.is_null() { + continue; + } + ui_order = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "ui:theme" => { + if v.is_null() { + continue; + } + ui_theme = 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 content = FormUiDefinition { + ui_order, + ui_theme, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormUiDefinitionVisitor) + } +} diff --git a/src/datadogV2/model/model_form_ui_definition_ui_theme.rs b/src/datadogV2/model/model_form_ui_definition_ui_theme.rs new file mode 100644 index 0000000000..ef32775e0c --- /dev/null +++ b/src/datadogV2/model/model_form_ui_definition_ui_theme.rs @@ -0,0 +1,119 @@ +// 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 visual theme applied to the form. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormUiDefinitionUiTheme { + /// The primary color of the form theme. + #[serde(rename = "primaryColor")] + pub primary_color: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormUiDefinitionUiTheme { + pub fn new() -> FormUiDefinitionUiTheme { + FormUiDefinitionUiTheme { + primary_color: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn primary_color( + mut self, + value: crate::datadogV2::model::FormUiDefinitionUiThemePrimaryColor, + ) -> Self { + self.primary_color = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for FormUiDefinitionUiTheme { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for FormUiDefinitionUiTheme { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormUiDefinitionUiThemeVisitor; + impl<'a> Visitor<'a> for FormUiDefinitionUiThemeVisitor { + type Value = FormUiDefinitionUiTheme; + + 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 primary_color: Option< + crate::datadogV2::model::FormUiDefinitionUiThemePrimaryColor, + > = 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() { + "primaryColor" => { + if v.is_null() { + continue; + } + primary_color = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _primary_color) = primary_color { + match _primary_color { + crate::datadogV2::model::FormUiDefinitionUiThemePrimaryColor::UnparsedObject(_primary_color) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = FormUiDefinitionUiTheme { + primary_color, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormUiDefinitionUiThemeVisitor) + } +} diff --git a/src/datadogV2/model/model_form_ui_definition_ui_theme_primary_color.rs b/src/datadogV2/model/model_form_ui_definition_ui_theme_primary_color.rs new file mode 100644 index 0000000000..14b8b947c3 --- /dev/null +++ b/src/datadogV2/model/model_form_ui_definition_ui_theme_primary_color.rs @@ -0,0 +1,72 @@ +// 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 FormUiDefinitionUiThemePrimaryColor { + GRAY, + RED, + ORANGE, + YELLOW, + GREEN, + LIGHT_BLUE, + DARK_BLUE, + MAGENTA, + INDIGO, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for FormUiDefinitionUiThemePrimaryColor { + fn to_string(&self) -> String { + match self { + Self::GRAY => String::from("gray"), + Self::RED => String::from("red"), + Self::ORANGE => String::from("orange"), + Self::YELLOW => String::from("yellow"), + Self::GREEN => String::from("green"), + Self::LIGHT_BLUE => String::from("light-blue"), + Self::DARK_BLUE => String::from("dark-blue"), + Self::MAGENTA => String::from("magenta"), + Self::INDIGO => String::from("indigo"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for FormUiDefinitionUiThemePrimaryColor { + 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 FormUiDefinitionUiThemePrimaryColor { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "gray" => Self::GRAY, + "red" => Self::RED, + "orange" => Self::ORANGE, + "yellow" => Self::YELLOW, + "green" => Self::GREEN, + "light-blue" => Self::LIGHT_BLUE, + "dark-blue" => Self::DARK_BLUE, + "magenta" => Self::MAGENTA, + "indigo" => Self::INDIGO, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_form_version_attributes.rs b/src/datadogV2/model/model_form_version_attributes.rs new file mode 100644 index 0000000000..1cae8bced1 --- /dev/null +++ b/src/datadogV2/model/model_form_version_attributes.rs @@ -0,0 +1,229 @@ +// 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 of a form version. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormVersionAttributes { + /// The time at which the version was created. + #[serde(rename = "created_at")] + pub created_at: chrono::DateTime, + /// A JSON Schema definition that describes the form's data fields. + #[serde(rename = "data_definition")] + pub data_definition: crate::datadogV2::model::FormDataDefinition, + /// The signature of the version definition. + #[serde(rename = "definition_signature")] + pub definition_signature: String, + /// The ETag for optimistic concurrency control. + #[serialize_always] + #[serde(rename = "etag")] + pub etag: Option, + /// The ID of the form version. + #[serde(rename = "id")] + pub id: Option, + /// The time at which the version was last modified. + #[serde(rename = "modified_at")] + pub modified_at: chrono::DateTime, + /// The state of a form version. + #[serde(rename = "state")] + pub state: crate::datadogV2::model::FormVersionState, + /// UI configuration for rendering form fields, including widget overrides, field ordering, and themes. + #[serde(rename = "ui_definition")] + pub ui_definition: crate::datadogV2::model::FormUiDefinition, + /// The ID of the user who created this version. + #[serde(rename = "user_id")] + pub user_id: i64, + /// The UUID of the user who created this version. + #[serde(rename = "user_uuid")] + pub user_uuid: uuid::Uuid, + /// The sequential version number. + #[serde(rename = "version")] + pub version: i64, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormVersionAttributes { + pub fn new( + created_at: chrono::DateTime, + data_definition: crate::datadogV2::model::FormDataDefinition, + definition_signature: String, + etag: Option, + modified_at: chrono::DateTime, + state: crate::datadogV2::model::FormVersionState, + ui_definition: crate::datadogV2::model::FormUiDefinition, + user_id: i64, + user_uuid: uuid::Uuid, + version: i64, + ) -> FormVersionAttributes { + FormVersionAttributes { + created_at, + data_definition, + definition_signature, + etag, + id: None, + modified_at, + state, + ui_definition, + user_id, + user_uuid, + version, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for FormVersionAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormVersionAttributesVisitor; + impl<'a> Visitor<'a> for FormVersionAttributesVisitor { + type Value = FormVersionAttributes; + + 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 created_at: Option> = None; + let mut data_definition: Option = None; + let mut definition_signature: Option = None; + let mut etag: Option> = None; + let mut id: Option = None; + let mut modified_at: Option> = None; + let mut state: Option = None; + let mut ui_definition: Option = None; + let mut user_id: Option = None; + let mut user_uuid: Option = None; + let mut version: 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() { + "created_at" => { + created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "data_definition" => { + data_definition = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "definition_signature" => { + definition_signature = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "etag" => { + etag = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + if v.is_null() { + continue; + } + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_at" => { + modified_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "state" => { + state = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _state) = state { + match _state { + crate::datadogV2::model::FormVersionState::UnparsedObject( + _state, + ) => { + _unparsed = true; + } + _ => {} + } + } + } + "ui_definition" => { + ui_definition = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_id" => { + user_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_uuid" => { + user_uuid = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "version" => { + version = 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 created_at = created_at.ok_or_else(|| M::Error::missing_field("created_at"))?; + let data_definition = + data_definition.ok_or_else(|| M::Error::missing_field("data_definition"))?; + let definition_signature = definition_signature + .ok_or_else(|| M::Error::missing_field("definition_signature"))?; + let etag = etag.ok_or_else(|| M::Error::missing_field("etag"))?; + let modified_at = + modified_at.ok_or_else(|| M::Error::missing_field("modified_at"))?; + let state = state.ok_or_else(|| M::Error::missing_field("state"))?; + let ui_definition = + ui_definition.ok_or_else(|| M::Error::missing_field("ui_definition"))?; + let user_id = user_id.ok_or_else(|| M::Error::missing_field("user_id"))?; + let user_uuid = user_uuid.ok_or_else(|| M::Error::missing_field("user_uuid"))?; + let version = version.ok_or_else(|| M::Error::missing_field("version"))?; + + let content = FormVersionAttributes { + created_at, + data_definition, + definition_signature, + etag, + id, + modified_at, + state, + ui_definition, + user_id, + user_uuid, + version, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormVersionAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_form_version_state.rs b/src/datadogV2/model/model_form_version_state.rs new file mode 100644 index 0000000000..9b9aa2109a --- /dev/null +++ b/src/datadogV2/model/model_form_version_state.rs @@ -0,0 +1,51 @@ +// 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 FormVersionState { + DRAFT, + FROZEN, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for FormVersionState { + fn to_string(&self) -> String { + match self { + Self::DRAFT => String::from("draft"), + Self::FROZEN => String::from("frozen"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for FormVersionState { + 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 FormVersionState { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "draft" => Self::DRAFT, + "frozen" => Self::FROZEN, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_forms_response.rs b/src/datadogV2/model/model_forms_response.rs new file mode 100644 index 0000000000..b1309110dd --- /dev/null +++ b/src/datadogV2/model/model_forms_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 a list of forms. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FormsResponse { + /// A list of form resource objects. + #[serde(rename = "data")] + pub data: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FormsResponse { + pub fn new(data: Vec) -> FormsResponse { + FormsResponse { + 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 FormsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormsResponseVisitor; + impl<'a> Visitor<'a> for FormsResponseVisitor { + type Value = FormsResponse; + + 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 = FormsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FormsResponseVisitor) + } +} diff --git a/tests/scenarios/cassettes/v2/forms/Create-a-form-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/forms/Create-a-form-returns-OK-response.frozen new file mode 100644 index 0000000000..094857b451 --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Create-a-form-returns-OK-response.frozen @@ -0,0 +1 @@ +2026-06-04T18:34:02.931Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Create-a-form-returns-OK-response.json b/tests/scenarios/cassettes/v2/forms/Create-a-form-returns-OK-response.json new file mode 100644 index 0000000000..cdc51f15f4 --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Create-a-form-returns-OK-response.json @@ -0,0 +1,67 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"anonymous\":false,\"data_definition\":{},\"description\":\"A form to collect user feedback.\",\"idp_survey\":false,\"name\":\"User Feedback Form\",\"single_response\":false,\"ui_definition\":{}},\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/forms" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"edb7d6d5-e21c-4fd0-845d-679317b5c2c9\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:04.103183Z\",\"datastore_config\":{\"datastore_id\":\"7cc8dadd-3529-4d0f-b8cb-f8c11c165867\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A form to collect user feedback.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:04.103183Z\",\"name\":\"User Feedback Form\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"version\":{\"id\":\"354653\",\"state\":\"draft\",\"version\":1,\"etag\":\"b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d\",\"definition_signature\":\"{\\\"signature\\\":\\\"{\\\\\\\"version\\\\\\\":2,\\\\\\\"algorithm\\\\\\\":\\\\\\\"ecdsa-p384\\\\\\\",\\\\\\\"pubkey\\\\\\\":\\\\\\\"XOOWpRG1rFvaLHaG9qLf+GG78llET0BKnZtokyAtLfg=\\\\\\\",\\\\\\\"timestamp\\\\\\\":1780598044,\\\\\\\"proof\\\\\\\":\\\\\\\"MGQCMHsaS9oy6ZDzhUZuJQAYiivxgo9XKx5NjTW/0wafPecXBQ3lr27bKejXr4ihAuwxsgIwPfgedZacZ4t3Qg8p0+jrXH5MBdZx9hrat8mijVibYuLUd2n+bxaY0xcghHKwbtu4\\\\\\\"}\\\",\\\"version\\\":1}\",\"data_definition\":{},\"ui_definition\":{},\"created_at\":\"2026-06-04T18:34:04.103183Z\",\"modified_at\":\"2026-06-04T18:34:04.103183Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:02 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/forms/edb7d6d5-e21c-4fd0-845d-679317b5c2c9" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"edb7d6d5-e21c-4fd0-845d-679317b5c2c9\",\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:02 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Create-and-publish-a-form-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/forms/Create-and-publish-a-form-returns-OK-response.frozen new file mode 100644 index 0000000000..0add2d175d --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Create-and-publish-a-form-returns-OK-response.frozen @@ -0,0 +1 @@ +2026-06-04T18:34:04.703Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Create-and-publish-a-form-returns-OK-response.json b/tests/scenarios/cassettes/v2/forms/Create-and-publish-a-form-returns-OK-response.json new file mode 100644 index 0000000000..f2c540723a --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Create-and-publish-a-form-returns-OK-response.json @@ -0,0 +1,67 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"anonymous\":false,\"data_definition\":{},\"description\":\"A form to collect user feedback.\",\"idp_survey\":false,\"name\":\"User Feedback Form\",\"single_response\":false,\"ui_definition\":{}},\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/forms/create_and_publish" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"65318f43-ac0f-4990-add8-9847eee98fd8\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:05.178222Z\",\"datastore_config\":{\"datastore_id\":\"c89fc16a-53fb-4439-a007-1ebec095b1b7\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A form to collect user feedback.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:05.178222Z\",\"name\":\"User Feedback Form\",\"org_id\":321813,\"publication\":{\"id\":\"357922\",\"org_id\":321813,\"form_id\":\"65318f43-ac0f-4990-add8-9847eee98fd8\",\"publish_seq\":1,\"form_version\":1,\"created_at\":\"2026-06-04T18:34:05.178222Z\",\"modified_at\":\"2026-06-04T18:34:05.178222Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"},\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"version\":{\"id\":\"354654\",\"state\":\"frozen\",\"version\":1,\"etag\":\"b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d\",\"definition_signature\":\"{\\\"signature\\\":\\\"{\\\\\\\"version\\\\\\\":2,\\\\\\\"algorithm\\\\\\\":\\\\\\\"ecdsa-p384\\\\\\\",\\\\\\\"pubkey\\\\\\\":\\\\\\\"XOOWpRG1rFvaLHaG9qLf+GG78llET0BKnZtokyAtLfg=\\\\\\\",\\\\\\\"timestamp\\\\\\\":1780598045,\\\\\\\"proof\\\\\\\":\\\\\\\"MGYCMQCPPczYtNvj1RLjrQkIrQNHHVgB3nxFIjn5jgwUE0tweuTV1kZnaYYUg+gl1Eh5+tMCMQCajq1cy1MaWEbzHA0EcDC6LjyQ5ajqqngb3RMQwzP8ewvsh+uzkPD2v6AHjnW115o=\\\\\\\"}\\\",\\\"version\\\":1}\",\"data_definition\":{},\"ui_definition\":{},\"created_at\":\"2026-06-04T18:34:05.178222Z\",\"modified_at\":\"2026-06-04T18:34:05.178222Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:04 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/forms/65318f43-ac0f-4990-add8-9847eee98fd8" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"65318f43-ac0f-4990-add8-9847eee98fd8\",\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:04 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Delete-a-form-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/forms/Delete-a-form-returns-OK-response.frozen new file mode 100644 index 0000000000..602659c5aa --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Delete-a-form-returns-OK-response.frozen @@ -0,0 +1 @@ +2026-06-04T18:34:05.786Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Delete-a-form-returns-OK-response.json b/tests/scenarios/cassettes/v2/forms/Delete-a-form-returns-OK-response.json new file mode 100644 index 0000000000..d0f12f58cd --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Delete-a-form-returns-OK-response.json @@ -0,0 +1,95 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"anonymous\":false,\"data_definition\":{},\"description\":\"A simple test form.\",\"idp_survey\":false,\"name\":\"Test-Delete_a_form_returns_OK_response-1780598045\",\"single_response\":false,\"ui_definition\":{}},\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/forms" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"257a9d32-6ed0-429b-9745-75366363caf3\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:06.128238Z\",\"datastore_config\":{\"datastore_id\":\"1e33b83f-0733-454e-9404-c032a479548e\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A simple test form.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:06.128238Z\",\"name\":\"Test-Delete_a_form_returns_OK_response-1780598045\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"version\":{\"id\":\"354655\",\"state\":\"draft\",\"version\":1,\"etag\":\"b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d\",\"definition_signature\":\"{\\\"signature\\\":\\\"{\\\\\\\"version\\\\\\\":2,\\\\\\\"algorithm\\\\\\\":\\\\\\\"ecdsa-p384\\\\\\\",\\\\\\\"pubkey\\\\\\\":\\\\\\\"XOOWpRG1rFvaLHaG9qLf+GG78llET0BKnZtokyAtLfg=\\\\\\\",\\\\\\\"timestamp\\\\\\\":1780598046,\\\\\\\"proof\\\\\\\":\\\\\\\"MGQCMDR3p4Wc6qLinT0JK9tT2I3NBvYMx43pPcUuCOyMapne99sS2RJe0woOU68I0GbQvwIwQMw7OQruNsIuTNJxK0zthVCFnXaxLASIvl2NsyomT9s/p2cgEzOY4T+XyRl6i27c\\\\\\\"}\\\",\\\"version\\\":1}\",\"data_definition\":{},\"ui_definition\":{},\"created_at\":\"2026-06-04T18:34:06.128238Z\",\"modified_at\":\"2026-06-04T18:34:06.128238Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:05 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/forms/257a9d32-6ed0-429b-9745-75366363caf3" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"257a9d32-6ed0-429b-9745-75366363caf3\",\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:05 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/forms/257a9d32-6ed0-429b-9745-75366363caf3" + }, + "response": { + "body": { + "string": "{}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:05 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-Not-Found-response.frozen b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-Not-Found-response.frozen new file mode 100644 index 0000000000..9e0e0d9867 --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-Not-Found-response.frozen @@ -0,0 +1 @@ +2026-06-04T18:34:06.925Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-Not-Found-response.json b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-Not-Found-response.json new file mode 100644 index 0000000000..3bceac44f6 --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-Not-Found-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/forms/00000000-0000-0000-0000-000000000001" + }, + "response": { + "body": { + "string": "{\"errors\":[{\"status\":\"404\",\"id\":\"bccf11bd-13c7-4911-9c00-58c00b6f8f52\",\"title\":\"form not found\"}]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:06 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-OK-response.frozen new file mode 100644 index 0000000000..aea0ca127d --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-OK-response.frozen @@ -0,0 +1 @@ +2026-06-04T18:34:07.294Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-OK-response.json b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-OK-response.json new file mode 100644 index 0000000000..df8ef1b4c8 --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/Get-a-form-returns-OK-response.json @@ -0,0 +1,95 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"anonymous\":false,\"data_definition\":{},\"description\":\"A simple test form.\",\"idp_survey\":false,\"name\":\"Test-Get_a_form_returns_OK_response-1780598047\",\"single_response\":false,\"ui_definition\":{}},\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/forms" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"b42493d4-fbd0-4139-b4b9-4815f414621d\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:07.632566Z\",\"datastore_config\":{\"datastore_id\":\"9aace6ce-ee9d-4c81-b176-22bed53ff080\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A simple test form.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:07.632566Z\",\"name\":\"Test-Get_a_form_returns_OK_response-1780598047\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"version\":{\"id\":\"354656\",\"state\":\"draft\",\"version\":1,\"etag\":\"b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d\",\"definition_signature\":\"{\\\"signature\\\":\\\"{\\\\\\\"version\\\\\\\":2,\\\\\\\"algorithm\\\\\\\":\\\\\\\"ecdsa-p384\\\\\\\",\\\\\\\"pubkey\\\\\\\":\\\\\\\"XOOWpRG1rFvaLHaG9qLf+GG78llET0BKnZtokyAtLfg=\\\\\\\",\\\\\\\"timestamp\\\\\\\":1780598047,\\\\\\\"proof\\\\\\\":\\\\\\\"MGUCMQCkP+Usa2zK0v4SsSDBHsE4p88u025oyaRrAnNTiTXLwGr3K0W4/MAFeeosBwZonE0CMGYsqH/GAJUKeY0ZZGl8GZp2QeY1l3byimzWXRLf36CHhuB1Pshv/7bi0WoYYCOQIg==\\\\\\\"}\\\",\\\"version\\\":1}\",\"data_definition\":{},\"ui_definition\":{},\"created_at\":\"2026-06-04T18:34:07.632566Z\",\"modified_at\":\"2026-06-04T18:34:07.632566Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:07 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/forms/b42493d4-fbd0-4139-b4b9-4815f414621d" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"b42493d4-fbd0-4139-b4b9-4815f414621d\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:07.632566Z\",\"datastore_config\":{\"datastore_id\":\"9aace6ce-ee9d-4c81-b176-22bed53ff080\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A simple test form.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:07.632566Z\",\"name\":\"Test-Get_a_form_returns_OK_response-1780598047\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"version\":{\"id\":\"354656\",\"state\":\"draft\",\"version\":1,\"etag\":\"b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d\",\"definition_signature\":\"{\\\"signature\\\":\\\"{\\\\\\\"version\\\\\\\":2,\\\\\\\"algorithm\\\\\\\":\\\\\\\"ecdsa-p384\\\\\\\",\\\\\\\"pubkey\\\\\\\":\\\\\\\"XOOWpRG1rFvaLHaG9qLf+GG78llET0BKnZtokyAtLfg=\\\\\\\",\\\\\\\"timestamp\\\\\\\":1780598047,\\\\\\\"proof\\\\\\\":\\\\\\\"MGUCMQCkP+Usa2zK0v4SsSDBHsE4p88u025oyaRrAnNTiTXLwGr3K0W4/MAFeeosBwZonE0CMGYsqH/GAJUKeY0ZZGl8GZp2QeY1l3byimzWXRLf36CHhuB1Pshv/7bi0WoYYCOQIg==\\\\\\\"}\\\",\\\"version\\\":1}\",\"data_definition\":{},\"ui_definition\":{},\"created_at\":\"2026-06-04T18:34:07.632566Z\",\"modified_at\":\"2026-06-04T18:34:07.632566Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:07 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/forms/b42493d4-fbd0-4139-b4b9-4815f414621d" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"b42493d4-fbd0-4139-b4b9-4815f414621d\",\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:07 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/List-forms-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/forms/List-forms-returns-OK-response.frozen new file mode 100644 index 0000000000..e1050a989d --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/List-forms-returns-OK-response.frozen @@ -0,0 +1 @@ +2026-06-04T18:34:08.479Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/forms/List-forms-returns-OK-response.json b/tests/scenarios/cassettes/v2/forms/List-forms-returns-OK-response.json new file mode 100644 index 0000000000..e183c74328 --- /dev/null +++ b/tests/scenarios/cassettes/v2/forms/List-forms-returns-OK-response.json @@ -0,0 +1,95 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"anonymous\":false,\"data_definition\":{},\"description\":\"A simple test form.\",\"idp_survey\":false,\"name\":\"Test-List_forms_returns_OK_response-1780598048\",\"single_response\":false,\"ui_definition\":{}},\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/forms" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"d71d1aef-539d-4951-b98e-ff4c0c4f97bb\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:08.937305Z\",\"datastore_config\":{\"datastore_id\":\"76b9f7b4-99d8-4a55-b95c-260cac22820d\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A simple test form.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:08.937305Z\",\"name\":\"Test-List_forms_returns_OK_response-1780598048\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"version\":{\"id\":\"354657\",\"state\":\"draft\",\"version\":1,\"etag\":\"b51f08b698d88d8027a935d9db649774949f5fb41a0c559bfee6a9a13225c72d\",\"definition_signature\":\"{\\\"signature\\\":\\\"{\\\\\\\"version\\\\\\\":2,\\\\\\\"algorithm\\\\\\\":\\\\\\\"ecdsa-p384\\\\\\\",\\\\\\\"pubkey\\\\\\\":\\\\\\\"XOOWpRG1rFvaLHaG9qLf+GG78llET0BKnZtokyAtLfg=\\\\\\\",\\\\\\\"timestamp\\\\\\\":1780598048,\\\\\\\"proof\\\\\\\":\\\\\\\"MGUCMBSAXvYX++PAyywDBLlJsqgHq1ug3WLtMqKQRwx50qdAdj1UP1W58NnN9/DP70HavAIxANwA4guivHrOqlL36ETzde//0mI55MJ8Yv0ynU2p+QhqCSuJEHHgUUWjk0wYKJuZog==\\\\\\\"}\\\",\\\"version\\\":1}\",\"data_definition\":{},\"ui_definition\":{},\"created_at\":\"2026-06-04T18:34:08.937305Z\",\"modified_at\":\"2026-06-04T18:34:08.937305Z\",\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:08 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/forms" + }, + "response": { + "body": { + "string": "{\"data\":[{\"id\":\"7af864d6-8c2f-41e5-b80d-1be56ea33d23\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:05:41.512876Z\",\"datastore_config\":{\"datastore_id\":\"543a7e0e-0f0f-4b14-8911-2f20df5f1b07\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A form to collect user feedback.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:05:41.512876Z\",\"name\":\"User Feedback Form\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":1445416,\"user_uuid\":\"3ad549bf-eba0-11e9-a77a-0705486660d0\"}},{\"id\":\"b2953c07-9385-4de2-9cd3-af3f5d6c7d09\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:15:44.116619Z\",\"datastore_config\":{\"datastore_id\":\"77b4b384-27d6-4619-bb55-1b2158d0080b\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A form to collect user feedback.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:15:44.116619Z\",\"name\":\"User Feedback Form\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":1445416,\"user_uuid\":\"3ad549bf-eba0-11e9-a77a-0705486660d0\"}},{\"id\":\"d71d1aef-539d-4951-b98e-ff4c0c4f97bb\",\"type\":\"forms\",\"attributes\":{\"active\":true,\"anonymous\":false,\"created_at\":\"2026-06-04T18:34:08.937305Z\",\"datastore_config\":{\"datastore_id\":\"76b9f7b4-99d8-4a55-b95c-260cac22820d\",\"primary_column_name\":\"id\",\"primary_key_generation_strategy\":\"none\"},\"description\":\"A simple test form.\",\"idp_survey\":false,\"modified_at\":\"2026-06-04T18:34:08.937305Z\",\"name\":\"Test-List_forms_returns_OK_response-1780598048\",\"org_id\":321813,\"self_service\":false,\"single_response\":false,\"user_id\":2320499,\"user_uuid\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:08 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/forms/d71d1aef-539d-4951-b98e-ff4c0c4f97bb" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"d71d1aef-539d-4951-b98e-ff4c0c4f97bb\",\"type\":\"forms\"}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Thu, 04 Jun 2026 18:34:08 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v2/forms.feature b/tests/scenarios/features/v2/forms.feature new file mode 100644 index 0000000000..40823edbc0 --- /dev/null +++ b/tests/scenarios/features/v2/forms.feature @@ -0,0 +1,107 @@ +@endpoint(forms) @endpoint(forms-v2) +Feature: Forms + The Datadog Forms API lets you create and manage forms within the App + Builder platform. You can configure form settings, manage versions, + publish forms, and handle sharing configurations. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "Forms" API + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Create a form returns "Bad Request" response + Given operation "CreateForm" enabled + And new "CreateForm" request + And body with value {"data": {"attributes": {"anonymous": false, "data_definition": {"description": "Welcome to the Engineering Experience Survey.", "required": [], "title": "Developer Experience Survey", "type": "object"}, "description": "A form to collect user feedback.", "idp_survey": false, "name": "User Feedback Form", "single_response": false, "ui_definition": {"ui:order": [], "ui:theme": {"primaryColor": "gray"}}}, "type": "forms"}} + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/app-builder-backend + Scenario: Create a form returns "OK" response + Given operation "CreateForm" enabled + And new "CreateForm" request + And body with value {"data": {"attributes": {"anonymous": false, "data_definition": {}, "description": "A form to collect user feedback.", "idp_survey": false, "name": "User Feedback Form", "single_response": false, "ui_definition": {}}, "type": "forms"}} + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Create and publish a form returns "Bad Request" response + Given operation "CreateAndPublishForm" enabled + And new "CreateAndPublishForm" request + And body with value {"data": {"attributes": {"anonymous": false, "data_definition": {"description": "Welcome to the Engineering Experience Survey.", "required": [], "title": "Developer Experience Survey", "type": "object"}, "description": "A form to collect user feedback.", "idp_survey": false, "name": "User Feedback Form", "single_response": false, "ui_definition": {"ui:order": [], "ui:theme": {"primaryColor": "gray"}}}, "type": "forms"}} + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/app-builder-backend + Scenario: Create and publish a form returns "OK" response + Given operation "CreateAndPublishForm" enabled + And new "CreateAndPublishForm" request + And body with value {"data": {"attributes": {"anonymous": false, "data_definition": {}, "description": "A form to collect user feedback.", "idp_survey": false, "name": "User Feedback Form", "single_response": false, "ui_definition": {}}, "type": "forms"}} + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Delete a form returns "Bad Request" response + Given operation "DeleteForm" enabled + And new "DeleteForm" request + And request contains "form_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/app-builder-backend + Scenario: Delete a form returns "OK" response + Given operation "DeleteForm" enabled + And there is a valid "form" in the system + And new "DeleteForm" request + And request contains "form_id" parameter from "form.data.id" + When the request is sent + Then the response status is 200 OK + And the response "data.id" has the same value as "form.data.id" + And the response "data.type" is equal to "forms" + + @generated @skip @team:DataDog/app-builder-backend + Scenario: Get a form returns "Bad Request" response + Given operation "GetForm" enabled + And new "GetForm" request + And request contains "form_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/app-builder-backend + Scenario: Get a form returns "Not Found" response + Given operation "GetForm" enabled + And new "GetForm" request + And request contains "form_id" parameter with value "00000000-0000-0000-0000-000000000001" + When the request is sent + Then the response status is 404 Not Found + + @team:DataDog/app-builder-backend + Scenario: Get a form returns "OK" response + Given operation "GetForm" enabled + And there is a valid "form" in the system + And new "GetForm" request + And request contains "form_id" parameter from "form.data.id" + When the request is sent + Then the response status is 200 OK + And the response "data.id" has the same value as "form.data.id" + 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 forms returns "Bad Request" response + Given operation "ListForms" enabled + And new "ListForms" request + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/app-builder-backend + Scenario: List forms returns "OK" response + Given operation "ListForms" enabled + And there is a valid "form" in the system + And new "ListForms" request + When the request is sent + Then the response status is 200 OK + And the response "data" has item with field "id" with value "{{ form.data.id }}" + And the response "data" has item with field "type" with value "forms" + And the response "data" has item with field "attributes.name" with value "{{ unique }}" diff --git a/tests/scenarios/features/v2/given.json b/tests/scenarios/features/v2/given.json index 0e1e956697..0a6db71d71 100644 --- a/tests/scenarios/features/v2/given.json +++ b/tests/scenarios/features/v2/given.json @@ -498,6 +498,30 @@ "tag": "Feature Flags", "operationId": "UpdateAllocationsForFeatureFlagInEnvironment" }, + { + "parameters": [ + { + "name": "body", + "value": "{\n \"data\": {\n \"type\": \"forms\",\n \"attributes\": {\n \"name\": \"{{ unique }}\",\n \"description\": \"A simple test form.\",\n \"anonymous\": false,\n \"single_response\": false,\n \"idp_survey\": false,\n \"data_definition\": {},\n \"ui_definition\": {}\n }\n }\n}" + } + ], + "step": "there is a valid \"form\" in the system", + "key": "form", + "tag": "Forms", + "operationId": "CreateForm" + }, + { + "parameters": [ + { + "name": "body", + "value": "{\n \"data\": {\n \"type\": \"forms\",\n \"attributes\": {\n \"name\": \"{{ unique }}\",\n \"description\": \"A simple test form.\",\n \"anonymous\": false,\n \"single_response\": false,\n \"idp_survey\": false,\n \"data_definition\": {},\n \"ui_definition\": {}\n }\n }\n}" + } + ], + "step": "there is a valid \"form_published\" in the system", + "key": "form_published", + "tag": "Forms", + "operationId": "CreateAndPublishForm" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 9101d0155c..61278fe120 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2609,6 +2609,50 @@ "type": "unsafe" } }, + "ListForms": { + "tag": "Forms", + "undo": { + "type": "safe" + } + }, + "CreateForm": { + "tag": "Forms", + "undo": { + "operationId": "DeleteForm", + "parameters": [ + { + "name": "form_id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, + "CreateAndPublishForm": { + "tag": "Forms", + "undo": { + "operationId": "DeleteForm", + "parameters": [ + { + "name": "form_id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, + "DeleteForm": { + "tag": "Forms", + "undo": { + "type": "idempotent" + } + }, + "GetForm": { + "tag": "Forms", + "undo": { + "type": "safe" + } + }, "GetHamrOrgConnection": { "tag": "High Availability MultiRegion", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 1b05e31666..379d157717 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -106,6 +106,7 @@ pub struct ApiInstances { pub v2_api_error_tracking: Option, pub v2_api_events: Option, pub v2_api_feature_flags: Option, + pub v2_api_forms: Option, pub v2_api_high_availability_multi_region: Option, pub v2_api_entity_integration_configs: @@ -851,6 +852,13 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { ), ); } + "Forms" => { + world.api_instances.v2_api_forms = + Some(datadogV2::api_forms::FormsAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone(), + )); + } "HighAvailabilityMultiRegion" => { world.api_instances.v2_api_high_availability_multi_region = Some(datadogV2::api_high_availability_multi_region::HighAvailabilityMultiRegionAPI::with_client_and_config( world.config.clone(), @@ -4474,6 +4482,22 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.UnarchiveFeatureFlag".into(), test_v2_unarchive_feature_flag, ); + world + .function_mappings + .insert("v2.ListForms".into(), test_v2_list_forms); + world + .function_mappings + .insert("v2.CreateForm".into(), test_v2_create_form); + world.function_mappings.insert( + "v2.CreateAndPublishForm".into(), + test_v2_create_and_publish_form, + ); + world + .function_mappings + .insert("v2.DeleteForm".into(), test_v2_delete_form); + world + .function_mappings + .insert("v2.GetForm".into(), test_v2_get_form); world.function_mappings.insert( "v2.GetHamrOrgConnection".into(), test_v2_get_hamr_org_connection, @@ -34409,6 +34433,135 @@ fn test_v2_unarchive_feature_flag(world: &mut DatadogWorld, _parameters: &HashMa world.response.code = response.status.as_u16(); } +fn test_v2_list_forms(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_forms + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.list_forms_with_http_info()) { + 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_create_form(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_forms + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.create_form_with_http_info(body)) { + 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_create_and_publish_form(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_forms + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.create_and_publish_form_with_http_info(body)) { + 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_delete_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.delete_form_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_get_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 version = _parameters + .get("version") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_forms::GetFormOptionalParams::default(); + params.version = version; + let response = match block_on(api.get_form_with_http_info(form_id, params)) { + 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_get_hamr_org_connection(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances