fireproofsocks

fireproofsocks

I’m working to document a large Elixir project and I’ve noticed that the Ecto schemas do not provide detailed types for their structs.

The best I’ve come up with is to include

@type t :: %__MODULE__{}

inside my Ecto schema modules. This at least causes the shape of the struct to show up in the docs, but it’s not what I would consider “polished”. In the generated ExDoc pages, the type includes the __meta__ attribute (which is confusing to any onlooker unfamiliar with Elixir) and all the values are represented with the term() catch-all:

@type t() :: %MyEctoSchema{
  __meta__: term(),
  foo: term(),
  bar: term(),
  # ...

The source-code says “Generating typespecs for schemas is out of the scope of Ecto.Schema” and that “t/0 has to be defined manually”… but when I tried manually adding my struct fields (in the way I would if this were a normal non-Ecto struct), my definitions all seem to be ignored regardless – it seems that no matter what I define, the output is the same default (with the __meta__ field and every field type as term()).

I did some noodling when I put together the inspecto package, but I don’t think it helps here since I don’t think you can dynamically assemble a type definition (or maybe you can in a macro?).

I think I’m probably missing something so I thought I’d do a sanity check here in the forum. Thanks for any insights!

Showing Posts 1 to 4

LostKobrakai

LostKobrakai

A ecto schema has a __meta__ field if you want it or not. It’s used to store metadata (see Ecto.get_meta). Doing %MyEctoSchema{} will make sure all keys of the schema are part of the typespec no matter if you explicitly type them or not.

vrod

vrod

What seems to be a bug is that the fields are listed explicitly, the documentation for the type do not update.

LostKobrakai

LostKobrakai

I just tried it out in a project of mine and the docs update just fine for explicitly listed keys.

fireproofsocks

fireproofsocks OP

Ah, I see it now – even if you force the fields in your own type definition, all the other fields are still filled in (with the default term() catch-alls)

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews