entc: improve generated comments for edges and fields (#2632)

* replace default field comment with user comment if defined
* use comments defined on edges in generated entities
* add docs for comment method on edges and fields
* update integration to reflect above changes
This commit is contained in:
Will Bicks
2022-06-13 08:52:47 -04:00
committed by GitHub
parent 1572f1eb14
commit cd1afb235c
24 changed files with 88 additions and 31 deletions

View File

@@ -1416,6 +1416,23 @@ However, you should note, that this is currently an SQL-only feature.
Read more about this in the [Indexes](schema-indexes.md) section.
## Comments
A comment can be added to the edge using the `.Comment()` method. This comment
appears before the edge in the generated entity code. Newlines are supported
using the `\n` escape sequence.
```go
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("pets", Pet.Type).
Comment("Pets that this user is responsible for taking care of.\n" +
"May be zero to many, depending on the user.")
}
}
```
## Annotations
`Annotations` is used to attach arbitrary metadata to the edge object in code generation.

View File

@@ -508,6 +508,23 @@ func (User) Fields() []ent.Field {
}
```
## Comments
A comment can be added to a field using the `.Comment()` method. This comment
appears before the field in the generated entity code. Newlines are supported
using the `\n` escape sequence.
```go
// Fields of the user.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("John Doe").
Comment("Name of the user.\n If not specified, defaults to \"John Doe\"."),
}
}
```
## Storage Key
Custom storage name can be configured using the `StorageKey` method.