slice for tags

This commit is contained in:
Shreyas Goenka 2024-09-06 15:22:06 +02:00
parent 1dd399f3fe
commit 75a571a56d
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 15 additions and 13 deletions

View File

@ -10,17 +10,19 @@ import (
"strings"
)
var skipTags = []string{
// Fields tagged "readonly" should not be emitted in the schema as they are
// computed at runtime, and should not be assigned a value by the bundle author.
const readonlyTag = "readonly"
"readonly",
// Annotation for internal bundle fields that should not be exposed to customers.
// Fields can be tagged as "internal" to remove them from the generated schema.
const internalTag = "internal"
"internal",
// Annotation for bundle fields that have been deprecated.
// Fields tagged as "deprecated" are omitted from the generated schema.
const deprecatedTag = "deprecated"
"deprecated",
}
type constructor struct {
// Map of typ.PkgPath() + "." + typ.Name() to the schema for that type.
@ -251,11 +253,11 @@ func (c *constructor) fromTypeStruct(typ reflect.Type) (Schema, error) {
bundleTags := strings.Split(structField.Tag.Get("bundle"), ",")
// Fields marked as "readonly", "internal" or "deprecated" are skipped
// while generating the schema
if slices.Contains(bundleTags, readonlyTag) ||
slices.Contains(bundleTags, internalTag) ||
slices.Contains(bundleTags, deprecatedTag) {
for _, tag := range skipTags {
if slices.Contains(bundleTags, tag) {
continue
}
}
jsonTags := strings.Split(structField.Tag.Get("json"), ",")
fieldName := jsonTags[0]