Skip to content

Commit

Permalink
Openapi spex objects refactor (#484)
Browse files Browse the repository at this point in the history
* OpenApiSpex schemas with struct?: false

* OpenApiSpex bumped to 3.19.1

* Controllers refactored to new api schemas
  • Loading branch information
CDimonaco authored Jul 16, 2024
1 parent 012fd30 commit d9d22d4
Show file tree
Hide file tree
Showing 33 changed files with 917 additions and 826 deletions.
7 changes: 3 additions & 4 deletions lib/wanda_web/controllers/v1/execution_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ defmodule WandaWeb.V1.ExecutionController do
execution_id: execution_id,
group_id: group_id,
targets: targets,
env: env
} = body_params = Map.get(conn, :body_params)

target_type = Map.get(body_params, :target_type)
env: env,
target_type: target_type
} = OpenApiSpex.body_params(conn)

with :ok <-
execution_server_impl().start_execution(
Expand Down
7 changes: 3 additions & 4 deletions lib/wanda_web/controllers/v2/execution_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ defmodule WandaWeb.V2.ExecutionController do
execution_id: execution_id,
group_id: group_id,
targets: targets,
env: env
} = body_params = Map.get(conn, :body_params)

target_type = Map.get(body_params, :target_type)
env: env,
target_type: target_type
} = OpenApiSpex.body_params(conn)

with :ok <-
execution_server_impl().start_execution(
Expand Down
23 changes: 13 additions & 10 deletions lib/wanda_web/schemas/accepted_execution_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ defmodule WandaWeb.Schemas.AcceptedExecutionResponse do

require OpenApiSpex

OpenApiSpex.schema(%{
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}
}
})
OpenApiSpex.schema(
%{
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}
}
},
struct?: false
)
end
39 changes: 21 additions & 18 deletions lib/wanda_web/schemas/bad_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ defmodule WandaWeb.Schemas.BadRequest do

require OpenApiSpex

OpenApiSpex.schema(%{
title: "BadRequest",
type: :object,
additionalProperties: false,
properties: %{
errors: %Schema{
type: :array,
items: %Schema{
type: :object,
additionalProperties: false,
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,
additionalProperties: false,
properties: %{
detail: %Schema{
type: :string,
example: "Invalid request payload."
},
title: %Schema{type: :string, example: "Bad Request"}
}
}
}
}
}
})
},
struct?: false
)

def response do
Operation.response(
Expand Down
31 changes: 17 additions & 14 deletions lib/wanda_web/schemas/health.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ defmodule WandaWeb.Schemas.Health do

require OpenApiSpex

OpenApiSpex.schema(%Schema{
title: "Health",
type: :object,
additionalProperties: false,
example: %{
database: "pass"
},
properties: %{
database: %Schema{
description: "The status of the database connection",
type: :string,
enum: ["pass", "fail"]
OpenApiSpex.schema(
%Schema{
title: "Health",
type: :object,
additionalProperties: false,
example: %{
database: "pass"
},
properties: %{
database: %Schema{
description: "The status of the database connection",
type: :string,
enum: ["pass", "fail"]
}
}
}
})
},
struct?: false
)

def response do
Operation.response(
Expand Down
33 changes: 18 additions & 15 deletions lib/wanda_web/schemas/not_found.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ defmodule WandaWeb.Schemas.NotFound do

require OpenApiSpex

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"}
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"}
}
}
}
}
}
})
},
struct?: false
)

def response do
Operation.response(
Expand Down
29 changes: 16 additions & 13 deletions lib/wanda_web/schemas/ready.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ defmodule WandaWeb.Schemas.Ready do

require OpenApiSpex

OpenApiSpex.schema(%Schema{
title: "Ready",
type: :object,
additionalProperties: false,
example: %{
ready: true
},
properties: %{
ready: %Schema{
description: "Wanda platform ready",
type: :boolean
OpenApiSpex.schema(
%Schema{
title: "Ready",
type: :object,
additionalProperties: false,
example: %{
ready: true
},
properties: %{
ready: %Schema{
description: "Wanda platform ready",
type: :boolean
}
}
}
})
},
struct?: false
)

def response do
Operation.response(
Expand Down
21 changes: 12 additions & 9 deletions lib/wanda_web/schemas/v1/catalog/catalog_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ defmodule WandaWeb.Schemas.V1.Catalog.CatalogResponse do

require OpenApiSpex

OpenApiSpex.schema(%{
title: "CatalogResponse",
description: "Checks catalog listing response",
type: :object,
additionalProperties: false,
properties: %{
items: %Schema{type: :array, description: "List of catalog checks", items: Check}
}
})
OpenApiSpex.schema(
%{
title: "CatalogResponse",
description: "Checks catalog listing response",
type: :object,
additionalProperties: false,
properties: %{
items: %Schema{type: :array, description: "List of catalog checks", items: Check}
}
},
struct?: false
)
end
Loading

0 comments on commit d9d22d4

Please sign in to comment.