Skip to content

Commit

Permalink
Openapi schemas no additional properties (#2355)
Browse files Browse the repository at this point in the history
* Add additionalProperties false to openapi schema objects

* Cluster v1/v2 controller tests and view refactored for openapi
compatibility

* HealthOverview controller refactored for openapi compatibility

* Host views aligned with openapi spex

* Sap system view adapted to sap system controller openapi

* Fixed Host schema v1

* mix credo fix

* Revert "HealthOverview controller refactored for openapi compatibility"

This reverts commit 8869575.

* Addressing review feedbacks

* Temporary fix incompatible api check

* Revert "Temporary fix incompatible api check"

This reverts commit 2df1abd.
  • Loading branch information
CDimonaco authored Feb 22, 2024
1 parent e23371b commit ff64338
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/bad_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.BadRequest do
OpenApiSpex.schema(%{
title: "BadRequest",
type: :object,
additionalProperties: false,
properties: %{
errors: %Schema{
type: :array,
Expand Down
3 changes: 3 additions & 0 deletions lib/trento_web/openapi/v1/schema/chart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do
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{
Expand Down Expand Up @@ -43,6 +44,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do

OpenApiSpex.schema(%{
title: "HostCpuChart",
additionalProperties: false,
description: "A Time Series chart with information about the cpu usage of a host",
type: :object,
properties: %{
Expand All @@ -63,6 +65,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do
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,
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/checks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Checks.ChecksSelectionRequest do
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{
Expand Down
5 changes: 5 additions & 0 deletions lib/trento_web/openapi/v1/schema/checks_catalog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do
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"},
Expand Down Expand Up @@ -50,6 +51,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do
OpenApiSpex.schema(%{
title: "ChecksGroup",
description: "A Group of related Checks (Corosync, Pacemaker ...)",
additionalProperties: false,
type: :object,
properties: %{
group: %Schema{type: :string, description: "Group Name"},
Expand All @@ -64,6 +66,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do
OpenApiSpex.schema(%{
title: "ProviderCatalog",
description: "A Provider specific Catalog, and respective values",
additionalProperties: false,
type: :object,
properties: %{
provider: %Schema{
Expand Down Expand Up @@ -164,6 +167,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do
OpenApiSpex.schema(%{
title: "CatalogNotfound",
description: "No Catalog was found for the provided query",
additionalProperties: false,
type: :object,
properties: %{
error: %Schema{
Expand All @@ -181,6 +185,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do
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"}
Expand Down
5 changes: 5 additions & 0 deletions lib/trento_web/openapi/v1/schema/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
title: "ClusterResource",
description: "A Cluster Resource",
type: :object,
additionalProperties: false,
properties: %{
id: %Schema{type: :string},
type: %Schema{type: :string},
Expand All @@ -30,6 +31,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
OpenApiSpex.schema(%{
title: "HanaClusterNode",
description: "A HANA Cluster Node",
additionalProperties: false,
type: :object,
properties: %{
name: %Schema{type: :string},
Expand All @@ -56,6 +58,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
OpenApiSpex.schema(%{
title: "SbdDevice",
description: "SBD Device",
additionalProperties: false,
type: :object,
properties: %{
device: %Schema{type: :string},
Expand All @@ -71,6 +74,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
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{
Expand Down Expand Up @@ -118,6 +122,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
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"},
Expand Down
8 changes: 8 additions & 0 deletions lib/trento_web/openapi/v1/schema/database.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do
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},
sid: %Schema{type: :string, description: "SID"},
Expand All @@ -23,6 +24,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do
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},
Expand Down Expand Up @@ -65,6 +72,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do
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"},
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/discovery_event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.DiscoveryEvent do
title: "DiscoveryEvent",
description: "A discovery event",
type: :object,
additionalProperties: false,
properties: %{
agent_id: %Schema{type: :string, format: :uuid},
discovery_type: %Schema{type: :string},
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/health.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Health do
example: %{
database: "pass"
},
additionalProperties: false,
properties: %{
database: %Schema{
description: "The status of the database connection",
Expand Down
16 changes: 15 additions & 1 deletion lib/trento_web/openapi/v1/schema/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do
require OpenApiSpex
alias OpenApiSpex.Schema

alias TrentoWeb.OpenApi.V1.Schema.{Provider, SaptuneStatus, SlesSubscription, Tags}
alias TrentoWeb.OpenApi.V1.Schema.{
Provider,
ResourceHealth,
SaptuneStatus,
SlesSubscription,
Tags
}

defmodule IPv4 do
@moduledoc false
Expand Down Expand Up @@ -33,6 +39,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do
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"},
Expand All @@ -51,6 +58,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do
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",
Expand All @@ -70,6 +78,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do
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",
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/http_std.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.HttpStd do
"labelname" => "mylabel"
}
},
additionalProperties: false,
properties: %{
labels: %Schema{
type: :object,
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/not_found.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.NotFound do
OpenApiSpex.schema(%{
title: "NotFound",
type: :object,
additionalProperties: false,
properties: %{
errors: %Schema{
type: :array,
Expand Down
2 changes: 2 additions & 0 deletions lib/trento_web/openapi/v1/schema/platform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Platform do
title: "PlatformSettings",
description: "Settings values for the current installation",
type: :object,
additionalProperties: false,
properties: %{
eula_accepted: %Schema{
type: :boolean,
Expand All @@ -31,6 +32,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Platform do
title: "GeneralInformation",
description: "General information about the current installation",
type: :object,
additionalProperties: false,
properties: %{
flavor: %Schema{
type: :string,
Expand Down
3 changes: 3 additions & 0 deletions lib/trento_web/openapi/v1/schema/provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do
title: "AzureProviderData",
description: "Azure detected metadata",
type: :object,
additionalProperties: false,
properties: %{
resource_group: %Schema{type: :string},
location: %Schema{type: :string},
Expand All @@ -54,6 +55,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do
title: "AwsProviderData",
description: "AWS detected metadata",
type: :object,
additionalProperties: false,
properties: %{
account_id: %Schema{type: :string},
ami_id: %Schema{type: :string},
Expand All @@ -74,6 +76,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do
title: "GcpProviderData",
description: "GCP detected metadata",
type: :object,
additionalProperties: false,
properties: %{
disk_number: %Schema{type: :integer},
image: %Schema{type: :string},
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/ready.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Ready do
example: %{
ready: true
},
additionalProperties: false,
properties: %{
ready: %Schema{
description: "Trento Web platform ready",
Expand Down
11 changes: 10 additions & 1 deletion lib/trento_web/openapi/v1/schema/sap_system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
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"},
Expand All @@ -24,6 +25,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
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},
Expand All @@ -49,6 +56,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
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"},
Expand Down Expand Up @@ -90,6 +98,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
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"},
Expand All @@ -113,7 +122,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
sapsystem_health: ResourceHealth,
database_health: ResourceHealth,
hosts_health: ResourceHealth,
clusters_heatlh: %Schema{
clusters_health: %Schema{
allOf: [
ResourceHealth,
%Schema{deprecated: true}
Expand Down
5 changes: 5 additions & 0 deletions lib/trento_web/openapi/v1/schema/saptune_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do
title: "Saptune service",
description: "Saptune service",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{
type: :string,
Expand All @@ -36,6 +37,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do
title: "Saptune note",
description: "Saptune note",
type: :object,
additionalProperties: false,
properties: %{
id: %Schema{
type: :string,
Expand All @@ -56,6 +58,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do
title: "Saptune solution",
description: "Saptune solution",
type: :object,
additionalProperties: false,
properties: %{
id: %Schema{
type: :boolean,
Expand All @@ -81,6 +84,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do
title: "Saptune staging",
description: "Saptune staging data",
type: :object,
additionalProperties: false,
properties: %{
enabled: %Schema{
type: :boolean,
Expand All @@ -105,6 +109,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do
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"},
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/sles_subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SlesSubscription do
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},
Expand Down
3 changes: 3 additions & 0 deletions lib/trento_web/openapi/v1/schema/suma_credentials.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do
title: "SaveSUMACredentialsRequest",
description: "Request body for saving SUMA credentials",
type: :object,
additionalProperties: false,
properties: %{
url: %Schema{
type: :string
Expand Down Expand Up @@ -39,6 +40,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do
"Request body for updating SUMA credentials.\nOnly provide fields to be updated",
type: :object,
minProperties: 1,
additionalProperties: false,
properties: %{
url: %Schema{
type: :string
Expand Down Expand Up @@ -66,6 +68,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do
title: "SUMACredentials",
description: "User settings for SUSE Manager",
type: :object,
additionalProperties: false,
properties: %{
url: %Schema{
type: :string,
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Tags do
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},
Expand Down
Loading

0 comments on commit ff64338

Please sign in to comment.