Repository: goadesign/goa (go)

Issue:
Missing descriptions after bumping from 3.5.4 to 3.5.5
We just bumped Goa, and noticed the following change:
<img width="893" alt="CleanShot 2022-02-11 at 09 23 59@2x" src="https://user-images.githubusercontent.com/1005/153566720-c35272f6-2f84-478b-8db3-d97464389106.png">

This is from the following snippets:
```go
var UUID = Type("UUID", String, func() {
	Format(FormatUUID)
})

// ...
// Payload...
      Attribute("id", UUID, "Offer ID")
// ...
```

Looking at the changelog, I believe it's due to [this change](https://github.com/goadesign/goa/pull/2991).


Pull request description:
Properly generate format
for primitive alias types in OpenAPI spec v3

Fixes #2995

Patch:
diff --git a/http/codegen/openapi/v3/types.go b/http/codegen/openapi/v3/types.go
index e021260c..01cec5ef 100644
--- a/http/codegen/openapi/v3/types.go
+++ b/http/codegen/openapi/v3/types.go
@@ -141,13 +141,8 @@ func (sf *schemafier) schemafy(attr *expr.AttributeExpr, noref ...bool) *openapi
 	s := openapi.NewSchema()
 	var note string
 
-	unaliased := attr
-	if expr.IsAlias(attr.Type) {
-		unaliased = attr.Type.(expr.UserType).Attribute()
-	}
-
 	// Initialize type and format
-	switch t := unaliased.Type.(type) {
+	switch t := attr.Type.(type) {
 	case expr.Primitive:
 		switch t.Kind() {
 		case expr.UIntKind, expr.UInt64Kind, expr.UInt32Kind:
@@ -192,21 +187,25 @@ func (sf *schemafier) schemafy(attr *expr.AttributeExpr, noref ...bool) *openapi
 			s.AdditionalProperties = true
 		}
 	case expr.UserType:
-		h := sf.hashAttribute(attr, fnv.New64())
-		ref, ok := sf.hashes[h]
-		if len(noref) == 0 && ok {
-			s.Ref = ref
-		} else {
-			name := t.Name()
-			if n, ok := t.Attribute().Meta["name:original"]; ok {
-				name = n[0]
+		if !expr.IsAlias(t) {
+			h := sf.hashAttribute(attr, fnv.New64())
+			ref, ok := sf.hashes[h]
+			if len(noref) == 0 && ok {
+				s.Ref = ref
+			} else {
+				name := t.Name()
+				if n, ok := t.Attribute().Meta["name:original"]; ok {
+					name = n[0]
+				}
+				typeName := sf.uniquify(codegen.Goify(name, true))
+				s.Ref = toRef(typeName)
+				sf.hashes[h] = s.Ref
+				sf.schemas[typeName] = sf.schemafy(t.Attribute(), true)
 			}
-			typeName := sf.uniquify(codegen.Goify(name, true))
-			s.Ref = toRef(typeName)
-			sf.hashes[h] = s.Ref
-			sf.schemas[typeName] = sf.schemafy(t.Attribute(), true)
+			return s // All other schema properties are set in the reference
 		}
-		return s // All other schema properties are set in the reference
+		// Alias primitive type
+		s = sf.schemafy(t.Attribute())
 	default:
 		panic(fmt.Sprintf("unknown type %T", t)) // bug
 	}


Test patch:
diff --git a/http/codegen/openapi/v3/testdata/dsls/types.go b/http/codegen/openapi/v3/testdata/dsls/types.go
index 06a97bfe..2cef0ae2 100644
--- a/http/codegen/openapi/v3/testdata/dsls/types.go
+++ b/http/codegen/openapi/v3/testdata/dsls/types.go
@@ -15,6 +15,22 @@ func StringBodyDSL(svcName, metName string) func() {
 	}
 }
 
+func AliasStringBodyDSL(svcName, metName string) func() {
+	return func() {
+		var UUID = Type("UUID", String, func() {
+			Format(FormatUUID)
+		})
+		var _ = Service(svcName, func() {
+			Method(metName, func() {
+				Payload(UUID)
+				HTTP(func() {
+					POST("/")
+				})
+			})
+		})
+	}
+}
+
 func ObjectBodyDSL(svcName, metName string) func() {
 	return func() {
 		var _ = Service(svcName, func() {
diff --git a/http/codegen/openapi/v3/types_test.go b/http/codegen/openapi/v3/types_test.go
index 5ac617fb..7325c034 100644
--- a/http/codegen/openapi/v3/types_test.go
+++ b/http/codegen/openapi/v3/types_test.go
@@ -14,6 +14,7 @@ import (
 // describes a type for comparison in tests.
 type typ struct {
 	Type      string
+	Format    string
 	Props     []attr
 	SkipProps bool
 }
@@ -30,6 +31,7 @@ type rt map[int]typ
 var (
 	tempty  typ
 	tstring = typ{Type: "string"}
+	tuuid   = typ{Type: "string", Format: "uuid"}
 	tint    = typ{Type: "integer"}
 	tarray  = typ{Type: "array"}
 )
@@ -62,6 +64,7 @@ func TestBuildBodyTypes(t *testing.T) {
 		DSL  func()
 
 		ExpectedType          typ
+		ExpectedFormat        string
 		ExpectedResponseTypes rt
 	}{{
 		Name: "string_body",
@@ -69,6 +72,12 @@ func TestBuildBodyTypes(t *testing.T) {
 
 		ExpectedType:          tstring,
 		ExpectedResponseTypes: rt{204: tempty},
+	}, {
+		Name: "alias_string_body",
+		DSL:  dsls.AliasStringBodyDSL(svcName, "alias_string_body"),
+
+		ExpectedType:          tuuid,
+		ExpectedResponseTypes: rt{204: tempty},
 	}, {
 		Name: "object_body",
 		DSL:  dsls.ObjectBodyDSL(svcName, "object_body"),
@@ -186,6 +195,11 @@ func matchesSchemaWithPrefix(t *testing.T, ctx string, s *openapi.Schema, types
 	if tt.Type != string(s.Type) {
 		t.Errorf("%s: %sgot type %q, expected %q", ctx, prefix, s.Type, tt.Type)
 	}
+	if tt.Format != "" {
+		if s.Format != tt.Format {
+			t.Errorf("%s: %sgot format %q, expected %q", ctx, prefix, s.Format, tt.Format)
+		}
+	}
 	if tt.Type == "object" {
 		if tt.SkipProps {
 			return