Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open api spex object refactor #2780

Merged
merged 4 commits into from
Jul 16, 2024
Merged

Open api spex object refactor #2780

merged 4 commits into from
Jul 16, 2024

Conversation

CDimonaco
Copy link
Member

Description

This PR change the use of OpenApiSpex macro, to include struct?:false as parameter.

This allow us to better pattern match into the controller action functions and also allow us to not decode the body_params into a map, and pass them directly to ecto, as phoenix convention.

The validation of the paramters and openapi definition remains untouched.

Other small controller fixes added.

Tested.

@CDimonaco CDimonaco added tech debt elixir Pull requests that update Elixir code labels Jul 15, 2024
@CDimonaco CDimonaco requested review from balanza and arbulu89 July 15, 2024 10:10
@CDimonaco CDimonaco self-assigned this Jul 15, 2024
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
I'm not 100% what we "solve" with this exactly, except one decode function, as everything else remains untouched in essence

It's a pity that there is not any way to set struct? default value as false somehow.
Otherwise, we need to remember always to add the value, and it looks like something we can forget pretty easily. I hope we don't 😅

Maybe we could have our own macro for that

@@ -116,7 +112,4 @@ defmodule TrentoWeb.V1.SUMACredentialsController do
end

def get_policy_resource(_), do: Trento.SoftwareUpdates.Settings

defp decode_body(body) when is_struct(body), do: Map.from_struct(body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the unique real place where we are forced to decode to map?
As far as I see, we can get the remaining fields exactly the same way without the struct? field

@CDimonaco CDimonaco marked this pull request as draft July 15, 2024 12:59
@CDimonaco CDimonaco force-pushed the open_api_spex_object_refactor branch from 2fb1833 to 732d355 Compare July 15, 2024 14:11
@CDimonaco CDimonaco marked this pull request as ready for review July 15, 2024 14:21
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@CDimonaco CDimonaco force-pushed the open_api_spex_object_refactor branch from e8cf6de to 4e198f4 Compare July 16, 2024 09:00
@CDimonaco CDimonaco merged commit 32ff8c6 into main Jul 16, 2024
26 checks passed
@CDimonaco CDimonaco deleted the open_api_spex_object_refactor branch July 16, 2024 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elixir Pull requests that update Elixir code tech debt
Development

Successfully merging this pull request may close these issues.

2 participants