goa icon indicating copy to clipboard operation
goa copied to clipboard

question: how to have uuid.UUID as type but still specify `format: uuid` in openapi spec?

Open gabyx opened this issue 6 months ago • 2 comments

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?

gabyx avatar Aug 06 '25 07:08 gabyx

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 avatar Nov 07 '25 16:11 ichbestimmtnicht

@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")

gabyx avatar Nov 11 '25 14:11 gabyx