Hi guys.
I have input data with two fields: data - base64 string signature - signed data field.
Field data has predicted structure and I need to validate it.
I need combination of custom type (Base64) and embed schema.
Is it possible to create embed schema on base64 string?
Something like that:
embedded_schema do
embeds_one :data, Data, type: Base64 do
field :id, Ecto.UUID
field :password, :string
field :date, :string
end
field(:signature, :string)
end
Also if you want to understand the reason why you shouldn’t use uuid as a primary key you can read this thread where i asked a lot of questions regarding this topic Best way to generate an UUID for the id field?
As you can see, I’m using embedded_schema, that not generates primary key.
It’s because this schema for request validation and will not used with ecto_sql.
I know that default UUID generates at compile-time, but this is not me case
that’s close to what I do.
I’ve created custom type Base64, that expects base64 string and decode it to map.
Then I’m using validate_change/3 for validation.
But I thought that maybe there is a more elegant way to do this.