goa
goa copied to clipboard
question: how to have uuid.UUID as type but still specify `format: uuid` in openapi spec?
We have this UUID field:
dsl.Field(0, "id", dsl.String, func() {
// Serialize it with `uuid.UUID`.
dsl.Meta("struct:field:type", "uuid.UUID", "github.com/google/uuid")
// Some other stuff, for tags in GO...
dsl.Meta("struct:tag:yaml", "id")
})
instead of
dsl.Field(0, "id", dsl.String, func() {
// Use the string formatting checks.
dsl.Format(dsl.FormatUUID)
// Some other stuff, for tags in GO...
dsl.Meta("struct:tag:yaml", "id")
})
The latter however nicely puts the format: uuid on the openapi spec.
Is there a way to hack that in as well for the first use case which is much more nice to use in Go?
dsl.Field(0, "id", dsl.String, func() {
// Use the string formatting checks.
dsl.Format(dsl.FormatUUID)
// Serialize it with `uuid.UUID`.
dsl.Meta("struct:field:type", "uuid.UUID", "github.com/google/uuid")
// Some other stuff, for tags in GO...
dsl.Meta("struct:tag:yaml", "id")
})
I should do the trick.
@ichbestimmtnicht : That does not work.
I made this note in the code:
// NOTE: `d.Format(d.FormatUUID)` : Does not work currently, since validation
// comes after serialization which only works for strings with `d.Format`.
d.Meta("struct:field:type", "uuid.UUID", "github.com/google/uuid")
d.Example("UUID", "c9ae032e-e4d7-4556-9d50-b19e0c7bc6c4")