-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add openapi schemas * Enhance Fallback controller and error json view * Add customization controller and initial action * Add extra tests for follback controller * Add extra validation tests * Adjust custom value openapi schema description * Adjust matching in error json
- Loading branch information
1 parent
057a909
commit 22c0419
Showing
13 changed files
with
616 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
lib/wanda_web/controllers/v1/checks_customizations_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule WandaWeb.V1.ChecksCustomizationsController do | ||
use WandaWeb, :controller | ||
use OpenApiSpex.ControllerSpecs | ||
|
||
alias OpenApiSpex.Schema | ||
|
||
alias WandaWeb.Schemas.{BadRequest, Forbidden} | ||
alias WandaWeb.Schemas.V1.ChecksCustomizations.{CustomizationRequest, CustomizationResponse} | ||
|
||
alias Wanda.ChecksCustomizations | ||
|
||
plug OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true | ||
action_fallback WandaWeb.FallbackController | ||
|
||
operation :apply_custom_values, | ||
summary: "Apply custom values for a specific check", | ||
parameters: [ | ||
check_id: [ | ||
in: :path, | ||
description: "Identifier of the specific check that is being customized", | ||
type: %Schema{ | ||
type: :string | ||
}, | ||
example: "ABC123" | ||
], | ||
group_id: [ | ||
in: :path, | ||
description: "Identifier of the group for which a custom value should be applied", | ||
type: %Schema{ | ||
type: :string, | ||
format: :uuid | ||
}, | ||
example: "00000000-0000-0000-0000-000000000001" | ||
] | ||
], | ||
request_body: {"Custom Values", "application/json", CustomizationRequest}, | ||
responses: [ | ||
ok: {"Check Customizations", "application/json", CustomizationResponse}, | ||
forbidden: Forbidden.response(), | ||
bad_request: BadRequest.response(), | ||
unprocessable_entity: OpenApiSpex.JsonErrorResponse.response() | ||
] | ||
|
||
def apply_custom_values(conn, %{check_id: check_id, group_id: group_id}) do | ||
%{values: custom_values} = OpenApiSpex.body_params(conn) | ||
|
||
with {:ok, customization} <- ChecksCustomizations.customize(check_id, group_id, custom_values) do | ||
render(conn, :check_customization, %{customization: customization}) | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
lib/wanda_web/controllers/v1/checks_customizations_json.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule WandaWeb.V1.ChecksCustomizationsJSON do | ||
alias Wanda.Catalog.CheckCustomization | ||
|
||
def check_customization(%{ | ||
customization: %CheckCustomization{ | ||
custom_values: values | ||
} | ||
}) do | ||
%{ | ||
values: values | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule WandaWeb.Schemas.Forbidden do | ||
@moduledoc """ | ||
403 - Forbidden | ||
""" | ||
|
||
alias OpenApiSpex.Operation | ||
alias OpenApiSpex.Schema | ||
|
||
require OpenApiSpex | ||
|
||
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( | ||
"Forbidden", | ||
"application/json", | ||
__MODULE__ | ||
) | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
lib/wanda_web/schemas/v1/checks_customizations/custom_value.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule WandaWeb.Schemas.V1.ChecksCustomizations.CustomValue do | ||
@moduledoc """ | ||
Custom value to be applied or already applied to a check | ||
""" | ||
|
||
alias OpenApiSpex.Schema | ||
|
||
require OpenApiSpex | ||
|
||
OpenApiSpex.schema( | ||
%{ | ||
title: "CustomValue", | ||
description: "A single custom value to be applied or already applied to a check", | ||
type: :object, | ||
additionalProperties: false, | ||
properties: %{ | ||
name: %Schema{type: :string, description: "Name of the specific value to be customized"}, | ||
value: %Schema{ | ||
description: "Overriding value", | ||
oneOf: [ | ||
%Schema{type: :string}, | ||
%Schema{type: :number}, | ||
%Schema{type: :boolean} | ||
] | ||
} | ||
}, | ||
required: [:name, :value] | ||
}, | ||
struct?: false | ||
) | ||
end |
30 changes: 30 additions & 0 deletions
30
lib/wanda_web/schemas/v1/checks_customizations/customization_request.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule WandaWeb.Schemas.V1.ChecksCustomizations.CustomizationRequest do | ||
@moduledoc """ | ||
Request to customize a check | ||
""" | ||
|
||
alias OpenApiSpex.Schema | ||
alias WandaWeb.Schemas.V1.ChecksCustomizations.CustomValue | ||
|
||
require OpenApiSpex | ||
|
||
OpenApiSpex.schema( | ||
%{ | ||
title: "CustomizationRequest", | ||
description: "Request to customize a check", | ||
type: :object, | ||
additionalProperties: false, | ||
minProperties: 1, | ||
properties: %{ | ||
values: %Schema{ | ||
type: :array, | ||
description: "List of values to customize", | ||
items: CustomValue, | ||
minItems: 1 | ||
} | ||
}, | ||
required: [:values] | ||
}, | ||
struct?: false | ||
) | ||
end |
27 changes: 27 additions & 0 deletions
27
lib/wanda_web/schemas/v1/checks_customizations/customization_response.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule WandaWeb.Schemas.V1.ChecksCustomizations.CustomizationResponse do | ||
@moduledoc """ | ||
Response for a customization operation | ||
""" | ||
alias WandaWeb.Schemas.V1.ChecksCustomizations.CustomValue | ||
|
||
alias OpenApiSpex.Schema | ||
|
||
require OpenApiSpex | ||
|
||
OpenApiSpex.schema( | ||
%{ | ||
title: "CustomizationResponse", | ||
description: "Response for a customization", | ||
type: :object, | ||
additionalProperties: false, | ||
properties: %{ | ||
values: %Schema{ | ||
type: :array, | ||
description: "List of the custom values applied", | ||
items: CustomValue | ||
} | ||
} | ||
}, | ||
struct?: false | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.