ash-project / spark

Tooling for building DSLs in Elixir
MIT License
105 stars 23 forks source link

Documentation Improvements for Spark.Dsl.Entity #39

Open erikaaus opened 1 year ago

erikaaus commented 1 year ago

Proposal

This issues is to keep track of improvement ideas for the documentation for Spark.Dsl.Entity.

Questions

Work to be done

erikaaus commented 1 year ago

Question: What are deprecations? They're typed as a keyword list of strings.

Question: What's the difference between describe and docs?

erikaaus commented 1 year ago

Question: What is the examples field for?

erikaaus commented 1 year ago

Question: What is an example of an identifier? It's mentioned in the moduledoc, but it was automatically added to the typespec by Elixir, so it's listed as term().

zachdaniel commented 1 year ago

Question: What are deprecations? They're typed as a keyword list of strings.

Question: What's the difference between describe and docs?

deprecations are specific keys in the schema that have been deprecated. i.e deprecations: [name: "The name option has been deprecated, use surname"] instead.

describe is your user provided documentation. docs should not be set by the user. It is an internal field.

zachdaniel commented 1 year ago

Question: What is the examples field for?

The examples field allows you to show examples of a given section or entity. For example:

@attribute %Spark.Dsl.Entity{
  name: :attribute,
  ...,
  examples: [
    """
    attribute :foo, :string
    """
  ]
}

It should be shown in the automatically generated documentation.

zachdaniel commented 1 year ago

Question: What is an example of an identifier? It's mentioned in the moduledoc, but it was automatically added to the typespec by Elixir, so it's listed as term().

identifier refers to a field on the entity that it should be unique on. For example, in Ash.Resource the attribute resource is unique on :name. The type should be {:auto, :unique_integer} to automatically generate a unique integer identifier, or an atom. The {:auto, :unique_integer} kinda sounds useless at first, but entities with an identifier set on them can be used with Spark.Dsl.Transformer.replace_entity without having to pass a replacement function, which can be useful where nothing specific identifies a given entity and you have to programatically transform them.

erikareads commented 1 year ago

The type should be {:auto, :unique_integer} to automatically generate a unique integer identifier, or an atom.

To be clear, is that the type set by the user in their Entity, or is it the type generated by Spark if the user opts in?

If the former, I believe the type would be @type id :: {:auto, :unique_integer} | nil to reflect the fact that a user may opt out of using the identifier?

zachdaniel commented 1 year ago

yes, you are correct 👍