Skip to content

Commit

Permalink
Openapi no additional properties take two (#383)
Browse files Browse the repository at this point in the history
* Update schema and disable additional properties

* Update view and test

* Update factory

* Refactor view, test and factory

* Refactor catalog test v2 and update factory
  • Loading branch information
EMaksy authored Mar 20, 2024
1 parent 1dcb3df commit def1f36
Show file tree
Hide file tree
Showing 33 changed files with 173 additions and 31 deletions.
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/accepted_execution_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule WandaWeb.Schemas.AcceptedExecutionResponse do
title: "AcceptedExecutionResponse",
description: "Identifiers of the recently accepted execution",
type: :object,
additionalProperties: false,
properties: %{
execution_id: %Schema{type: :string, format: :uuid},
group_id: %Schema{type: :string, format: :uuid}
Expand Down
2 changes: 2 additions & 0 deletions lib/wanda_web/schemas/bad_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ defmodule WandaWeb.Schemas.BadRequest do
OpenApiSpex.schema(%{
title: "BadRequest",
type: :object,
additionalProperties: false,
properties: %{
errors: %Schema{
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
properties: %{
detail: %Schema{
type: :string,
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/health.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule WandaWeb.Schemas.Health do
OpenApiSpex.schema(%Schema{
title: "Health",
type: :object,
additionalProperties: false,
example: %{
database: "pass"
},
Expand Down
2 changes: 2 additions & 0 deletions lib/wanda_web/schemas/not_found.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ defmodule WandaWeb.Schemas.NotFound do
OpenApiSpex.schema(%{
title: "NotFound",
type: :object,
additionalProperties: false,
properties: %{
errors: %Schema{
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
properties: %{
detail: %Schema{type: :string, example: "The requested resource cannot be found."},
title: %Schema{type: :string, example: "Not Found"}
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/ready.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule WandaWeb.Schemas.Ready do
OpenApiSpex.schema(%Schema{
title: "Ready",
type: :object,
additionalProperties: false,
example: %{
ready: true
},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/catalog/catalog_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule WandaWeb.Schemas.V1.Catalog.CatalogResponse do
title: "CatalogResponse",
description: "Checks catalog listing response",
type: :object,
additionalProperties: false,
properties: %{
items: %Schema{type: :array, description: "List of catalog checks", items: Check}
}
Expand Down
44 changes: 35 additions & 9 deletions lib/wanda_web/schemas/v1/catalog/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ defmodule WandaWeb.Schemas.V1.Catalog.Check do
title: "Check",
description: "A single check from the catalog",
type: :object,
additionalProperties: false,
properties: %{
id: %Schema{type: :string, description: "Check ID"},
name: %Schema{type: :string, description: "Check name"},
when: %Schema{
type: :string,
description: "Expression to determine whether a check should run",
group: %Schema{type: :string, description: "Check group"},
description: %Schema{type: :string, description: "Check description"},
remediation: %Schema{type: :string, description: "Check remediation"},
metadata: %Schema{
type: :object,
description: "Check metadata",
nullable: true
},
severity: %Schema{
type: :string,
description: "Check severity: critical|warning",
enum: [:critical, :warning]
},
premium: %Schema{
type: :boolean,
description: "Check is Premium or not"
},
facts: %Schema{
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Fact name"},
gatherer: %Schema{type: :string, description: "Used gatherer"},
Expand All @@ -44,6 +45,7 @@ defmodule WandaWeb.Schemas.V1.Catalog.Check do
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Value name"},
default: %Schema{
Expand All @@ -54,6 +56,7 @@ defmodule WandaWeb.Schemas.V1.Catalog.Check do
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
properties: %{
value: %Schema{
oneOf: [
Expand All @@ -79,6 +82,7 @@ defmodule WandaWeb.Schemas.V1.Catalog.Check do
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Expectation name"},
type: %Schema{
Expand All @@ -96,10 +100,32 @@ defmodule WandaWeb.Schemas.V1.Catalog.Check do
description: "Message returned when the check fails"
}
},
required: [:name, :type, :expression]
required: [:name, :type, :expression, :failure_message]
}
},
when: %Schema{
type: :string,
description: "Expression to determine whether a check should run",
nullable: true
},
premium: %Schema{
type: :boolean,
description: "Check is Premium or not"
}
},
required: [:id, :name, :severity, :facts, :values, :expectations]
required: [
:id,
:name,
:group,
:description,
:remediation,
:metadata,
:severity,
:facts,
:values,
:expectations,
:when,
:premium
]
})
end
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/agent_check_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule WandaWeb.Schemas.V1.Execution.AgentCheckError do
description:
"An error describing that some of the facts could not be gathered on a specific agent eg. gathering failure or timeout",
type: :object,
additionalProperties: false,
properties: %{
agent_id: %Schema{type: :string, format: :uuid, description: "Agent ID"},
facts: %Schema{
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/check_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule WandaWeb.Schemas.V1.Execution.CheckResult do
title: "CheckResult",
description: "The result of a check",
type: :object,
additionalProperties: false,
properties: %{
check_id: %Schema{type: :string, description: "Check ID"},
expectation_results: %Schema{type: :array, items: ExpectationResult},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/execution_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule WandaWeb.Schemas.V1.Execution.ExecutionResponse do
title: "ExecutionResponse",
description: "The representation of an execution, it may be a running or completed one",
type: :object,
additionalProperties: false,
properties: %{
execution_id: %Schema{type: :string, format: :uuid, description: "Execution ID"},
group_id: %Schema{type: :string, format: :uuid, description: "Group ID"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.ExpectationEvaluation do
title: "ExpectationEvaluation",
description: "Evaluation of an expectation",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Name"},
return_value: %Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.ExpectationEvaluationError do
title: "ExpectationEvaluationError",
description: "An error occurred during the evaluation of an expectation",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Expectation name"},
message: %Schema{type: :string, description: "Error message"},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/expectation_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.ExpectationResult do
title: "ExpectationResult",
description: "The result of an expectation",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Expectation name"},
result: %Schema{type: :boolean, description: "Result of the expectation condition"},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/fact.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.Fact do
title: "Fact",
description: "The result of a check",
type: :object,
additionalProperties: false,
properties: %{
check_id: %Schema{type: :string, description: "Check ID"},
name: %Schema{type: :string, description: "Name"},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/fact_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.FactError do
title: "FactError",
description: "An error describing that a fact could not be gathered",
type: :object,
additionalProperties: false,
properties: %{
check_id: %Schema{type: :string, description: "Check ID"},
name: %Schema{type: :string, description: "Fact name"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule WandaWeb.Schemas.V1.Execution.ListExecutionsResponse do
title: "ListExecutionsResponse",
description: "The paginated list of executions",
type: :object,
additionalProperties: false,
properties: %{
items: %Schema{type: :array, items: ExecutionResponse},
total_count: %Schema{type: :integer, description: "Total count of executions"}
Expand Down
2 changes: 2 additions & 0 deletions lib/wanda_web/schemas/v1/execution/start_execution_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule WandaWeb.Schemas.V1.Execution.StartExecutionRequest do
title: "Target",
description: "Target Agent on which facts gathering should happen",
type: :object,
additionalProperties: false,
properties: %{
agent_id: %Schema{
type: :string,
Expand All @@ -37,6 +38,7 @@ defmodule WandaWeb.Schemas.V1.Execution.StartExecutionRequest do
title: "StartExecutionRequest",
description: "Context to run a Check Execution",
type: :object,
additionalProperties: false,
properties: %{
execution_id: %Schema{type: :string, format: :uuid, description: "Execution identifier"},
group_id: %Schema{type: :string, format: :uuid, description: "Group Execution identifier"},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/target.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.Target do
title: "Target",
description: "Target where execution facts are gathered",
type: :object,
additionalProperties: false,
properties: %{
agent_id: %Schema{type: :string, format: :uuid, description: "Agent ID"},
checks: %Schema{
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v1/execution/value.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V1.Execution.Value do
title: "Value",
description: "A Value used in the expectations evaluation",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Name"},
value: %Schema{
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v2/execution/agent_check_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule WandaWeb.Schemas.V2.Execution.AgentCheckResult do
title: "AgentCheckResult",
description: "The result of check on a specific agent",
type: :object,
additionalProperties: false,
properties: %{
agent_id: %Schema{type: :string, format: :uuid, description: "Agent ID"},
facts: %Schema{type: :array, items: Fact, description: "Facts gathered from the targets"},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v2/execution/check_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule WandaWeb.Schemas.V2.Execution.CheckResult do
title: "CheckResult",
description: "The result of a check",
type: :object,
additionalProperties: false,
properties: %{
check_id: %Schema{type: :string, description: "Check ID"},
expectation_results: %Schema{type: :array, items: ExpectationResult},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v2/execution/execution_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule WandaWeb.Schemas.V2.Execution.ExecutionResponse do
title: "ExecutionResponse",
description: "The representation of an execution, it may be a running or completed one",
type: :object,
additionalProperties: false,
properties: %{
execution_id: %Schema{type: :string, format: :uuid, description: "Execution ID"},
group_id: %Schema{type: :string, format: :uuid, description: "Group ID"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V2.Execution.ExpectationEvaluation do
title: "ExpectationEvaluation",
description: "Evaluation of an expectation",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Name"},
return_value: %Schema{
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v2/execution/expectation_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule WandaWeb.Schemas.V2.Execution.ExpectationResult do
title: "ExpectationResult",
description: "The result of an expectation",
type: :object,
additionalProperties: false,
properties: %{
name: %Schema{type: :string, description: "Expectation name"},
result: %Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule WandaWeb.Schemas.V2.Execution.ListExecutionsResponse do
title: "ListExecutionsResponse",
description: "The paginated list of executions",
type: :object,
additionalProperties: false,
properties: %{
items: %Schema{type: :array, items: ExecutionResponse},
total_count: %Schema{type: :integer, description: "Total count of executions"}
Expand Down
2 changes: 2 additions & 0 deletions lib/wanda_web/schemas/v2/execution/start_execution_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule WandaWeb.Schemas.V2.Execution.StartExecutionRequest do
title: "Target",
description: "Target Agent on which facts gathering should happen",
type: :object,
additionalProperties: false,
properties: %{
agent_id: %Schema{
type: :string,
Expand All @@ -37,6 +38,7 @@ defmodule WandaWeb.Schemas.V2.Execution.StartExecutionRequest do
title: "StartExecutionRequest",
description: "Context to run a Check Execution",
type: :object,
additionalProperties: false,
properties: %{
execution_id: %Schema{type: :string, format: :uuid, description: "Execution identifier"},
group_id: %Schema{type: :string, format: :uuid, description: "Group Execution identifier"},
Expand Down
1 change: 1 addition & 0 deletions lib/wanda_web/schemas/v3/catalog/catalog_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule WandaWeb.Schemas.V3.Catalog.CatalogResponse do
title: "CatalogResponse",
description: "Checks catalog listing response",
type: :object,
additionalProperties: false,
properties: %{
items: %Schema{type: :array, description: "List of catalog checks", items: Check}
}
Expand Down
Loading

0 comments on commit def1f36

Please sign in to comment.