mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
entc/gen: make custom field comment render as additional line(s) (#1234)
* Make custom field comment render as additional line(s) * Make the test for the comment aware of the new format
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -21,15 +21,19 @@ import (
|
||||
type {{ $.Name }} struct {
|
||||
config {{ template "model/omittags" $ }}
|
||||
// ID of the ent.
|
||||
{{- if $.ID.Comment }}
|
||||
{{- range $line := split $.ID.Comment "\n" }}
|
||||
// {{ $line }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
ID {{ $.ID.Type }} {{ with $.Annotations.Fields.StructTag.id }}`{{ . }}`{{ else }}`{{ $.ID.StructTag }}`{{ end }}
|
||||
{{- range $f := $.Fields }}
|
||||
{{- $tag := $f.StructTag }}{{ with $tags := $.Annotations.Fields.StructTag }}{{ with index $tags $f.Name }}{{ $tag = . }}{{ end }}{{ end }}
|
||||
// {{ $f.StructField }} holds the value of the "{{ $f.Name }}" field.
|
||||
{{- if $f.Comment }}
|
||||
{{- range $line := split $f.Comment "\n" }}
|
||||
// {{ $line }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
// {{ $f.StructField }} holds the value of the "{{ $f.Name }}" field.
|
||||
{{- end }}
|
||||
{{ $f.StructField }} {{ if $f.Nillable }}*{{ end }}{{ $f.Type }} {{ if not $f.Sensitive }}`{{ $tag }}`{{ else }}{{ template "model/omittags" $ }}{{ end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestSchemaConfig(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
if f, ok := n.(*ast.Field); ok && len(f.Names) > 0 && f.Names[0].Name == fd.Name {
|
||||
require.Equal(t, fd.Comment, f.Doc.Text())
|
||||
require.Contains(t, fd.Comment, f.Doc.Text())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -19,6 +19,7 @@ type User struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
// Comment line1
|
||||
// Comment line2
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
@@ -27,6 +27,7 @@ type Card struct {
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"-"`
|
||||
// Name holds the value of the "name" field.
|
||||
// Exact name written on card
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
@@ -29,6 +29,7 @@ type Group struct {
|
||||
Type *string `json:"type,omitempty"`
|
||||
// MaxUsers holds the value of the "max_users" field.
|
||||
MaxUsers int `json:"max_users,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
// field with multiple validators
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
@@ -26,6 +26,7 @@ type Card struct {
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"-"`
|
||||
// Name holds the value of the "name" field.
|
||||
// Exact name written on card
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
@@ -28,6 +28,7 @@ type Group struct {
|
||||
Type *string `json:"type,omitempty"`
|
||||
// MaxUsers holds the value of the "max_users" field.
|
||||
MaxUsers int `json:"max_users,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
// field with multiple validators
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
@@ -23,10 +23,12 @@ type Card struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"number,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
// Exact name written on card
|
||||
Name string `json:"name,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// InHook holds the value of the "in_hook" field.
|
||||
// A mandatory field that is set by the hook
|
||||
InHook string `json:"in_hook,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
Reference in New Issue
Block a user