diff --git a/lib/trento_web/openapi/v1/schema/ability.ex b/lib/trento_web/openapi/v1/schema/ability.ex index 2545e1399f..2aca752c7c 100644 --- a/lib/trento_web/openapi/v1/schema/ability.ex +++ b/lib/trento_web/openapi/v1/schema/ability.ex @@ -7,37 +7,43 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Ability do defmodule AbilityItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "Ability", - description: "Ability entry", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "Ability ID", nullable: false}, - name: %Schema{type: :string, description: "Ability name", nullable: false}, - resource: %Schema{ - type: :string, - description: "Resource attached to ability", - nullable: false + OpenApiSpex.schema( + %{ + title: "Ability", + description: "Ability entry", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "Ability ID", nullable: false}, + name: %Schema{type: :string, description: "Ability name", nullable: false}, + resource: %Schema{ + type: :string, + description: "Resource attached to ability", + nullable: false + }, + label: %Schema{ + type: :string, + description: "Description of the ability", + nullable: false + } }, - label: %Schema{ - type: :string, - description: "Description of the ability", - nullable: false - } + required: [:id, :name, :resource] }, - required: [:id, :name, :resource] - }) + struct?: false + ) end defmodule AbilityCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "AbilityCollection", - description: "A collection of abilities in the system", - type: :array, - items: AbilityItem - }) + OpenApiSpex.schema( + %{ + title: "AbilityCollection", + description: "A collection of abilities in the system", + type: :array, + items: AbilityItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/activity_log.ex b/lib/trento_web/openapi/v1/schema/activity_log.ex index 69357033ac..aff8d989ff 100644 --- a/lib/trento_web/openapi/v1/schema/activity_log.ex +++ b/lib/trento_web/openapi/v1/schema/activity_log.ex @@ -4,37 +4,40 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ActivityLog do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "ActivityLog", - description: "Activity Log for the current installation.", - type: :array, - items: %Schema{ - title: "ActivityLogEntry", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{ - type: :string, - description: "Identifier of Activity Log entry.", - format: :uuid + OpenApiSpex.schema( + %{ + title: "ActivityLog", + description: "Activity Log for the current installation.", + type: :array, + items: %Schema{ + title: "ActivityLogEntry", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{ + type: :string, + description: "Identifier of Activity Log entry.", + format: :uuid + }, + type: %Schema{ + type: :string, + description: "Type of Activity Log entry." + }, + actor: %Schema{ + type: :string, + description: "Actor causing an Activity Log entry. E.g. System or a specific user." + }, + metadata: %Schema{ + type: :object + }, + occurred_on: %Schema{ + type: :string, + description: "Timestamp upon Activity Log entry insertion." + } }, - type: %Schema{ - type: :string, - description: "Type of Activity Log entry." - }, - actor: %Schema{ - type: :string, - description: "Actor causing an Activity Log entry. E.g. System or a specific user." - }, - metadata: %Schema{ - type: :object - }, - occurred_on: %Schema{ - type: :string, - description: "Timestamp upon Activity Log entry insertion." - } - }, - required: [:id, :type, :actor, :metadata, :occurred_on] - } - }) + required: [:id, :type, :actor, :metadata, :occurred_on] + } + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/available_software_updates.ex b/lib/trento_web/openapi/v1/schema/available_software_updates.ex index 0fb84c6b87..6787ea11f5 100644 --- a/lib/trento_web/openapi/v1/schema/available_software_updates.ex +++ b/lib/trento_web/openapi/v1/schema/available_software_updates.ex @@ -6,78 +6,87 @@ defmodule TrentoWeb.OpenApi.V1.Schema.AvailableSoftwareUpdates do defmodule UpgradablePackage do @moduledoc false - OpenApiSpex.schema(%{ - title: "UpgradablePackage", - description: "Upgradable package", - type: :object, - additionalProperties: false, - properties: %{ - arch: %Schema{type: :string, description: "Package name"}, - from_epoch: %Schema{type: :string, description: "From epoch"}, - from_release: %Schema{type: :string, description: "From which release"}, - from_version: %Schema{type: :string, description: "From version"}, - name: %Schema{type: :string, description: "Upgradable package name"}, - to_epoch: %Schema{type: :string, description: "To epoch"}, - to_package_id: %Schema{type: :string, description: "To package id"}, - to_release: %Schema{type: :string, description: "To release"}, - to_version: %Schema{type: :string, description: "To version"} - } - }) + OpenApiSpex.schema( + %{ + title: "UpgradablePackage", + description: "Upgradable package", + type: :object, + additionalProperties: false, + properties: %{ + arch: %Schema{type: :string, description: "Package name"}, + from_epoch: %Schema{type: :string, description: "From epoch"}, + from_release: %Schema{type: :string, description: "From which release"}, + from_version: %Schema{type: :string, description: "From version"}, + name: %Schema{type: :string, description: "Upgradable package name"}, + to_epoch: %Schema{type: :string, description: "To epoch"}, + to_package_id: %Schema{type: :string, description: "To package id"}, + to_release: %Schema{type: :string, description: "To release"}, + to_version: %Schema{type: :string, description: "To version"} + } + }, + struct?: false + ) end defmodule RelevantPatch do @moduledoc false - OpenApiSpex.schema(%{ - title: "RelevantPatch", - description: "Relevant patch", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "Advisory's id"}, - advisory_name: %Schema{type: :string, description: "Advisory name"}, - advisory_status: %Schema{type: :string, description: "Advisory status"}, - advisory_synopsis: %Schema{type: :string, description: "Advisory's synopsis"}, - advisory_type: %Schema{ - type: :string, - description: "Advisory's type", - enum: [:security_advisory, :bugfix, :enhancement] - }, - date: %Schema{type: :string, description: "Advisory's date"}, - update_date: %Schema{type: :string, description: "Advisory's update date"} - } - }) + OpenApiSpex.schema( + %{ + title: "RelevantPatch", + description: "Relevant patch", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "Advisory's id"}, + advisory_name: %Schema{type: :string, description: "Advisory name"}, + advisory_status: %Schema{type: :string, description: "Advisory status"}, + advisory_synopsis: %Schema{type: :string, description: "Advisory's synopsis"}, + advisory_type: %Schema{ + type: :string, + description: "Advisory's type", + enum: [:security_advisory, :bugfix, :enhancement] + }, + date: %Schema{type: :string, description: "Advisory's date"}, + update_date: %Schema{type: :string, description: "Advisory's update date"} + } + }, + struct?: false + ) end defmodule PatchesForPackage do @moduledoc false - OpenApiSpex.schema(%{ - title: "PatchesForPackage", - description: "Relevant patches covered by a package upgrade", - type: :object, - additionalProperties: false, - properties: %{ - package_id: %Schema{type: :string, description: ""}, - patches: %Schema{ - type: :array, - additionalProperties: false, - items: %Schema{ - title: "PatchForPackage", - description: "A list of relevant patches that the upgrade covers", + OpenApiSpex.schema( + %{ + title: "PatchesForPackage", + description: "Relevant patches covered by a package upgrade", + type: :object, + additionalProperties: false, + properties: %{ + package_id: %Schema{type: :string, description: ""}, + patches: %Schema{ + type: :array, additionalProperties: false, - properties: %{ - advisory_type: %Schema{type: :string, description: "Advisory type"}, - advisory: %Schema{type: :string, description: "Advisory name for the patch"}, - synopsis: %Schema{type: :string, description: "Advisory synopsis for the patch"}, - issue_date: %Schema{type: :string, description: "Advisory issue date"}, - last_modified_date: %Schema{ - type: :string, - description: "Advisory last modified date" + items: %Schema{ + title: "PatchForPackage", + description: "A list of relevant patches that the upgrade covers", + additionalProperties: false, + properties: %{ + advisory_type: %Schema{type: :string, description: "Advisory type"}, + advisory: %Schema{type: :string, description: "Advisory name for the patch"}, + synopsis: %Schema{type: :string, description: "Advisory synopsis for the patch"}, + issue_date: %Schema{type: :string, description: "Advisory issue date"}, + last_modified_date: %Schema{ + type: :string, + description: "Advisory last modified date" + } } } } } - } - }) + }, + struct?: false + ) end defmodule AvailableSoftwareUpdatesResponse do @@ -124,135 +133,150 @@ defmodule TrentoWeb.OpenApi.V1.Schema.AvailableSoftwareUpdates do defmodule ErrataDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "ErrataDetails", - description: "Details for the erratum matching the given advisory name", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :number, format: :int, description: "Advisory ID number"}, - issue_date: %Schema{ - type: :string, - format: "date", - description: "Advisory issue date" - }, - update_date: %Schema{ - type: :string, - format: "date", - description: "Advisory update date" - }, - last_modified_date: %Schema{ - type: :string, - format: "date", - description: "Advisory last modified date" - }, - synopsis: %Schema{type: :string, description: "Advisory synopsis"}, - release: %Schema{type: :number, format: :int, description: "Advisory Release number"}, - advisory_status: %Schema{type: :string, description: "Advisory status"}, - vendor_advisory: %Schema{type: :string, description: "Vendor advisory"}, - type: %Schema{type: :string, description: "Advisory type"}, - product: %Schema{type: :string, description: "Advisory product"}, - errata_from: %Schema{type: :string, description: "Advisory errata"}, - topic: %Schema{type: :string, description: "Advisory topic"}, - description: %Schema{type: :string, description: "Advisory description"}, - references: %Schema{type: :string, description: "Advisory references"}, - notes: %Schema{type: :string, description: "Advisory notes"}, - solution: %Schema{type: :string, description: "Advisory solution"}, - reboot_suggested: %Schema{ - type: :boolean, - description: - "A boolean flag signaling whether a system reboot is advisable following the application of the errata. Typical example is upon kernel update." - }, - restart_suggested: %Schema{ - type: :boolean, - description: - "A boolean flag signaling a weather reboot of the package manager is advisable following the application of the errata. This is commonly used to address update stack issues before proceeding with other updates." + OpenApiSpex.schema( + %{ + title: "ErrataDetails", + description: "Details for the erratum matching the given advisory name", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :number, format: :int, description: "Advisory ID number"}, + issue_date: %Schema{ + type: :string, + format: "date", + description: "Advisory issue date" + }, + update_date: %Schema{ + type: :string, + format: "date", + description: "Advisory update date" + }, + last_modified_date: %Schema{ + type: :string, + format: "date", + description: "Advisory last modified date" + }, + synopsis: %Schema{type: :string, description: "Advisory synopsis"}, + release: %Schema{type: :number, format: :int, description: "Advisory Release number"}, + advisory_status: %Schema{type: :string, description: "Advisory status"}, + vendor_advisory: %Schema{type: :string, description: "Vendor advisory"}, + type: %Schema{type: :string, description: "Advisory type"}, + product: %Schema{type: :string, description: "Advisory product"}, + errata_from: %Schema{type: :string, description: "Advisory errata"}, + topic: %Schema{type: :string, description: "Advisory topic"}, + description: %Schema{type: :string, description: "Advisory description"}, + references: %Schema{type: :string, description: "Advisory references"}, + notes: %Schema{type: :string, description: "Advisory notes"}, + solution: %Schema{type: :string, description: "Advisory solution"}, + reboot_suggested: %Schema{ + type: :boolean, + description: + "A boolean flag signaling whether a system reboot is advisable following the application of the errata. Typical example is upon kernel update." + }, + restart_suggested: %Schema{ + type: :boolean, + description: + "A boolean flag signaling a weather reboot of the package manager is advisable following the application of the errata. This is commonly used to address update stack issues before proceeding with other updates." + } } - } - }) + }, + struct?: false + ) end defmodule CVEs do @moduledoc false - OpenApiSpex.schema(%{ - title: "CVEs", - description: "List of CVEs applicable to the errata with the given advisory name.", - type: :array, - additionalProperties: false, - items: %Schema{ - title: "CVE", - description: "A fix for a publicly known security vulnerability", - type: :string - } - }) + OpenApiSpex.schema( + %{ + title: "CVEs", + description: "List of CVEs applicable to the errata with the given advisory name.", + type: :array, + additionalProperties: false, + items: %Schema{ + title: "CVE", + description: "A fix for a publicly known security vulnerability", + type: :string + } + }, + struct?: false + ) end defmodule AdvisoryFixes do @moduledoc false - OpenApiSpex.schema(%{ - title: "AdvisoryFixes", - description: "Response returned from the get advisory fixes endpoint", - type: :object, - additionalProperties: %Schema{type: :string} - }) + OpenApiSpex.schema( + %{ + title: "AdvisoryFixes", + description: "Response returned from the get advisory fixes endpoint", + type: :object, + additionalProperties: %Schema{type: :string} + }, + struct?: false + ) end defmodule AffectedPackages do @moduledoc false - OpenApiSpex.schema(%{ - title: "AffectedPackages", - description: "Response returned from the get affected packages endpoint", - type: :array, - additionalProperties: false, - items: %Schema{ - title: "AffectedPackage", - description: "Metadata for a package effected by an advisory", - type: :object, - properties: %{ - name: %Schema{ - type: :string, - description: "Package name" - }, - arch_label: %Schema{ - type: :string, - description: "Package architecture" - }, - version: %Schema{ - type: :string, - description: "Package upstream version" - }, - release: %Schema{ - type: :string, - description: "Package RPM release number" - }, - epoch: %Schema{ - type: :string, - description: "Package epoch number" + OpenApiSpex.schema( + %{ + title: "AffectedPackages", + description: "Response returned from the get affected packages endpoint", + type: :array, + additionalProperties: false, + items: %Schema{ + title: "AffectedPackage", + description: "Metadata for a package effected by an advisory", + type: :object, + properties: %{ + name: %Schema{ + type: :string, + description: "Package name" + }, + arch_label: %Schema{ + type: :string, + description: "Package architecture" + }, + version: %Schema{ + type: :string, + description: "Package upstream version" + }, + release: %Schema{ + type: :string, + description: "Package RPM release number" + }, + epoch: %Schema{ + type: :string, + description: "Package epoch number" + } } } - } - }) + }, + struct?: false + ) end defmodule AffectedSystems do @moduledoc false - OpenApiSpex.schema(%{ - title: "AffectedSystems", - description: "Response returned from the get affected systems endpoint", - type: :array, - additionalProperties: false, - items: %Schema{ - title: "AffectedSystem", - description: "Metadata for a system effected by an advisory", - type: :object, - properties: %{ - name: %Schema{ - type: :string, - description: "System name" + OpenApiSpex.schema( + %{ + title: "AffectedSystems", + description: "Response returned from the get affected systems endpoint", + type: :array, + additionalProperties: false, + items: %Schema{ + title: "AffectedSystem", + description: "Metadata for a system effected by an advisory", + type: :object, + properties: %{ + name: %Schema{ + type: :string, + description: "System name" + } } } - } - }) + }, + struct?: false + ) end defmodule ErrataDetailsResponse do diff --git a/lib/trento_web/openapi/v1/schema/bad_request.ex b/lib/trento_web/openapi/v1/schema/bad_request.ex index cc42b36eda..d90675464a 100644 --- a/lib/trento_web/openapi/v1/schema/bad_request.ex +++ b/lib/trento_web/openapi/v1/schema/bad_request.ex @@ -8,26 +8,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.BadRequest do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "BadRequest", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "Invalid request payload." - }, - title: %Schema{type: :string, example: "Bad Request"} + OpenApiSpex.schema( + %{ + title: "BadRequest", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "Invalid request payload." + }, + title: %Schema{type: :string, example: "Bad Request"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/chart.ex b/lib/trento_web/openapi/v1/schema/chart.ex index 7313dbb47d..13d54e839d 100644 --- a/lib/trento_web/openapi/v1/schema/chart.ex +++ b/lib/trento_web/openapi/v1/schema/chart.ex @@ -6,73 +6,82 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do defmodule ChartTimeSeries do @moduledoc false - OpenApiSpex.schema(%{ - title: "ChartTimeSeries", - description: - "A Time Series for a chart, has a series of float values distributed through time", - type: :object, - additionalProperties: false, - properties: %{ - label: %Schema{type: :string, description: "The name of series"}, - series: %Schema{ - type: :array, - description: "The values of the series", - items: %Schema{ - type: :object, - description: "A timestamp/value pair", - properties: %{ - timestamp: %Schema{ - type: :string, - format: "date-time", - description: "ISO8601 timestamp" - }, - value: %Schema{ - type: :number, - example: 270_396.2030, - format: :float, - description: "Float value" + OpenApiSpex.schema( + %{ + title: "ChartTimeSeries", + description: + "A Time Series for a chart, has a series of float values distributed through time", + type: :object, + additionalProperties: false, + properties: %{ + label: %Schema{type: :string, description: "The name of series"}, + series: %Schema{ + type: :array, + description: "The values of the series", + items: %Schema{ + type: :object, + description: "A timestamp/value pair", + properties: %{ + timestamp: %Schema{ + type: :string, + format: "date-time", + description: "ISO8601 timestamp" + }, + value: %Schema{ + type: :number, + example: 270_396.2030, + format: :float, + description: "Float value" + } } } } } - } - }) + }, + struct?: false + ) end defmodule HostCpuChart do @moduledoc false - OpenApiSpex.schema(%{ - title: "HostCpuChart", - additionalProperties: false, - description: "A Time Series chart with information about the cpu usage of a host", - type: :object, - properties: %{ - busy_iowait: ChartTimeSeries, - busy_irqs: ChartTimeSeries, - busy_other: ChartTimeSeries, - busy_system: ChartTimeSeries, - busy_user: ChartTimeSeries, - idle: ChartTimeSeries - } - }) + OpenApiSpex.schema( + %{ + title: "HostCpuChart", + additionalProperties: false, + description: "A Time Series chart with information about the cpu usage of a host", + type: :object, + properties: %{ + busy_iowait: ChartTimeSeries, + busy_irqs: ChartTimeSeries, + busy_other: ChartTimeSeries, + busy_system: ChartTimeSeries, + busy_user: ChartTimeSeries, + idle: ChartTimeSeries + } + }, + struct?: false + ) end defmodule HostMemoryChart do @moduledoc false - OpenApiSpex.schema(%{ - title: "HostMemoryChart", - description: "A Time series chart with information about the memory usage of a host", - type: :object, - additionalProperties: false, - properties: %{ - ram_total: ChartTimeSeries, - ram_cache_and_buffer: ChartTimeSeries, - ram_free: ChartTimeSeries, - ram_used: ChartTimeSeries, - swap_used: ChartTimeSeries - } - }) + OpenApiSpex.schema( + %{ + title: "HostMemoryChart", + description: "A Time series chart with information about the memory usage of a host", + type: :object, + additionalProperties: false, + properties: %{ + ram_total: ChartTimeSeries, + ram_cache_and_buffer: ChartTimeSeries, + ram_free: ChartTimeSeries, + ram_used: ChartTimeSeries, + swap_used: ChartTimeSeries + } + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/checks.ex b/lib/trento_web/openapi/v1/schema/checks.ex index b2a23ea88a..9564e28372 100644 --- a/lib/trento_web/openapi/v1/schema/checks.ex +++ b/lib/trento_web/openapi/v1/schema/checks.ex @@ -3,17 +3,21 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Checks.ChecksSelectionRequest do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "ChecksSelectionRequest", - description: "A list of desired checks that should be executed on the target infrastructure", - additionalProperties: false, - type: :object, - properties: %{ - checks: %Schema{ - type: :array, - items: %Schema{type: :string} - } + OpenApiSpex.schema( + %{ + title: "ChecksSelectionRequest", + description: + "A list of desired checks that should be executed on the target infrastructure", + additionalProperties: false, + type: :object, + properties: %{ + checks: %Schema{ + type: :array, + items: %Schema{type: :string} + } + }, + required: [:checks] }, - required: [:checks] - }) + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/checks_catalog.ex b/lib/trento_web/openapi/v1/schema/checks_catalog.ex index a10bfc2c27..d9a26c620c 100644 --- a/lib/trento_web/openapi/v1/schema/checks_catalog.ex +++ b/lib/trento_web/openapi/v1/schema/checks_catalog.ex @@ -9,188 +9,213 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do defmodule Check do @moduledoc false - OpenApiSpex.schema(%{ - title: "Check", - description: "An available check to be executed on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Check ID", format: :uuid}, - name: %Schema{type: :string, description: "Check Name"}, - description: %Schema{type: :string, description: "Check Description"}, - remediation: %Schema{type: :string, description: "Check Remediation"}, - implementation: %Schema{type: :string, description: "Check Implementation"}, - labels: %Schema{type: :string, description: "Check Labels"}, - premium: %Schema{ - type: :boolean, - description: "Indicates whether the current check is a Premium check" - }, - group: %Schema{ - type: :string, - description: "Check Group, available when requiring a Flat Catalog" - }, - provider: Provider.SupportedProviders - } - }) + OpenApiSpex.schema( + %{ + title: "Check", + description: "An available check to be executed on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Check ID", format: :uuid}, + name: %Schema{type: :string, description: "Check Name"}, + description: %Schema{type: :string, description: "Check Description"}, + remediation: %Schema{type: :string, description: "Check Remediation"}, + implementation: %Schema{type: :string, description: "Check Implementation"}, + labels: %Schema{type: :string, description: "Check Labels"}, + premium: %Schema{ + type: :boolean, + description: "Indicates whether the current check is a Premium check" + }, + group: %Schema{ + type: :string, + description: "Check Group, available when requiring a Flat Catalog" + }, + provider: Provider.SupportedProviders + } + }, + struct?: false + ) end defmodule FlatCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "FlatCatalog", - description: "A flat list of the available Checks", - type: :array, - items: Check - }) + OpenApiSpex.schema( + %{ + title: "FlatCatalog", + description: "A flat list of the available Checks", + type: :array, + items: Check + }, + struct?: false + ) end defmodule ChecksGroup do @moduledoc false - OpenApiSpex.schema(%{ - title: "ChecksGroup", - description: "A Group of related Checks (Corosync, Pacemaker ...)", - additionalProperties: false, - type: :object, - properties: %{ - group: %Schema{type: :string, description: "Group Name"}, - checks: FlatCatalog - } - }) + OpenApiSpex.schema( + %{ + title: "ChecksGroup", + description: "A Group of related Checks (Corosync, Pacemaker ...)", + additionalProperties: false, + type: :object, + properties: %{ + group: %Schema{type: :string, description: "Group Name"}, + checks: FlatCatalog + } + }, + struct?: false + ) end defmodule ProviderCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "ProviderCatalog", - description: "A Provider specific Catalog, and respective values", - additionalProperties: false, - type: :object, - properties: %{ - provider: %Schema{ - title: "ChecksProvider", - type: :string, - description: - "The provider determining the values for the attached checks (azure, aws ...)", - enum: [:azure, :aws, :gcp, :default] - }, - groups: %Schema{ - title: "ChecksGroups", - description: "A list of ChecksGroup for the respective provider", - type: :array, - items: ChecksGroup + OpenApiSpex.schema( + %{ + title: "ProviderCatalog", + description: "A Provider specific Catalog, and respective values", + additionalProperties: false, + type: :object, + properties: %{ + provider: %Schema{ + title: "ChecksProvider", + type: :string, + description: + "The provider determining the values for the attached checks (azure, aws ...)", + enum: [:azure, :aws, :gcp, :default] + }, + groups: %Schema{ + title: "ChecksGroups", + description: "A list of ChecksGroup for the respective provider", + type: :array, + items: ChecksGroup + } } - } - }) + }, + struct?: false + ) end defmodule GroupedCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "GroupedCatalog", - description: - "A list of available Checks: grouped by provider (azure, aws ...) and checks groups (Corosync, Pacemaker ...)", - type: :array, - items: ProviderCatalog - }) + OpenApiSpex.schema( + %{ + title: "GroupedCatalog", + description: + "A list of available Checks: grouped by provider (azure, aws ...) and checks groups (Corosync, Pacemaker ...)", + type: :array, + items: ProviderCatalog + }, + struct?: false + ) end defmodule Catalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "ChecksCatalog", - description: "A representation of the Checks Catalog", - oneOf: [ - GroupedCatalog, - FlatCatalog - ], - example: [ - %{ - groups: [ - %{ - checks: [ - %{ - description: "Corosync `token` timeout is set to `5000`\n", - id: "156F64", - implementation: - "---\n\n- name: \"{{ name }}.check\"\n lineinfile:\n path: /etc/corosync/corosync.conf\n regexp: '^(\\s+){{ key_name }}:'\n line: \"\\t{{ key_name }}: {{ expected[name] }}\"\n insertafter: 'totem {'\n register: config_updated\n when:\n - ansible_check_mode\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", - labels: "generic", - name: "1.1.1", - premium: false, - remediation: - "## Abstract\nThe value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" - }, - %{ - description: "Corosync is running with `token` timeout set to `5000`\n", - id: "53D035", - implementation: - "---\n\n- name: \"{{ name }}.check\"\n shell: 'corosync-cmapctl | grep \"runtime.config.totem.token (u32) = \" | sed \"s/^.*= //\"'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected['1.1.1']\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", - labels: "generic", - name: "1.1.1.runtime", - premium: false, - remediation: - "## Abstract\nThe runtime value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" - } - ], - group: "Corosync" - }, - %{ - checks: [ - %{ - description: "Fencing is enabled in the cluster attributes\n", - id: "205AF7", - implementation: - "---\n\n- name: \"{{ name }}.check\"\n command: 'crm_attribute -t crm_config -G -n stonith-enabled --quiet'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected[name]\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", - labels: "generic", - name: "1.2.1", - premium: false, - remediation: - "## Abstract\nFencing is mandatory to guarantee data integrity for your SAP Applications.\nRunning a HA Cluster without fencing is not supported and might cause data loss.\n\n## Remediation\nExecute the following command to enable it:\n```\ncrm configure property stonith-enabled=true\n```\n\n## References\n- https://documentation.suse.com/sle-ha/15-SP3/html/SLE-HA-all/cha-ha-fencing.html#sec-ha-fencing-recommend\n" - } - ], - group: "Pacemaker" - } - ], - provider: "aws" - } - ] - }) + OpenApiSpex.schema( + %{ + title: "ChecksCatalog", + description: "A representation of the Checks Catalog", + oneOf: [ + GroupedCatalog, + FlatCatalog + ], + example: [ + %{ + groups: [ + %{ + checks: [ + %{ + description: "Corosync `token` timeout is set to `5000`\n", + id: "156F64", + implementation: + "---\n\n- name: \"{{ name }}.check\"\n lineinfile:\n path: /etc/corosync/corosync.conf\n regexp: '^(\\s+){{ key_name }}:'\n line: \"\\t{{ key_name }}: {{ expected[name] }}\"\n insertafter: 'totem {'\n register: config_updated\n when:\n - ansible_check_mode\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", + labels: "generic", + name: "1.1.1", + premium: false, + remediation: + "## Abstract\nThe value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" + }, + %{ + description: "Corosync is running with `token` timeout set to `5000`\n", + id: "53D035", + implementation: + "---\n\n- name: \"{{ name }}.check\"\n shell: 'corosync-cmapctl | grep \"runtime.config.totem.token (u32) = \" | sed \"s/^.*= //\"'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected['1.1.1']\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", + labels: "generic", + name: "1.1.1.runtime", + premium: false, + remediation: + "## Abstract\nThe runtime value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" + } + ], + group: "Corosync" + }, + %{ + checks: [ + %{ + description: "Fencing is enabled in the cluster attributes\n", + id: "205AF7", + implementation: + "---\n\n- name: \"{{ name }}.check\"\n command: 'crm_attribute -t crm_config -G -n stonith-enabled --quiet'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected[name]\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", + labels: "generic", + name: "1.2.1", + premium: false, + remediation: + "## Abstract\nFencing is mandatory to guarantee data integrity for your SAP Applications.\nRunning a HA Cluster without fencing is not supported and might cause data loss.\n\n## Remediation\nExecute the following command to enable it:\n```\ncrm configure property stonith-enabled=true\n```\n\n## References\n- https://documentation.suse.com/sle-ha/15-SP3/html/SLE-HA-all/cha-ha-fencing.html#sec-ha-fencing-recommend\n" + } + ], + group: "Pacemaker" + } + ], + provider: "aws" + } + ] + }, + struct?: false + ) end defmodule CatalogNotfound do @moduledoc false - OpenApiSpex.schema(%{ - title: "CatalogNotfound", - description: "No Catalog was found for the provided query", - additionalProperties: false, - type: :object, - properties: %{ - error: %Schema{ - type: :string, - enum: [:not_found] - } + OpenApiSpex.schema( + %{ + title: "CatalogNotfound", + description: "No Catalog was found for the provided query", + additionalProperties: false, + type: :object, + properties: %{ + error: %Schema{ + type: :string, + enum: [:not_found] + } + }, + example: %{error: "not_found"} }, - example: %{error: "not_found"} - }) + struct?: false + ) end defmodule UnableToLoadCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "UnableToLoadCatalog", - description: "Something wrong happened while loading the catalog. ie: it is not ready yet", - additionalProperties: false, - type: :object, - properties: %{ - error: %Schema{type: :string, description: "The error message"} + OpenApiSpex.schema( + %{ + title: "UnableToLoadCatalog", + description: + "Something wrong happened while loading the catalog. ie: it is not ready yet", + additionalProperties: false, + type: :object, + properties: %{ + error: %Schema{type: :string, description: "The error message"} + }, + example: %{error: "(not_ready|some other error message)"} }, - example: %{error: "(not_ready|some other error message)"} - }) + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/cluster.ex b/lib/trento_web/openapi/v1/schema/cluster.ex index 9d13f5ef23..9729deb260 100644 --- a/lib/trento_web/openapi/v1/schema/cluster.ex +++ b/lib/trento_web/openapi/v1/schema/cluster.ex @@ -10,164 +10,189 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do defmodule ClusterResource do @moduledoc false - OpenApiSpex.schema(%{ - title: "ClusterResource", - description: "A Cluster Resource", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string}, - type: %Schema{type: :string}, - role: %Schema{type: :string}, - status: %Schema{type: :string}, - fail_count: %Schema{type: :integer} - } - }) + OpenApiSpex.schema( + %{ + title: "ClusterResource", + description: "A Cluster Resource", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string}, + type: %Schema{type: :string}, + role: %Schema{type: :string}, + status: %Schema{type: :string}, + fail_count: %Schema{type: :integer} + } + }, + struct?: false + ) end defmodule HanaClusterNode do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterNode", - description: "A HANA Cluster Node", - additionalProperties: false, - type: :object, - properties: %{ - name: %Schema{type: :string}, - site: %Schema{type: :string}, - hana_status: %Schema{type: :string}, - attributes: %Schema{ - type: :object, - description: "Node attributes", - additionalProperties: %Schema{type: :string} - }, - virtual_ip: %Schema{type: :string}, - resources: %Schema{ - description: "A list of Cluster resources", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterNode", + description: "A HANA Cluster Node", + additionalProperties: false, + type: :object, + properties: %{ + name: %Schema{type: :string}, + site: %Schema{type: :string}, + hana_status: %Schema{type: :string}, + attributes: %Schema{ + type: :object, + description: "Node attributes", + additionalProperties: %Schema{type: :string} + }, + virtual_ip: %Schema{type: :string}, + resources: %Schema{ + description: "A list of Cluster resources", + type: :array, + items: ClusterResource + } } - } - }) + }, + struct?: false + ) end defmodule SbdDevice do @moduledoc false - OpenApiSpex.schema(%{ - title: "SbdDevice", - description: "SBD Device", - additionalProperties: false, - type: :object, - properties: %{ - device: %Schema{type: :string}, - status: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "SbdDevice", + description: "SBD Device", + additionalProperties: false, + type: :object, + properties: %{ + device: %Schema{type: :string}, + status: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule HanaClusterDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterDetails", - description: "Details of a HANA Pacemaker Cluster", - type: :object, - additionalProperties: false, - properties: %{ - system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, - system_replication_operation_mode: %Schema{ - type: :string, - description: "System Replication Operation Mode" - }, - secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, - sr_health_state: %Schema{type: :string, description: "SR health state"}, - fencing_type: %Schema{type: :string, description: "Fencing Type"}, - stopped_resources: %Schema{ - description: "A list of the stopped resources on this HANA Cluster", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterDetails", + description: "Details of a HANA Pacemaker Cluster", + type: :object, + additionalProperties: false, + properties: %{ + system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, + system_replication_operation_mode: %Schema{ + type: :string, + description: "System Replication Operation Mode" + }, + secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, + sr_health_state: %Schema{type: :string, description: "SR health state"}, + fencing_type: %Schema{type: :string, description: "Fencing Type"}, + stopped_resources: %Schema{ + description: "A list of the stopped resources on this HANA Cluster", + type: :array, + items: ClusterResource + }, + nodes: %Schema{ + type: :array, + items: HanaClusterNode + }, + sbd_devices: %Schema{ + type: :array, + items: SbdDevice + } }, - nodes: %Schema{ - type: :array, - items: HanaClusterNode - }, - sbd_devices: %Schema{ - type: :array, - items: SbdDevice - } + required: [:nodes] }, - required: [:nodes] - }) + struct?: false + ) end defmodule Details do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClusterDetails", - description: "Details of the detected PacemakerCluster", - nullable: true, - oneOf: [ - HanaClusterDetails - ] - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClusterDetails", + description: "Details of the detected PacemakerCluster", + nullable: true, + oneOf: [ + HanaClusterDetails + ] + }, + struct?: false + ) end defmodule PacemakerCluster do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerCluster", - description: "A discovered Pacemaker Cluster on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, - name: %Schema{type: :string, description: "Cluster name"}, - sid: %Schema{type: :string, description: "SID"}, - additional_sids: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" - }, - provider: Provider.SupportedProviders, - type: %Schema{ - type: :string, - description: "Detected type of the cluster", - enum: [:hana_scale_up, :hana_scale_out, :unknown] - }, - selected_checks: %Schema{ - title: "SelectedChecks", - description: "A list of check ids selected for an execution on this cluster", - type: :array, - items: %Schema{type: :string} - }, - health: ResourceHealth, - resources_number: %Schema{type: :integer, description: "Resource number", nullable: true}, - hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, - cib_last_written: %Schema{ - type: :string, - description: "CIB last written date", - nullable: true - }, - details: Details, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "PacemakerCluster", + description: "A discovered Pacemaker Cluster on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, + name: %Schema{type: :string, description: "Cluster name"}, + sid: %Schema{type: :string, description: "SID"}, + additional_sids: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" + }, + provider: Provider.SupportedProviders, + type: %Schema{ + type: :string, + description: "Detected type of the cluster", + enum: [:hana_scale_up, :hana_scale_out, :unknown] + }, + selected_checks: %Schema{ + title: "SelectedChecks", + description: "A list of check ids selected for an execution on this cluster", + type: :array, + items: %Schema{type: :string} + }, + health: ResourceHealth, + resources_number: %Schema{ + type: :integer, + description: "Resource number", + nullable: true + }, + hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, + cib_last_written: %Schema{ + type: :string, + description: "CIB last written date", + nullable: true + }, + details: Details, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule PacemakerClustersCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClustersCollection", - description: "A list of the discovered Pacemaker Clusters", - type: :array, - items: PacemakerCluster - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClustersCollection", + description: "A list of the discovered Pacemaker Clusters", + type: :array, + items: PacemakerCluster + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/database.ex b/lib/trento_web/openapi/v1/schema/database.ex index b2123f2c02..1afd68ac53 100644 --- a/lib/trento_web/openapi/v1/schema/database.ex +++ b/lib/trento_web/openapi/v1/schema/database.ex @@ -9,98 +9,110 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do defmodule DatabaseInstance do @moduledoc false - OpenApiSpex.schema(%{ - title: "DatabaseInstance", - description: "A discovered HANA Database Instance on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - sap_system_id: %Schema{ - type: :string, - description: "SAP System ID", - format: :uuid, - deprecated: true - }, - database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - tenant: %Schema{type: :string, description: "Tenant"}, - instance_number: %Schema{type: :string, description: "Instance Number"}, - instance_hostname: %Schema{ - type: :string, - description: "Instance Hostname", - nullable: true - }, - features: %Schema{type: :string, description: "Instance Features"}, - http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, - https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, - start_priority: %Schema{ - type: :string, - description: "Instance Start Priority", - nullable: true - }, - host_id: %Schema{ - type: :string, - description: "Identifier of the host where current instance is running", - format: :uuid - }, - system_replication: %Schema{type: :string, description: "System Replication"}, - system_replication_status: %Schema{ - type: :string, - description: "System Replication Status" - }, - health: ResourceHealth, - absent_at: %Schema{ - type: :string, - description: "Absent instance timestamp", - format: :datetime, - nullable: true - }, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "DatabaseInstance", + description: "A discovered HANA Database Instance on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + sap_system_id: %Schema{ + type: :string, + description: "SAP System ID", + format: :uuid, + deprecated: true + }, + database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + tenant: %Schema{type: :string, description: "Tenant"}, + instance_number: %Schema{type: :string, description: "Instance Number"}, + instance_hostname: %Schema{ + type: :string, + description: "Instance Hostname", + nullable: true + }, + features: %Schema{type: :string, description: "Instance Features"}, + http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, + https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, + start_priority: %Schema{ + type: :string, + description: "Instance Start Priority", + nullable: true + }, + host_id: %Schema{ + type: :string, + description: "Identifier of the host where current instance is running", + format: :uuid + }, + system_replication: %Schema{type: :string, description: "System Replication"}, + system_replication_status: %Schema{ + type: :string, + description: "System Replication Status" + }, + health: ResourceHealth, + absent_at: %Schema{ + type: :string, + description: "Absent instance timestamp", + format: :datetime, + nullable: true + }, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule DatabaseInstances do @moduledoc false - OpenApiSpex.schema(%{ - title: "DatabaseInstances", - description: - "A list of DatabaseInstances, part of a complete SAP System, or only a HANA Database", - type: :array, - items: DatabaseInstance - }) + OpenApiSpex.schema( + %{ + title: "DatabaseInstances", + description: + "A list of DatabaseInstances, part of a complete SAP System, or only a HANA Database", + type: :array, + items: DatabaseInstance + }, + struct?: false + ) end defmodule DatabaseItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "Database", - description: "A discovered HANA Database on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Database ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - health: ResourceHealth, - database_instances: DatabaseInstances, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "Database", + description: "A discovered HANA Database on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Database ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + health: ResourceHealth, + database_instances: DatabaseInstances, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule DatabasesCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "DatabasesCollection", - description: "A list of the discovered HANA Databases", - type: :array, - items: DatabaseItem - }) + OpenApiSpex.schema( + %{ + title: "DatabasesCollection", + description: "A list of the discovered HANA Databases", + type: :array, + items: DatabaseItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/discovery_event.ex b/lib/trento_web/openapi/v1/schema/discovery_event.ex index ea1365a4b1..56135d4b2f 100644 --- a/lib/trento_web/openapi/v1/schema/discovery_event.ex +++ b/lib/trento_web/openapi/v1/schema/discovery_event.ex @@ -5,19 +5,22 @@ defmodule TrentoWeb.OpenApi.V1.Schema.DiscoveryEvent do require OpenApiSpex - OpenApiSpex.schema(%{ - title: "DiscoveryEvent", - description: "A discovery event", - type: :object, - additionalProperties: false, - properties: %{ - agent_id: %Schema{type: :string, format: :uuid}, - discovery_type: %Schema{type: :string}, - payload: %Schema{ - nullable: true, - oneOf: [%Schema{type: :object}, %Schema{type: :array}] - } + OpenApiSpex.schema( + %{ + title: "DiscoveryEvent", + description: "A discovery event", + type: :object, + additionalProperties: false, + properties: %{ + agent_id: %Schema{type: :string, format: :uuid}, + discovery_type: %Schema{type: :string}, + payload: %Schema{ + nullable: true, + oneOf: [%Schema{type: :object}, %Schema{type: :array}] + } + }, + required: [:agent_id, :discovery_type, :payload] }, - required: [:agent_id, :discovery_type, :payload] - }) + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/forbidden.ex b/lib/trento_web/openapi/v1/schema/forbidden.ex index 76d284bfc7..7f11840542 100644 --- a/lib/trento_web/openapi/v1/schema/forbidden.ex +++ b/lib/trento_web/openapi/v1/schema/forbidden.ex @@ -7,26 +7,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Forbidden do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "Forbidden", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "The requested operation could not be performed." - }, - title: %Schema{type: :string, example: "Forbidden"} + OpenApiSpex.schema( + %{ + title: "Forbidden", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "The requested operation could not be performed." + }, + title: %Schema{type: :string, example: "Forbidden"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/health.ex b/lib/trento_web/openapi/v1/schema/health.ex index d1617f1eae..12a3f58206 100644 --- a/lib/trento_web/openapi/v1/schema/health.ex +++ b/lib/trento_web/openapi/v1/schema/health.ex @@ -7,21 +7,24 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Health do require OpenApiSpex - OpenApiSpex.schema(%Schema{ - title: "Health", - type: :object, - example: %{ - database: "pass" - }, - additionalProperties: false, - properties: %{ - database: %Schema{ - description: "The status of the database connection", - type: :string, - enum: ["pass", "fail"] + OpenApiSpex.schema( + %Schema{ + title: "Health", + type: :object, + example: %{ + database: "pass" + }, + additionalProperties: false, + properties: %{ + database: %Schema{ + description: "The status of the database connection", + type: :string, + enum: ["pass", "fail"] + } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/host.ex b/lib/trento_web/openapi/v1/schema/host.ex index a74492fad7..b4199d3b9d 100644 --- a/lib/trento_web/openapi/v1/schema/host.ex +++ b/lib/trento_web/openapi/v1/schema/host.ex @@ -15,104 +15,116 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do defmodule IPv4 do @moduledoc false - OpenApiSpex.schema(%{ - title: "IPv4", - type: :string, - format: :ipv4 - }) + OpenApiSpex.schema( + %{ + title: "IPv4", + type: :string, + format: :ipv4 + }, + struct?: false + ) end defmodule IPv6 do @moduledoc false - OpenApiSpex.schema(%{ - title: "IPv6", - type: :string, - format: :ipv6 - }) + OpenApiSpex.schema( + %{ + title: "IPv6", + type: :string, + format: :ipv6 + }, + struct?: false + ) end defmodule HostItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "Host", - description: "A discovered host on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Host ID", format: :uuid}, - hostname: %Schema{type: :string, description: "Host name"}, - ip_addresses: %Schema{ - type: :array, - description: "IP addresses", - items: %Schema{ - title: "IPAddress", - anyOf: [ - IPv4, - IPv6 - ] - } - }, - agent_version: %Schema{ - type: :string, - description: "Version of the agent installed on the host" - }, - health: ResourceHealth, - cluster_id: %Schema{ - type: :string, - description: "Identifier of the cluster this host is part of", - format: :uuid - }, - heartbeat: %Schema{ - type: :string, - description: "Host's last heartbeat status", - enum: [:critical, :passing, :unknown] - }, - provider: Provider.SupportedProviders, - provider_data: Provider.ProviderData, - tags: Tags, - sles_subscriptions: %Schema{ - title: "SlesSubscriptions", - description: "A list of the available SLES Subscriptions on a host", - type: :array, - items: SlesSubscription - }, - selected_checks: %Schema{ - title: "SelectedChecks", - description: "A list of check ids selected for an execution on this host", - type: :array, - items: %Schema{type: :string} - }, - saptune_status: SaptuneStatus, - deregistered_at: %Schema{ - title: "DeregisteredAt", - description: "Timestamp of the last deregistration of the host", - type: :string, - nullable: true, - format: :"date-time" - }, - last_heartbeat_timestamp: %Schema{ - title: "LastHeartbeatTimestamp", - description: "Timestamp of the last heartbeat received from the host", - type: :string, - nullable: true, - format: :"date-time" - }, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "Host", + description: "A discovered host on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Host ID", format: :uuid}, + hostname: %Schema{type: :string, description: "Host name"}, + ip_addresses: %Schema{ + type: :array, + description: "IP addresses", + items: %Schema{ + title: "IPAddress", + anyOf: [ + IPv4, + IPv6 + ] + } + }, + agent_version: %Schema{ + type: :string, + description: "Version of the agent installed on the host" + }, + health: ResourceHealth, + cluster_id: %Schema{ + type: :string, + description: "Identifier of the cluster this host is part of", + format: :uuid + }, + heartbeat: %Schema{ + type: :string, + description: "Host's last heartbeat status", + enum: [:critical, :passing, :unknown] + }, + provider: Provider.SupportedProviders, + provider_data: Provider.ProviderData, + tags: Tags, + sles_subscriptions: %Schema{ + title: "SlesSubscriptions", + description: "A list of the available SLES Subscriptions on a host", + type: :array, + items: SlesSubscription + }, + selected_checks: %Schema{ + title: "SelectedChecks", + description: "A list of check ids selected for an execution on this host", + type: :array, + items: %Schema{type: :string} + }, + saptune_status: SaptuneStatus, + deregistered_at: %Schema{ + title: "DeregisteredAt", + description: "Timestamp of the last deregistration of the host", + type: :string, + nullable: true, + format: :"date-time" + }, + last_heartbeat_timestamp: %Schema{ + title: "LastHeartbeatTimestamp", + description: "Timestamp of the last heartbeat received from the host", + type: :string, + nullable: true, + format: :"date-time" + }, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule HostsCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "HostsCollection", - description: "A list of the discovered hosts", - type: :array, - items: HostItem - }) + OpenApiSpex.schema( + %{ + title: "HostsCollection", + description: "A list of the discovered hosts", + type: :array, + items: HostItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/http_std.ex b/lib/trento_web/openapi/v1/schema/http_std.ex index fb47b534ee..a40fa72b2b 100644 --- a/lib/trento_web/openapi/v1/schema/http_std.ex +++ b/lib/trento_web/openapi/v1/schema/http_std.ex @@ -7,58 +7,64 @@ defmodule TrentoWeb.OpenApi.V1.Schema.HttpStd do defmodule Target do @moduledoc false - OpenApiSpex.schema(%{ - title: "HttpStd", - type: :object, - example: %{ - "targets" => ["myhost.de"], - "labels" => %{ - "labelname" => "mylabel" - } - }, - additionalProperties: false, - properties: %{ - labels: %Schema{ - type: :object, - description: "String valued labels", - additionalProperties: %Schema{type: :string} + OpenApiSpex.schema( + %{ + title: "HttpStd", + type: :object, + example: %{ + "targets" => ["myhost.de"], + "labels" => %{ + "labelname" => "mylabel" + } }, - targets: %Schema{ - type: :array, - description: "List of targets", - items: %Schema{ - title: "Targets", - anyOf: [ - %Schema{ - title: "IPv6", - type: :string, - format: :ipv6 - }, - %Schema{ - title: "IPv4", - type: :string, - format: :ipv4 - }, - %Schema{ - title: "Hostname", - type: :string, - format: :hostname - } - ] + additionalProperties: false, + properties: %{ + labels: %Schema{ + type: :object, + description: "String valued labels", + additionalProperties: %Schema{type: :string} + }, + targets: %Schema{ + type: :array, + description: "List of targets", + items: %Schema{ + title: "Targets", + anyOf: [ + %Schema{ + title: "IPv6", + type: :string, + format: :ipv6 + }, + %Schema{ + title: "IPv4", + type: :string, + format: :ipv4 + }, + %Schema{ + title: "Hostname", + type: :string, + format: :hostname + } + ] + } } } - } - }) + }, + struct?: false + ) end defmodule TargetList do @moduledoc false - OpenApiSpex.schema(%{ - title: "HttpSTDTargetList", - description: "Http discovery target list", - type: :array, - items: Target - }) + OpenApiSpex.schema( + %{ + title: "HttpSTDTargetList", + description: "Http discovery target list", + type: :array, + items: Target + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/not_found.ex b/lib/trento_web/openapi/v1/schema/not_found.ex index 4e6c07f04a..e21523a522 100644 --- a/lib/trento_web/openapi/v1/schema/not_found.ex +++ b/lib/trento_web/openapi/v1/schema/not_found.ex @@ -7,23 +7,26 @@ defmodule TrentoWeb.OpenApi.V1.Schema.NotFound do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "NotFound", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{type: :string, example: "The requested resource cannot be found."}, - title: %Schema{type: :string, example: "Not Found"} + OpenApiSpex.schema( + %{ + title: "NotFound", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{type: :string, example: "The requested resource cannot be found."}, + title: %Schema{type: :string, example: "Not Found"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/platform.ex b/lib/trento_web/openapi/v1/schema/platform.ex index 91da64e8d8..bde0698d70 100644 --- a/lib/trento_web/openapi/v1/schema/platform.ex +++ b/lib/trento_web/openapi/v1/schema/platform.ex @@ -7,137 +7,155 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Platform do defmodule Settings do @moduledoc false - OpenApiSpex.schema(%{ - title: "PlatformSettings", - description: "Settings values for the current installation", - type: :object, - additionalProperties: false, - properties: %{ - eula_accepted: %Schema{ - type: :boolean, - description: "Whether the user has accepted EULA (on a Premium installation)", - deprecated: true - }, - premium_subscription: %Schema{ - type: :boolean, - description: "Whether current installation is a Premium one" + OpenApiSpex.schema( + %{ + title: "PlatformSettings", + description: "Settings values for the current installation", + type: :object, + additionalProperties: false, + properties: %{ + eula_accepted: %Schema{ + type: :boolean, + description: "Whether the user has accepted EULA (on a Premium installation)", + deprecated: true + }, + premium_subscription: %Schema{ + type: :boolean, + description: "Whether current installation is a Premium one" + } } - } - }) + }, + struct?: false + ) end defmodule ApiKeySettings do @moduledoc false - OpenApiSpex.schema(%{ - title: "ApiKeySettings", - description: "Settings for Api Key generation", - type: :object, - additionalProperties: false, - properties: %{ - created_at: %Schema{ - type: :string, - format: :"date-time", - description: "The creation date of api key" - }, - generated_api_key: %Schema{ - type: :string, - description: "The generated api key from api key settings" + OpenApiSpex.schema( + %{ + title: "ApiKeySettings", + description: "Settings for Api Key generation", + type: :object, + additionalProperties: false, + properties: %{ + created_at: %Schema{ + type: :string, + format: :"date-time", + description: "The creation date of api key" + }, + generated_api_key: %Schema{ + type: :string, + description: "The generated api key from api key settings" + }, + expire_at: %Schema{ + type: :string, + format: :"date-time", + description: "The expire date of api key", + nullable: true + } }, - expire_at: %Schema{ - type: :string, - format: :"date-time", - description: "The expire date of api key", - nullable: true - } + required: [:generated_api_key, :expire_at, :created_at] }, - required: [:generated_api_key, :expire_at, :created_at] - }) + struct?: false + ) end defmodule ApiKeySettingsUpdateRequest do @moduledoc false - OpenApiSpex.schema(%{ - title: "ApiKeySettingsUpdateRequest", - description: "Request body for api key settings update", - type: :object, - additionalProperties: false, - properties: %{ - expire_at: %Schema{ - type: :string, - format: :"date-time", - description: "The expire date of api key", - nullable: true - } + OpenApiSpex.schema( + %{ + title: "ApiKeySettingsUpdateRequest", + description: "Request body for api key settings update", + type: :object, + additionalProperties: false, + properties: %{ + expire_at: %Schema{ + type: :string, + format: :"date-time", + description: "The expire date of api key", + nullable: true + } + }, + required: [:expire_at] }, - required: [:expire_at] - }) + struct?: false + ) end defmodule GeneralInformation do @moduledoc false - OpenApiSpex.schema(%{ - title: "GeneralInformation", - description: "General information about the current installation", - type: :object, - additionalProperties: false, - properties: %{ - flavor: %Schema{ - type: :string, - description: "Flavor of the current installation", - enum: ["Community", "Premium"] - }, - version: %Schema{ - type: :string, - description: "Version of the current server component installation" - }, - sles_subscriptions: %Schema{ - type: :integer, - description: "The number of SLES Subscription discovered on the target infrastructure" + OpenApiSpex.schema( + %{ + title: "GeneralInformation", + description: "General information about the current installation", + type: :object, + additionalProperties: false, + properties: %{ + flavor: %Schema{ + type: :string, + description: "Flavor of the current installation", + enum: ["Community", "Premium"] + }, + version: %Schema{ + type: :string, + description: "Version of the current server component installation" + }, + sles_subscriptions: %Schema{ + type: :integer, + description: "The number of SLES Subscription discovered on the target infrastructure" + } } - } - }) + }, + struct?: false + ) end defmodule RetentionTimeSettings do @moduledoc false - OpenApiSpex.schema(%{ - title: "RetentionTimeSettings", - description: "Retention Time settings of the Activity Log", - type: :object, - additionalProperties: false, - properties: %{ - value: %Schema{ - type: :integer, - description: - "The integer retention duration, that is used in conjunction with the retention time unit.", - minimum: 1 + OpenApiSpex.schema( + %{ + title: "RetentionTimeSettings", + description: "Retention Time settings of the Activity Log", + type: :object, + additionalProperties: false, + properties: %{ + value: %Schema{ + type: :integer, + description: + "The integer retention duration, that is used in conjunction with the retention time unit.", + minimum: 1 + }, + unit: %Schema{ + type: :string, + description: + "The retention duration unit, that is used in conjunction with the retention time period.", + enum: [:day, :week, :month, :year] + } }, - unit: %Schema{ - type: :string, - description: - "The retention duration unit, that is used in conjunction with the retention time period.", - enum: [:day, :week, :month, :year] - } + required: [:value, :unit] }, - required: [:value, :unit] - }) + struct?: false + ) end defmodule ActivityLogSettings do @moduledoc false - OpenApiSpex.schema(%{ - title: "ActivityLogSettings", - description: "Activity Log settings of the current installation", - type: :object, - additionalProperties: false, - properties: %{ - retention_time: RetentionTimeSettings + OpenApiSpex.schema( + %{ + title: "ActivityLogSettings", + description: "Activity Log settings of the current installation", + type: :object, + additionalProperties: false, + properties: %{ + retention_time: RetentionTimeSettings + }, + required: [:retention_time] }, - required: [:retention_time] - }) + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/precondition_failed.ex b/lib/trento_web/openapi/v1/schema/precondition_failed.ex index 5f0aef0835..8f0ebb436f 100644 --- a/lib/trento_web/openapi/v1/schema/precondition_failed.ex +++ b/lib/trento_web/openapi/v1/schema/precondition_failed.ex @@ -7,27 +7,30 @@ defmodule TrentoWeb.OpenApi.V1.Schema.PreconditionFailed do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "PreconditionFailed", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: - "Mid-air collision detected, please refresh the resource you are trying to update." - }, - title: %Schema{type: :string, example: "Precondition Failed"} + OpenApiSpex.schema( + %{ + title: "PreconditionFailed", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: + "Mid-air collision detected, please refresh the resource you are trying to update." + }, + title: %Schema{type: :string, example: "Precondition Failed"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/precondition_required.ex b/lib/trento_web/openapi/v1/schema/precondition_required.ex index 6064cd6894..50d929e3a9 100644 --- a/lib/trento_web/openapi/v1/schema/precondition_required.ex +++ b/lib/trento_web/openapi/v1/schema/precondition_required.ex @@ -7,26 +7,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.PreconditionRequired do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "PreconditionRequired", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "Request needs to be conditional, please provide If-Match header." - }, - title: %Schema{type: :string, example: "Precondition Required"} + OpenApiSpex.schema( + %{ + title: "PreconditionRequired", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "Request needs to be conditional, please provide If-Match header." + }, + title: %Schema{type: :string, example: "Precondition Required"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/prometheus.ex b/lib/trento_web/openapi/v1/schema/prometheus.ex index cbebbfa06c..0d8761d912 100644 --- a/lib/trento_web/openapi/v1/schema/prometheus.ex +++ b/lib/trento_web/openapi/v1/schema/prometheus.ex @@ -7,18 +7,21 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Prometheus do defmodule ExporterStatus do @moduledoc false - OpenApiSpex.schema(%{ - title: "PrometheusExporterStatus", - type: :object, - example: %{ - "Node exporter" => "critical" + OpenApiSpex.schema( + %{ + title: "PrometheusExporterStatus", + type: :object, + example: %{ + "Node exporter" => "critical" + }, + additionalProperties: %Schema{ + enum: [:critical, :passing, :unknown], + description: + "Status of the exporter, the value could be one of passing, critical, unknown", + type: :string + } }, - additionalProperties: %Schema{ - enum: [:critical, :passing, :unknown], - description: - "Status of the exporter, the value could be one of passing, critical, unknown", - type: :string - } - }) + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/provider.ex b/lib/trento_web/openapi/v1/schema/provider.ex index d282b96414..4b484804c0 100644 --- a/lib/trento_web/openapi/v1/schema/provider.ex +++ b/lib/trento_web/openapi/v1/schema/provider.ex @@ -9,98 +9,116 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do defmodule SupportedProviders do @moduledoc false - OpenApiSpex.schema(%{ - title: "SupportedProviders", - type: :string, - description: "Detected Provider where the resource is running", - enum: Provider.values() - }) + OpenApiSpex.schema( + %{ + title: "SupportedProviders", + type: :string, + description: "Detected Provider where the resource is running", + enum: Provider.values() + }, + struct?: false + ) end defmodule FilterableProviders do @moduledoc false - OpenApiSpex.schema(%{ - title: "FilterableProvider", - type: :string, - description: "A provider that can be used to filter the Catalog", - enum: [:azure, :aws, :gcp, :default] - }) + OpenApiSpex.schema( + %{ + title: "FilterableProvider", + type: :string, + description: "A provider that can be used to filter the Catalog", + enum: [:azure, :aws, :gcp, :default] + }, + struct?: false + ) end defmodule AzureProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "AzureProviderData", - description: "Azure detected metadata", - type: :object, - additionalProperties: false, - properties: %{ - resource_group: %Schema{type: :string}, - location: %Schema{type: :string}, - vm_size: %Schema{type: :string}, - data_disk_number: %Schema{type: :integer}, - offer: %Schema{type: :string}, - sku: %Schema{type: :string}, - admin_username: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "AzureProviderData", + description: "Azure detected metadata", + type: :object, + additionalProperties: false, + properties: %{ + resource_group: %Schema{type: :string}, + location: %Schema{type: :string}, + vm_size: %Schema{type: :string}, + data_disk_number: %Schema{type: :integer}, + offer: %Schema{type: :string}, + sku: %Schema{type: :string}, + admin_username: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule AwsProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "AwsProviderData", - description: "AWS detected metadata", - type: :object, - additionalProperties: false, - properties: %{ - account_id: %Schema{type: :string}, - ami_id: %Schema{type: :string}, - availability_zone: %Schema{type: :string}, - data_disk_number: %Schema{type: :integer}, - instance_id: %Schema{type: :string}, - instance_type: %Schema{type: :string}, - region: %Schema{type: :string}, - vpc_id: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "AwsProviderData", + description: "AWS detected metadata", + type: :object, + additionalProperties: false, + properties: %{ + account_id: %Schema{type: :string}, + ami_id: %Schema{type: :string}, + availability_zone: %Schema{type: :string}, + data_disk_number: %Schema{type: :integer}, + instance_id: %Schema{type: :string}, + instance_type: %Schema{type: :string}, + region: %Schema{type: :string}, + vpc_id: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule GcpProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "GcpProviderData", - description: "GCP detected metadata", - type: :object, - additionalProperties: false, - properties: %{ - disk_number: %Schema{type: :integer}, - image: %Schema{type: :string}, - instance_name: %Schema{type: :string}, - machine_type: %Schema{type: :string}, - network: %Schema{type: :string}, - project_id: %Schema{type: :string}, - zone: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "GcpProviderData", + description: "GCP detected metadata", + type: :object, + additionalProperties: false, + properties: %{ + disk_number: %Schema{type: :integer}, + image: %Schema{type: :string}, + instance_name: %Schema{type: :string}, + machine_type: %Schema{type: :string}, + network: %Schema{type: :string}, + project_id: %Schema{type: :string}, + zone: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule ProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "ProviderMetadata", - nullable: true, - description: "Detected metadata for any provider", - oneOf: [ - AwsProviderData, - AzureProviderData, - GcpProviderData - ] - }) + OpenApiSpex.schema( + %{ + title: "ProviderMetadata", + nullable: true, + description: "Detected metadata for any provider", + oneOf: [ + AwsProviderData, + AzureProviderData, + GcpProviderData + ] + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/ready.ex b/lib/trento_web/openapi/v1/schema/ready.ex index 68fe848e02..c98796f272 100644 --- a/lib/trento_web/openapi/v1/schema/ready.ex +++ b/lib/trento_web/openapi/v1/schema/ready.ex @@ -7,20 +7,23 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Ready do require OpenApiSpex - OpenApiSpex.schema(%Schema{ - title: "Ready", - type: :object, - example: %{ - ready: true - }, - additionalProperties: false, - properties: %{ - ready: %Schema{ - description: "Trento Web platform ready", - type: :boolean + OpenApiSpex.schema( + %Schema{ + title: "Ready", + type: :object, + example: %{ + ready: true + }, + additionalProperties: false, + properties: %{ + ready: %Schema{ + description: "Trento Web platform ready", + type: :boolean + } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/resource_health.ex b/lib/trento_web/openapi/v1/schema/resource_health.ex index 585056997c..85cd7538a7 100644 --- a/lib/trento_web/openapi/v1/schema/resource_health.ex +++ b/lib/trento_web/openapi/v1/schema/resource_health.ex @@ -4,11 +4,14 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ResourceHealth do require OpenApiSpex require Trento.Enums.Health, as: Health - OpenApiSpex.schema(%{ - title: "ResourceHealth", - type: :string, - nullable: true, - description: "Detected health of a Resource", - enum: Health.values() - }) + OpenApiSpex.schema( + %{ + title: "ResourceHealth", + type: :string, + nullable: true, + description: "Detected health of a Resource", + enum: Health.values() + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/sap_system.ex b/lib/trento_web/openapi/v1/schema/sap_system.ex index d32ed5ef37..cf8ba2c451 100644 --- a/lib/trento_web/openapi/v1/schema/sap_system.ex +++ b/lib/trento_web/openapi/v1/schema/sap_system.ex @@ -11,145 +11,160 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do defmodule ApplicationInstance do @moduledoc false - OpenApiSpex.schema(%{ - title: "ApplicationInstance", - description: "A discovered Application Instance on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - sap_system_id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - instance_number: %Schema{type: :string, description: "Instance Number"}, - instance_hostname: %Schema{ - type: :string, - description: "Instance Hostname", - nullable: true - }, - absent_at: %Schema{ - type: :string, - description: "Absent instance timestamp", - format: :datetime, - nullable: true - }, - features: %Schema{type: :string, description: "Instance Features"}, - http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, - https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, - start_priority: %Schema{ - type: :string, - description: "Instance Start Priority", - nullable: true - }, - host_id: %Schema{ - type: :string, - description: "Identifier of the host where current instance is running", - format: :uuid - }, - health: ResourceHealth, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "ApplicationInstance", + description: "A discovered Application Instance on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + sap_system_id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + instance_number: %Schema{type: :string, description: "Instance Number"}, + instance_hostname: %Schema{ + type: :string, + description: "Instance Hostname", + nullable: true + }, + absent_at: %Schema{ + type: :string, + description: "Absent instance timestamp", + format: :datetime, + nullable: true + }, + features: %Schema{type: :string, description: "Instance Features"}, + http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, + https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, + start_priority: %Schema{ + type: :string, + description: "Instance Start Priority", + nullable: true + }, + host_id: %Schema{ + type: :string, + description: "Identifier of the host where current instance is running", + format: :uuid + }, + health: ResourceHealth, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule SAPSystemItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "SAPSystem", - description: "A discovered SAP System on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - tenant: %Schema{type: :string, description: "Tenant"}, - db_host: %Schema{type: :string, description: "Address of the connected Database"}, - health: ResourceHealth, - ensa_version: %Schema{ - type: :string, - enum: EnsaVersion.values(), - description: "ENSA version of the SAP system" - }, - application_instances: %Schema{ - title: "ApplicationInstances", - description: "A list of the discovered Application Instances for current SAP Systems", - type: :array, - items: ApplicationInstance - }, - database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, - database_sid: %Schema{type: :string, description: "Database SID"}, - database_instances: Database.DatabaseInstances, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "SAPSystem", + description: "A discovered SAP System on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + tenant: %Schema{type: :string, description: "Tenant"}, + db_host: %Schema{type: :string, description: "Address of the connected Database"}, + health: ResourceHealth, + ensa_version: %Schema{ + type: :string, + enum: EnsaVersion.values(), + description: "ENSA version of the SAP system" + }, + application_instances: %Schema{ + title: "ApplicationInstances", + description: "A list of the discovered Application Instances for current SAP Systems", + type: :array, + items: ApplicationInstance + }, + database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, + database_sid: %Schema{type: :string, description: "Database SID"}, + database_instances: Database.DatabaseInstances, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule SAPSystemsCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "SAPSystemsCollection", - description: "A list of the discovered SAP Systems", - type: :array, - items: SAPSystemItem - }) + OpenApiSpex.schema( + %{ + title: "SAPSystemsCollection", + description: "A list of the discovered SAP Systems", + type: :array, + items: SAPSystemItem + }, + struct?: false + ) end defmodule SAPSystemHealthOverview do @moduledoc false - OpenApiSpex.schema(%{ - title: "SAPSystemHealthOverview", - description: "An overview of the health of a discovered SAP System and its components", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - cluster_id: %Schema{ - type: :string, - description: "Cluster ID", - format: :uuid, - deprecated: true - }, - application_cluster_id: %Schema{ - type: :string, - description: "Application cluster ID", - format: :uuid - }, - database_cluster_id: %Schema{ - type: :string, - description: "Database cluster ID", - format: :uuid - }, - database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, - sapsystem_health: ResourceHealth, - database_health: ResourceHealth, - hosts_health: ResourceHealth, - clusters_health: %Schema{ - allOf: [ - ResourceHealth, - %Schema{deprecated: true} - ] - }, - application_cluster_health: ResourceHealth, - database_cluster_health: ResourceHealth, - tenant: %Schema{type: :string, description: "Tenant database SID", deprecated: true}, - database_sid: %Schema{type: :string, description: "Database SID"} - } - }) + OpenApiSpex.schema( + %{ + title: "SAPSystemHealthOverview", + description: "An overview of the health of a discovered SAP System and its components", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + cluster_id: %Schema{ + type: :string, + description: "Cluster ID", + format: :uuid, + deprecated: true + }, + application_cluster_id: %Schema{ + type: :string, + description: "Application cluster ID", + format: :uuid + }, + database_cluster_id: %Schema{ + type: :string, + description: "Database cluster ID", + format: :uuid + }, + database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, + sapsystem_health: ResourceHealth, + database_health: ResourceHealth, + hosts_health: ResourceHealth, + clusters_health: %Schema{ + allOf: [ + ResourceHealth, + %Schema{deprecated: true} + ] + }, + application_cluster_health: ResourceHealth, + database_cluster_health: ResourceHealth, + tenant: %Schema{type: :string, description: "Tenant database SID", deprecated: true}, + database_sid: %Schema{type: :string, description: "Database SID"} + } + }, + struct?: false + ) end defmodule HealthOverview do @moduledoc false - OpenApiSpex.schema(%{ - title: "HealthOverview", - description: "A list of health summaries for the discovered SAP Systems", - type: :array, - items: SAPSystemHealthOverview - }) + OpenApiSpex.schema( + %{ + title: "HealthOverview", + description: "A list of health summaries for the discovered SAP Systems", + type: :array, + items: SAPSystemHealthOverview + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/saptune_status.ex b/lib/trento_web/openapi/v1/schema/saptune_status.ex index 98319a4d9c..1a19207da4 100644 --- a/lib/trento_web/openapi/v1/schema/saptune_status.ex +++ b/lib/trento_web/openapi/v1/schema/saptune_status.ex @@ -8,134 +8,149 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do defmodule Service do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune service", - description: "Saptune service", - type: :object, - additionalProperties: false, - properties: %{ - name: %Schema{ - type: :string, - description: "Saptune service name" - }, - enabled: %Schema{ - type: :string, - description: "Enabled state as string" - }, - active: %Schema{ - type: :string, - description: "Active state as string" + OpenApiSpex.schema( + %{ + title: "Saptune service", + description: "Saptune service", + type: :object, + additionalProperties: false, + properties: %{ + name: %Schema{ + type: :string, + description: "Saptune service name" + }, + enabled: %Schema{ + type: :string, + description: "Enabled state as string" + }, + active: %Schema{ + type: :string, + description: "Active state as string" + } } - } - }) + }, + struct?: false + ) end defmodule Note do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune note", - description: "Saptune note", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{ - type: :string, - description: "Saptune note ID" - }, - additionally_enabled: %Schema{ - type: :boolean, - description: "Note is additionally enabled" + OpenApiSpex.schema( + %{ + title: "Saptune note", + description: "Saptune note", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{ + type: :string, + description: "Saptune note ID" + }, + additionally_enabled: %Schema{ + type: :boolean, + description: "Note is additionally enabled" + } } - } - }) + }, + struct?: false + ) end defmodule Solution do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune solution", - description: "Saptune solution", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{ - type: :boolean, - description: "Saptune solution ID" - }, - notes: %Schema{ - type: :array, - description: "Solution note IDs", - items: %Schema{type: :string} - }, - partial: %Schema{ - type: :boolean, - description: "Solution is partially applied" + OpenApiSpex.schema( + %{ + title: "Saptune solution", + description: "Saptune solution", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{ + type: :boolean, + description: "Saptune solution ID" + }, + notes: %Schema{ + type: :array, + description: "Solution note IDs", + items: %Schema{type: :string} + }, + partial: %Schema{ + type: :boolean, + description: "Solution is partially applied" + } } - } - }) + }, + struct?: false + ) end defmodule Staging do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune staging", - description: "Saptune staging data", + OpenApiSpex.schema( + %{ + title: "Saptune staging", + description: "Saptune staging data", + type: :object, + additionalProperties: false, + properties: %{ + enabled: %Schema{ + type: :boolean, + description: "Saptune staging is enabled" + }, + notes: %Schema{ + type: :array, + description: "Staged saptune note IDs", + items: %Schema{type: :string} + }, + solutions_ids: %Schema{ + type: :array, + description: "Staged saptune solution IDs", + items: %Schema{type: :string} + } + } + }, + struct?: false + ) + end + + OpenApiSpex.schema( + %{ + title: "Saptune status", + description: "Saptune status output on the host", type: :object, + nullable: true, additionalProperties: false, properties: %{ - enabled: %Schema{ - type: :boolean, - description: "Saptune staging is enabled" + package_version: %Schema{type: :string, description: "Saptune package version"}, + configured_version: %Schema{type: :string, description: "Saptune configure version"}, + tuning_state: %Schema{type: :string, description: "Saptune tuning state"}, + services: %Schema{ + title: "Saptune services", + description: "A list of saptune services", + type: :array, + items: Service }, - notes: %Schema{ + enabled_nodes: %Schema{ + title: "Enabled notes", + description: "A list of enabled notes", type: :array, - description: "Staged saptune note IDs", - items: %Schema{type: :string} + items: Note }, - solutions_ids: %Schema{ + applied_notes: %Schema{ + title: "Applied notes", + description: "A list of applied notes", type: :array, - description: "Staged saptune solution IDs", - items: %Schema{type: :string} - } - } - }) - end - - OpenApiSpex.schema(%{ - title: "Saptune status", - description: "Saptune status output on the host", - type: :object, - nullable: true, - additionalProperties: false, - properties: %{ - package_version: %Schema{type: :string, description: "Saptune package version"}, - configured_version: %Schema{type: :string, description: "Saptune configure version"}, - tuning_state: %Schema{type: :string, description: "Saptune tuning state"}, - services: %Schema{ - title: "Saptune services", - description: "A list of saptune services", - type: :array, - items: Service - }, - enabled_nodes: %Schema{ - title: "Enabled notes", - description: "A list of enabled notes", - type: :array, - items: Note - }, - applied_notes: %Schema{ - title: "Applied notes", - description: "A list of applied notes", - type: :array, - items: Note + items: Note + }, + enabled_solution: Solution, + applied_solution: Solution, + staging: Staging }, - enabled_solution: Solution, - applied_solution: Solution, - staging: Staging + required: [:package_version] }, - required: [:package_version] - }) + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/sles_subscription.ex b/lib/trento_web/openapi/v1/schema/sles_subscription.ex index a9dcfdccef..19931a7b9d 100644 --- a/lib/trento_web/openapi/v1/schema/sles_subscription.ex +++ b/lib/trento_web/openapi/v1/schema/sles_subscription.ex @@ -4,21 +4,24 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SlesSubscription do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "SlesSubscription", - description: "A discovered SLES Subscription on a host", - type: :object, - additionalProperties: false, - properties: %{ - host_id: %Schema{type: :string, format: :uuid}, - identifier: %Schema{type: :string}, - version: %Schema{type: :string}, - arch: %Schema{type: :string}, - status: %Schema{type: :string}, - subscription_status: %Schema{type: :string}, - type: %Schema{type: :string}, - starts_at: %Schema{type: :string}, - expires_at: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "SlesSubscription", + description: "A discovered SLES Subscription on a host", + type: :object, + additionalProperties: false, + properties: %{ + host_id: %Schema{type: :string, format: :uuid}, + identifier: %Schema{type: :string}, + version: %Schema{type: :string}, + arch: %Schema{type: :string}, + status: %Schema{type: :string}, + subscription_status: %Schema{type: :string}, + type: %Schema{type: :string}, + starts_at: %Schema{type: :string}, + expires_at: %Schema{type: :string} + } + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/suma_credentials.ex b/lib/trento_web/openapi/v1/schema/suma_credentials.ex index 5125518625..aa4c82eb12 100644 --- a/lib/trento_web/openapi/v1/schema/suma_credentials.ex +++ b/lib/trento_web/openapi/v1/schema/suma_credentials.ex @@ -7,27 +7,30 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do defmodule SaveSUMACredentialsRequest do @moduledoc false - OpenApiSpex.schema(%{ - title: "SaveSUMACredentialsRequest", - description: "Request body for saving SUMA credentials", - type: :object, - additionalProperties: false, - properties: %{ - url: %Schema{ - type: :string - }, - username: %Schema{ - type: :string - }, - password: %Schema{ - type: :string + OpenApiSpex.schema( + %{ + title: "SaveSUMACredentialsRequest", + description: "Request body for saving SUMA credentials", + type: :object, + additionalProperties: false, + properties: %{ + url: %Schema{ + type: :string + }, + username: %Schema{ + type: :string + }, + password: %Schema{ + type: :string + }, + ca_cert: %Schema{ + type: :string + } }, - ca_cert: %Schema{ - type: :string - } + required: [:url, :username, :password] }, - required: [:url, :username, :password] - }) + struct?: false + ) end defmodule UpdateSUMACredentialsRequest do @@ -64,27 +67,30 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do defmodule Settings do @moduledoc false - OpenApiSpex.schema(%{ - title: "SUMACredentials", - description: "User settings for SUSE Manager", - type: :object, - additionalProperties: false, - properties: %{ - url: %Schema{ - type: :string, - description: "URL of SUSE Manager" - }, - username: %Schema{ - type: :string, - description: "Username" - }, - ca_uploaded_at: %Schema{ - type: :string, - format: :datetime, - nullable: true, - description: "Time that SSL certificate was uploaded." + OpenApiSpex.schema( + %{ + title: "SUMACredentials", + description: "User settings for SUSE Manager", + type: :object, + additionalProperties: false, + properties: %{ + url: %Schema{ + type: :string, + description: "URL of SUSE Manager" + }, + username: %Schema{ + type: :string, + description: "Username" + }, + ca_uploaded_at: %Schema{ + type: :string, + format: :datetime, + nullable: true, + description: "Time that SSL certificate was uploaded." + } } - } - }) + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/tag.ex b/lib/trento_web/openapi/v1/schema/tag.ex index 200a95b976..a50f378876 100644 --- a/lib/trento_web/openapi/v1/schema/tag.ex +++ b/lib/trento_web/openapi/v1/schema/tag.ex @@ -9,26 +9,32 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Tags do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "Tag", - description: "A tag attached to a resource", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer}, - resource_id: %Schema{type: :string, format: :uuid}, - resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]}, - value: %Schema{type: :string}, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "Tag", + description: "A tag attached to a resource", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer}, + resource_id: %Schema{type: :string, format: :uuid}, + resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]}, + value: %Schema{type: :string}, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end - OpenApiSpex.schema(%{ - title: "Tags", - description: "A list of tags attached to a resource", - type: :array, - items: Tag - }) + OpenApiSpex.schema( + %{ + title: "Tags", + description: "A list of tags attached to a resource", + type: :array, + items: Tag + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/unauthorized.ex b/lib/trento_web/openapi/v1/schema/unauthorized.ex index a6ea150233..394cd47943 100644 --- a/lib/trento_web/openapi/v1/schema/unauthorized.ex +++ b/lib/trento_web/openapi/v1/schema/unauthorized.ex @@ -7,26 +7,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Unauthorized do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "Unauthorized", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "The requested operation could not be authorized." - }, - title: %Schema{type: :string, example: "Unauthorized"} + OpenApiSpex.schema( + %{ + title: "Unauthorized", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "The requested operation could not be authorized." + }, + title: %Schema{type: :string, example: "Unauthorized"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex b/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex index f1b36365d0..ce109e814f 100644 --- a/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex +++ b/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex @@ -7,24 +7,27 @@ defmodule TrentoWeb.OpenApi.V1.Schema.UnprocessableEntity do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - title: %Schema{type: :string, example: "Invalid value"}, - detail: %Schema{type: :string, example: "null value where string expected"} - }, - required: [:title, :detail] + OpenApiSpex.schema( + %{ + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + title: %Schema{type: :string, example: "Invalid value"}, + detail: %Schema{type: :string, example: "null value where string expected"} + }, + required: [:title, :detail] + } } - } + }, + required: [:errors] }, - required: [:errors] - }) + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/user.ex b/lib/trento_web/openapi/v1/schema/user.ex index b80391b0a4..a74f20e148 100644 --- a/lib/trento_web/openapi/v1/schema/user.ex +++ b/lib/trento_web/openapi/v1/schema/user.ex @@ -9,201 +9,230 @@ defmodule TrentoWeb.OpenApi.V1.Schema.User do defmodule UserTOTPEnrollmentPayload do @moduledoc false - @schema %Schema{ - title: "UserTOTPEnrollmentPayload", - description: "Trento User TOTP enrollment payload", - type: :object, - additionalProperties: false, - properties: %{ - secret: %Schema{type: :string, description: "TOTP secret", nullable: false}, - secret_qr_encoded: %Schema{ - type: :string, - description: "TOTP secret qr encoded", - nullable: false - } + OpenApiSpex.schema( + %{ + title: "UserTOTPEnrollmentPayload", + description: "Trento User TOTP enrollment payload", + type: :object, + additionalProperties: false, + properties: %{ + secret: %Schema{type: :string, description: "TOTP secret", nullable: false}, + secret_qr_encoded: %Schema{ + type: :string, + description: "TOTP secret qr encoded", + nullable: false + } + }, + required: [:secret, :secret_qr_encoded] }, - required: [:secret, :secret_qr_encoded] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserTOTPEnrollmentConfirmPayload do @moduledoc false - @schema %Schema{ - title: "UserTOTPEnrollmentConfirmPayload", - description: "Trento User TOTP enrollment completed payload", - type: :object, - additionalProperties: false, - properties: %{ - totp_enabled_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of TOTP enrollment", - nullable: false - } + OpenApiSpex.schema( + %{ + title: "UserTOTPEnrollmentConfirmPayload", + description: "Trento User TOTP enrollment completed payload", + type: :object, + additionalProperties: false, + properties: %{ + totp_enabled_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of TOTP enrollment", + nullable: false + } + }, + required: [:totp_enabled_at] }, - required: [:totp_enabled_at] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserTOTPEnrollmentConfirmRequest do @moduledoc false - @schema %Schema{ - title: "UserTOTPEnrollmentConfirmRequest", - description: "Trento User totp enrollment confirmation payload", - type: :object, - additionalProperties: false, - properties: %{ - totp_code: %Schema{ - type: :string, - description: "TOTP generated from enrollment secret", - nullable: false - } + OpenApiSpex.schema( + %{ + title: "UserTOTPEnrollmentConfirmRequest", + description: "Trento User totp enrollment confirmation payload", + type: :object, + additionalProperties: false, + properties: %{ + totp_code: %Schema{ + type: :string, + description: "TOTP generated from enrollment secret", + nullable: false + } + }, + required: [:totp_code] }, - required: [:totp_code] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserProfile do @moduledoc false - @schema %Schema{ - title: "UserProfile", - description: "Trento User profile", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "User ID", nullable: false}, - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - username: %Schema{type: :string, description: "User username", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - abilities: AbilityCollection, - password_change_requested: %Schema{ - type: :boolean, - description: "Password change is requested", - nullable: false - }, - totp_enabled: %Schema{ - type: :boolean, - description: "TOTP is enabled", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserProfile", + description: "Trento User profile", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "User ID", nullable: false}, + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + username: %Schema{type: :string, description: "User username", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + abilities: AbilityCollection, + password_change_requested: %Schema{ + type: :boolean, + description: "Password change is requested", + nullable: false + }, + totp_enabled: %Schema{ + type: :boolean, + description: "TOTP is enabled", + nullable: false + }, + created_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user creation", + nullable: false + }, + updated_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user last update", + nullable: true + } }, - created_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user creation", - nullable: false - }, - updated_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user last update", - nullable: true - } + required: [:username, :id, :fullname, :email, :created_at, :totp_enabled] }, - required: [:username, :id, :fullname, :email, :created_at, :totp_enabled] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserProfileUpdateRequest do @moduledoc false - @schema %Schema{ - title: "UserProfileUpdateRequest", - description: "Request body to update a user profile", - additionalProperties: false, - type: :object, - properties: %{ - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - password: %Schema{type: :string, description: "User new password", nullable: false}, - current_password: %Schema{ - type: :string, - description: "User current password, used to set a new password", - nullable: false - }, - password_confirmation: %Schema{ - type: :string, - description: "User new password, should be the same as password field", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserProfileUpdateRequest", + description: "Request body to update a user profile", + additionalProperties: false, + type: :object, + properties: %{ + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + password: %Schema{type: :string, description: "User new password", nullable: false}, + current_password: %Schema{ + type: :string, + description: "User current password, used to set a new password", + nullable: false + }, + password_confirmation: %Schema{ + type: :string, + description: "User new password, should be the same as password field", + nullable: false + } } - } - } - - def schema, do: @schema + }, + struct?: false + ) end defmodule UserCreationRequest do @moduledoc false - @schema %Schema{ - title: "UserCreationRequest", - description: "Request body to create a user", - type: :object, - additionalProperties: false, - properties: %{ - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - username: %Schema{type: :string, description: "User username", nullable: false}, - enabled: %Schema{ - type: :boolean, - description: "User enabled in the system", - nullable: false - }, - password: %Schema{type: :string, description: "User new password", nullable: false}, - password_confirmation: %Schema{ - type: :string, - description: "User new password, should be the same as password field", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserCreationRequest", + description: "Request body to create a user", + type: :object, + additionalProperties: false, + properties: %{ + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + username: %Schema{type: :string, description: "User username", nullable: false}, + enabled: %Schema{ + type: :boolean, + description: "User enabled in the system", + nullable: false + }, + password: %Schema{type: :string, description: "User new password", nullable: false}, + password_confirmation: %Schema{ + type: :string, + description: "User new password, should be the same as password field", + nullable: false + }, + abilities: AbilityCollection }, - abilities: AbilityCollection + required: [:fullname, :email, :enabled, :password, :password_confirmation, :username] }, - required: [:fullname, :email, :enabled, :password, :password_confirmation, :username] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserUpdateRequest do @moduledoc false - @schema %Schema{ - title: "UserUpdateRequest", - description: "Request body to update a user", - type: :object, - additionalProperties: false, - properties: %{ - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - enabled: %Schema{ - type: :boolean, - description: "User enabled in the system", - nullable: false - }, - password: %Schema{type: :string, description: "User new password", nullable: false}, - password_confirmation: %Schema{ - type: :string, - description: "User new password, should be the same as password field", - nullable: false - }, - abilities: AbilityCollection, - totp_disabled: %Schema{ - type: :boolean, - description: - "TOTP feature disabled for the user. The only accepted value here is 'true'", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserUpdateRequest", + description: "Request body to update a user", + type: :object, + additionalProperties: false, + properties: %{ + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + enabled: %Schema{ + type: :boolean, + description: "User enabled in the system", + nullable: false + }, + password: %Schema{type: :string, description: "User new password", nullable: false}, + password_confirmation: %Schema{ + type: :string, + description: "User new password, should be the same as password field", + nullable: false + }, + abilities: AbilityCollection, + totp_disabled: %Schema{ + type: :boolean, + description: + "TOTP feature disabled for the user. The only accepted value here is 'true'", + nullable: false + } } - } - } + }, + struct?: false + ) # see: https://github.com/open-api-spex/open_api_spex/issues/87 # This is an alternative way of defining schemas without having to deal to default values @@ -215,65 +244,75 @@ defmodule TrentoWeb.OpenApi.V1.Schema.User do # this means that in the controller the body params are passed as map, without converting from the struct # and we have everything cast and validated BUT without the hassle of cannot distinguish between passed # object keys or not and further conversions in the controller. - def schema, do: @schema end defmodule UserItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "UserItem", - description: "User entity in the system", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "User ID", nullable: false}, - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - username: %Schema{type: :string, description: "User username", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - enabled: %Schema{ - type: :boolean, - description: "User enabled in the system", - nullable: false - }, - abilities: AbilityCollection, - password_change_requested_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of password change request", - nullable: true - }, - created_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user creation", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserItem", + description: "User entity in the system", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "User ID", nullable: false}, + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + username: %Schema{type: :string, description: "User username", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + enabled: %Schema{ + type: :boolean, + description: "User enabled in the system", + nullable: false + }, + abilities: AbilityCollection, + password_change_requested_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of password change request", + nullable: true + }, + created_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user creation", + nullable: false + }, + updated_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user last update", + nullable: true + }, + totp_enabled_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of TOTP enrollment", + nullable: true + } }, - updated_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user last update", - nullable: true - }, - totp_enabled_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of TOTP enrollment", - nullable: true - } + required: [:username, :id, :fullname, :email, :created_at] }, - required: [:username, :id, :fullname, :email, :created_at] - }) + struct?: false + ) end defmodule UserCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "UserCollection", - description: "A collection of users in the system", - type: :array, - items: UserItem - }) + OpenApiSpex.schema( + %{ + title: "UserCollection", + description: "A collection of users in the system", + type: :array, + items: UserItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v2/schema/cluster.ex b/lib/trento_web/openapi/v2/schema/cluster.ex index 6ae868b652..2fde45db38 100644 --- a/lib/trento_web/openapi/v2/schema/cluster.ex +++ b/lib/trento_web/openapi/v2/schema/cluster.ex @@ -13,296 +13,334 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do defmodule ClusterResource do @moduledoc false - OpenApiSpex.schema(%{ - title: "ClusterResource", - description: "A Cluster Resource", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string}, - type: %Schema{type: :string}, - role: %Schema{type: :string}, - status: %Schema{type: :string}, - fail_count: %Schema{type: :integer}, - managed: %Schema{type: :boolean} - } - }) + OpenApiSpex.schema( + %{ + title: "ClusterResource", + description: "A Cluster Resource", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string}, + type: %Schema{type: :string}, + role: %Schema{type: :string}, + status: %Schema{type: :string}, + fail_count: %Schema{type: :integer}, + managed: %Schema{type: :boolean} + } + }, + struct?: false + ) end defmodule HanaClusterNode do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterNode", - description: "A HANA Cluster Node", - type: :object, - additionalProperties: false, - properties: %{ - name: %Schema{type: :string}, - site: %Schema{type: :string}, - indexserver_actual_role: %Schema{type: :string, nullable: true}, - nameserver_actual_role: %Schema{type: :string, nullable: true}, - hana_status: %Schema{type: :string, deprecated: true}, - status: %Schema{type: :string}, - attributes: %Schema{ - type: :object, - description: "Node attributes", - additionalProperties: %Schema{type: :string} - }, - virtual_ip: %Schema{type: :string}, - resources: %Schema{ - description: "A list of Cluster resources", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterNode", + description: "A HANA Cluster Node", + type: :object, + additionalProperties: false, + properties: %{ + name: %Schema{type: :string}, + site: %Schema{type: :string}, + indexserver_actual_role: %Schema{type: :string, nullable: true}, + nameserver_actual_role: %Schema{type: :string, nullable: true}, + hana_status: %Schema{type: :string, deprecated: true}, + status: %Schema{type: :string}, + attributes: %Schema{ + type: :object, + description: "Node attributes", + additionalProperties: %Schema{type: :string} + }, + virtual_ip: %Schema{type: :string}, + resources: %Schema{ + description: "A list of Cluster resources", + type: :array, + items: ClusterResource + } } - } - }) + }, + struct?: false + ) end defmodule HanaClusterSite do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterSite", - description: "A HANA Cluster Site", - type: :object, - additionalProperties: false, - properties: %{ - name: %Schema{type: :string, description: "Site name"}, - state: %Schema{type: :string, description: "Site state"}, - sr_health_state: %Schema{type: :string, description: "Site SR Health state"} - } - }) + OpenApiSpex.schema( + %{ + title: "HanaClusterSite", + description: "A HANA Cluster Site", + type: :object, + additionalProperties: false, + properties: %{ + name: %Schema{type: :string, description: "Site name"}, + state: %Schema{type: :string, description: "Site state"}, + sr_health_state: %Schema{type: :string, description: "Site SR Health state"} + } + }, + struct?: false + ) end defmodule HanaClusterDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterDetails", - description: "Details of a HANA Pacemaker Cluster", - type: :object, - additionalProperties: false, - properties: %{ - architecture_type: %Schema{ - type: :string, - description: "HANA architecture type.", - enum: HanaArchitectureType.values() - }, - system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, - system_replication_operation_mode: %Schema{ - type: :string, - description: "System Replication Operation Mode" - }, - secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, - sr_health_state: %Schema{type: :string, description: "SR health state", deprecated: true}, - fencing_type: %Schema{type: :string, description: "Fencing Type"}, - maintenance_mode: %Schema{ - type: :boolean, - description: "Maintenance mode enabled" - }, - stopped_resources: %Schema{ - description: "A list of the stopped resources on this HANA Cluster", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterDetails", + description: "Details of a HANA Pacemaker Cluster", + type: :object, + additionalProperties: false, + properties: %{ + architecture_type: %Schema{ + type: :string, + description: "HANA architecture type.", + enum: HanaArchitectureType.values() + }, + system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, + system_replication_operation_mode: %Schema{ + type: :string, + description: "System Replication Operation Mode" + }, + secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, + sr_health_state: %Schema{ + type: :string, + description: "SR health state", + deprecated: true + }, + fencing_type: %Schema{type: :string, description: "Fencing Type"}, + maintenance_mode: %Schema{ + type: :boolean, + description: "Maintenance mode enabled" + }, + stopped_resources: %Schema{ + description: "A list of the stopped resources on this HANA Cluster", + type: :array, + items: ClusterResource + }, + nodes: %Schema{ + type: :array, + items: HanaClusterNode + }, + sites: %Schema{ + description: "A list of HANA sites", + type: :array, + items: HanaClusterSite + }, + sbd_devices: %Schema{ + type: :array, + items: Cluster.SbdDevice + } }, - nodes: %Schema{ - type: :array, - items: HanaClusterNode - }, - sites: %Schema{ - description: "A list of HANA sites", - type: :array, - items: HanaClusterSite - }, - sbd_devices: %Schema{ - type: :array, - items: Cluster.SbdDevice - } + required: [:nodes] }, - required: [:nodes] - }) + struct?: false + ) end defmodule AscsErsClusterNode do @moduledoc false - OpenApiSpex.schema(%{ - title: "AscsErsClusterNode", - description: "ASCS/ERS Cluster Node", - type: :object, - additionalProperties: false, - properties: %{ - attributes: %Schema{ - type: :object, - description: "Node attributes", - additionalProperties: %Schema{type: :string} - }, - filesystems: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "List of filesystems managed in this node" - }, - name: %Schema{ - type: :string, - description: "Node name" - }, - status: %Schema{ - type: :string, - description: "Node status" - }, - resources: %Schema{ - type: :array, - items: ClusterResource, - description: "A list of Cluster resources" - }, - roles: %Schema{ - type: :array, - items: %Schema{type: :string, enum: AscsErsClusterRole.values()}, - description: "List of roles managed in this node" - }, - virtual_ips: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "List of virtual IPs managed in this node" + OpenApiSpex.schema( + %{ + title: "AscsErsClusterNode", + description: "ASCS/ERS Cluster Node", + type: :object, + additionalProperties: false, + properties: %{ + attributes: %Schema{ + type: :object, + description: "Node attributes", + additionalProperties: %Schema{type: :string} + }, + filesystems: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "List of filesystems managed in this node" + }, + name: %Schema{ + type: :string, + description: "Node name" + }, + status: %Schema{ + type: :string, + description: "Node status" + }, + resources: %Schema{ + type: :array, + items: ClusterResource, + description: "A list of Cluster resources" + }, + roles: %Schema{ + type: :array, + items: %Schema{type: :string, enum: AscsErsClusterRole.values()}, + description: "List of roles managed in this node" + }, + virtual_ips: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "List of virtual IPs managed in this node" + } } - } - }) + }, + struct?: false + ) end defmodule AscsErsClusterSAPSystem do @moduledoc false - OpenApiSpex.schema(%{ - title: "AscsErsClusterSAPSystem", - description: "SAP system managed by a ASCS/ERS cluster", - type: :object, - additionalProperties: false, - required: [:sid], - properties: %{ - sid: %Schema{type: :string, description: "SID"}, - distributed: %Schema{ - type: :boolean, - description: "ASCS and ERS instances are distributed and running in different nodes" - }, - filesystem_resource_based: %Schema{ - type: :boolean, - description: - "ASCS and ERS filesystems are handled by the cluster with the Filesystem resource agent" - }, - nodes: %Schema{ - type: :array, - items: AscsErsClusterNode, - description: "List of ASCS/ERS nodes for this SAP system" + OpenApiSpex.schema( + %{ + title: "AscsErsClusterSAPSystem", + description: "SAP system managed by a ASCS/ERS cluster", + type: :object, + additionalProperties: false, + required: [:sid], + properties: %{ + sid: %Schema{type: :string, description: "SID"}, + distributed: %Schema{ + type: :boolean, + description: "ASCS and ERS instances are distributed and running in different nodes" + }, + filesystem_resource_based: %Schema{ + type: :boolean, + description: + "ASCS and ERS filesystems are handled by the cluster with the Filesystem resource agent" + }, + nodes: %Schema{ + type: :array, + items: AscsErsClusterNode, + description: "List of ASCS/ERS nodes for this SAP system" + } } - } - }) + }, + struct?: false + ) end defmodule AscsErsClusterDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "AscsErsClusterDetails", - description: "Details of a ASCS/ERS Pacemaker Cluster", - type: :object, - additionalProperties: false, - properties: %{ - fencing_type: %Schema{ - type: :string, - description: "Fencing type" + OpenApiSpex.schema( + %{ + title: "AscsErsClusterDetails", + description: "Details of a ASCS/ERS Pacemaker Cluster", + type: :object, + additionalProperties: false, + properties: %{ + fencing_type: %Schema{ + type: :string, + description: "Fencing type" + }, + maintenance_mode: %Schema{ + type: :boolean, + description: "Maintenance mode enabled" + }, + sap_systems: %Schema{ + type: :array, + items: AscsErsClusterSAPSystem, + description: "List of managed SAP systems in a single or multi SID cluster" + }, + sbd_devices: %Schema{ + type: :array, + items: Cluster.SbdDevice, + description: "List of SBD devices used in the cluster" + }, + stopped_resources: %Schema{ + type: :array, + items: ClusterResource, + description: "List of the stopped resources on this HANA Cluster" + } }, - maintenance_mode: %Schema{ - type: :boolean, - description: "Maintenance mode enabled" - }, - sap_systems: %Schema{ - type: :array, - items: AscsErsClusterSAPSystem, - description: "List of managed SAP systems in a single or multi SID cluster" - }, - sbd_devices: %Schema{ - type: :array, - items: Cluster.SbdDevice, - description: "List of SBD devices used in the cluster" - }, - stopped_resources: %Schema{ - type: :array, - items: ClusterResource, - description: "List of the stopped resources on this HANA Cluster" - } + required: [:sap_systems] }, - required: [:sap_systems] - }) + struct?: false + ) end defmodule Details do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClusterDetails", - description: "Details of the detected PacemakerCluster", - nullable: true, - oneOf: [ - AscsErsClusterDetails, - HanaClusterDetails - ] - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClusterDetails", + description: "Details of the detected PacemakerCluster", + nullable: true, + oneOf: [ + AscsErsClusterDetails, + HanaClusterDetails + ] + }, + struct?: false + ) end defmodule PacemakerCluster do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerCluster", - description: "A discovered Pacemaker Cluster on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, - name: %Schema{type: :string, description: "Cluster name"}, - sid: %Schema{type: :string, description: "SID"}, - additional_sids: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" - }, - provider: Provider.SupportedProviders, - type: %Schema{ - type: :string, - description: "Detected type of the cluster", - enum: ClusterType.values() - }, - selected_checks: %Schema{ - title: "SelectedChecks", - description: "A list of check ids selected for an execution on this cluster", - type: :array, - items: %Schema{type: :string} - }, - health: ResourceHealth, - resources_number: %Schema{type: :integer, description: "Resource number", nullable: true}, - hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, - cib_last_written: %Schema{ - type: :string, - description: "CIB last written date", - nullable: true - }, - details: Details, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "PacemakerCluster", + description: "A discovered Pacemaker Cluster on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, + name: %Schema{type: :string, description: "Cluster name"}, + sid: %Schema{type: :string, description: "SID"}, + additional_sids: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" + }, + provider: Provider.SupportedProviders, + type: %Schema{ + type: :string, + description: "Detected type of the cluster", + enum: ClusterType.values() + }, + selected_checks: %Schema{ + title: "SelectedChecks", + description: "A list of check ids selected for an execution on this cluster", + type: :array, + items: %Schema{type: :string} + }, + health: ResourceHealth, + resources_number: %Schema{ + type: :integer, + description: "Resource number", + nullable: true + }, + hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, + cib_last_written: %Schema{ + type: :string, + description: "CIB last written date", + nullable: true + }, + details: Details, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule PacemakerClustersCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClustersCollection", - description: "A list of the discovered Pacemaker Clusters", - type: :array, - items: PacemakerCluster - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClustersCollection", + description: "A list of the discovered Pacemaker Clusters", + type: :array, + items: PacemakerCluster + }, + struct?: false + ) end end diff --git a/test/trento_web/controllers/v1/suse_manager_controller_test.exs b/test/trento_web/controllers/v1/suse_manager_controller_test.exs index e26eae7ae9..0c09e6b01a 100644 --- a/test/trento_web/controllers/v1/suse_manager_controller_test.exs +++ b/test/trento_web/controllers/v1/suse_manager_controller_test.exs @@ -11,10 +11,7 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do alias TrentoWeb.OpenApi.V1.Schema.AvailableSoftwareUpdates.{ AvailableSoftwareUpdatesResponse, ErrataDetailsResponse, - PatchesForPackage, - PatchesForPackagesResponse, - RelevantPatch, - UpgradablePackage + PatchesForPackagesResponse } setup do @@ -46,18 +43,18 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do %AvailableSoftwareUpdatesResponse{ relevant_patches: [ - %RelevantPatch{ + %{ id: 4182 }, - %RelevantPatch{ + %{ id: 4174 } ], upgradable_packages: [ - %UpgradablePackage{ + %{ name: "elixir" }, - %UpgradablePackage{ + %{ name: "systemd" } ] @@ -107,8 +104,8 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do %PatchesForPackagesResponse{ patches: [ - %PatchesForPackage{package_id: _, patches: _}, - %PatchesForPackage{package_id: _, patches: _} + %{package_id: _, patches: _}, + %{package_id: _, patches: _} ] } = conn @@ -128,8 +125,8 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do %PatchesForPackagesResponse{ patches: [ - %PatchesForPackage{package_id: _, patches: []}, - %PatchesForPackage{package_id: _, patches: []} + %{package_id: _, patches: []}, + %{package_id: _, patches: []} ] } = conn