Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing Schema Comment Placement in Generated Structs #4051

Open
tommynanny opened this issue May 11, 2024 · 0 comments
Open

Customizing Schema Comment Placement in Generated Structs #4051

tommynanny opened this issue May 11, 2024 · 0 comments

Comments

@tommynanny
Copy link

I'm currently using the ent framework for my project with https://github.com/swaggo/swag

Specifically, I'm using the Annotations method to add comments to my schema structs. However, the generated comments are placed above the struct definition, whereas I need them to be placed at the end of the struct.

Here's an example of how I'm currently defining annotations:

package "<project>/ent/schema"

// annotations of the Mission
func (Mission) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{Table: "EntMission"},
		schema.Comment(
			`
@description Mission model defines the structure of a mission
@name Mission`,
		),
	}
}

The above code generates comments above the struct definition which is fine in most cases.

package "<project>/ent"

// @description Mission model defines the structure of a mission
// @name Mission
type Mission struct {
	config `json:"-"`
        ...
}

But when testing with swag init to generate the swag doc which has reference to the generated Mission struct, the @name Mission placing in front of the struct as it is shown above does not seem to have any effect, instead, manually editing the generated Mission struct by placing the the @name Mission after the struct seems to be working as mentioned here "rename model to display"

package "<project>/ent"

// @description Mission model defines the structure of a mission
type Mission struct {
	config `json:"-"`
        ...
} // @name Mission

I am new to golang, and I am not sure what might be the best practice here - is it possible to have an option for schema comment generated after the struct or did I just miss something very obvious here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant