Repository: goadesign/goa
Pull request #3572 (2024-08-08 04:52:37)

Add "openapi:typename" meta to user types
This update forces OpenAPI generators to use specified type names rather than merging structurally identical types automatically.

Note: Goa-generated types (e.g., from anonymous payload or result definitions) will still be merged if structurally identical. This approach helps prevent the unnecessary proliferation of types in OpenAPI specifications.


Patch:
diff --git a/dsl/result_type.go b/dsl/result_type.go
index d10eb4b3..d8e503b9 100644
--- a/dsl/result_type.go
+++ b/dsl/result_type.go
@@ -116,6 +116,7 @@ func ResultType(identifier string, args ...any) *expr.ResultTypeExpr {
 	}
 	// Add the type to the generated types root for later evaluation.
 	rt := expr.NewResultTypeExpr(typeName, identifier, fn)
+	rt.Meta = expr.MetaExpr{"openapi:typename": []string{typeName}}
 	expr.Root.ResultTypes = append(expr.Root.ResultTypes, rt)
 
 	return rt
diff --git a/dsl/user_type.go b/dsl/user_type.go
index 8f18474a..bdd67ecb 100644
--- a/dsl/user_type.go
+++ b/dsl/user_type.go
@@ -103,8 +103,12 @@ func Type(name string, args ...any) expr.UserType {
 	}
 
 	t := &expr.UserTypeExpr{
-		TypeName:      name,
-		AttributeExpr: &expr.AttributeExpr{Type: base, DSLFunc: fn},
+		TypeName: name,
+		AttributeExpr: &expr.AttributeExpr{
+			Type:    base,
+			DSLFunc: fn,
+			Meta:    expr.MetaExpr{"openapi:typename": []string{name}},
+		},
 	}
 	expr.Root.Types = append(expr.Root.Types, t)
 	return t


Test patch:
diff --git a/http/codegen/openapi/v2/files_test.go b/http/codegen/openapi/v2/files_test.go
index 9335ab37..8a5685bc 100644
--- a/http/codegen/openapi/v2/files_test.go
+++ b/http/codegen/openapi/v2/files_test.go
@@ -13,6 +13,7 @@ import (
 
 	"github.com/getkin/kin-openapi/openapi2"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 
 	httpgen "goa.design/goa/v3/http/codegen"
 	"goa.design/goa/v3/http/codegen/openapi"
@@ -99,15 +100,15 @@ func TestSections(t *testing.T) {
 						t.Fatalf("failed to read golden file: %s", err)
 					}
 					if !bytes.Equal(buf.Bytes(), want) {
-						var left, right string
+						var got, expected string
 						if filepath.Ext(o.Path) == ".json" {
-							left = prettifyJSON(t, buf.Bytes())
-							right = prettifyJSON(t, want)
+							got = prettifyJSON(t, buf.Bytes())
+							expected = prettifyJSON(t, want)
 						} else {
-							left = buf.String()
-							right = string(want)
+							got = buf.String()
+							expected = string(want)
 						}
-						assert.Equal(t, left, right)
+						assert.Equal(t, expected, got)
 					}
 				})
 			}
@@ -145,51 +146,32 @@ func TestValidations(t *testing.T) {
 			openapi.Definitions = make(map[string]*openapi.Schema)
 			root := httpgen.RunHTTPDSL(t, c.DSL)
 			oFiles, err := openapiv2.Files(root)
-			if err != nil {
-				t.Fatalf("OpenAPI failed with %s", err)
-			}
-			if len(oFiles) == 0 {
-				t.Fatalf("No swagger files")
-			}
+			require.NoError(t, err, "OpenAPI failed")
+			require.NotEmpty(t, oFiles, "No swagger files")
 			for i, o := range oFiles {
 				tname := fmt.Sprintf("file%d", i)
 				s := o.SectionTemplates
 				t.Run(tname, func(t *testing.T) {
-					if len(s) != 1 {
-						t.Fatalf("expected 1 section, got %d", len(s))
-					}
-					if s[0].Source == "" {
-						t.Fatalf("empty section template")
-					}
-					if s[0].Data == nil {
-						t.Fatalf("nil data")
-					}
+					require.Len(t, s, 1, "expected 1 section, got %d", len(s))
+					require.NotEmpty(t, s[0].Source, "empty section template")
+					require.NotNil(t, s[0].Data, "nil data")
 					var buf bytes.Buffer
 					tmpl := template.Must(template.New("openapi").Funcs(s[0].FuncMap).Parse(s[0].Source))
-					if err := tmpl.Execute(&buf, s[0].Data); err != nil {
-						t.Fatalf("failed to render template: %s", err)
-					}
+					require.NoError(t, tmpl.Execute(&buf, s[0].Data), "failed to render template")
 					if filepath.Ext(o.Path) == ".json" {
-						if err := validateSwagger(buf.Bytes()); err != nil {
-							t.Fatalf("invalid swagger: %s", err)
-						}
+						require.NoError(t, validateSwagger(buf.Bytes()), "invalid swagger")
 					}
 
 					golden := filepath.Join(goldenPath, fmt.Sprintf("%s_%s.golden", c.Name, tname))
 					if *update {
-						if err := os.WriteFile(golden, buf.Bytes(), 0644); err != nil {
-							t.Fatalf("failed to update golden file: %s", err)
-						}
+						require.NoError(t, os.WriteFile(golden, buf.Bytes(), 0644), "failed to update golden file")
+						return
 					}
 
 					want, err := os.ReadFile(golden)
+					require.NoError(t, err, "failed to read golden file")
 					want = bytes.ReplaceAll(want, []byte{'\r', '\n'}, []byte{'\n'})
-					if err != nil {
-						t.Fatalf("failed to read golden file: %s", err)
-					}
-					if !bytes.Equal(buf.Bytes(), want) {
-						t.Errorf("result do not match the golden file:\n--BEGIN--\n%s\n--END--\n", buf.Bytes())
-					}
+					assert.Equal(t, string(want), buf.String())
 				})
 			}
 		})
@@ -212,51 +194,32 @@ func TestExtensions(t *testing.T) {
 			openapi.Definitions = make(map[string]*openapi.Schema)
 			root := httpgen.RunHTTPDSL(t, c.DSL)
 			oFiles, err := openapiv2.Files(root)
-			if err != nil {
-				t.Fatalf("OpenAPI failed with %s", err)
-			}
-			if len(oFiles) == 0 {
-				t.Fatalf("No swagger files")
-			}
+			require.NoError(t, err, "OpenAPI failed")
+			require.NotEmpty(t, oFiles, "No swagger files")
 			for i, o := range oFiles {
 				tname := fmt.Sprintf("file%d", i)
 				s := o.SectionTemplates
 				t.Run(tname, func(t *testing.T) {
-					if len(s) != 1 {
-						t.Fatalf("expected 1 section, got %d", len(s))
-					}
-					if s[0].Source == "" {
-						t.Fatalf("empty section template")
-					}
-					if s[0].Data == nil {
-						t.Fatalf("nil data")
-					}
+					require.Len(t, s, 1, "expected 1 section, got %d", len(s))
+					require.NotEmpty(t, s[0].Source, "empty section template")
+					require.NotNil(t, s[0].Data, "nil data")
 					var buf bytes.Buffer
 					tmpl := template.Must(template.New("openapi").Funcs(s[0].FuncMap).Parse(s[0].Source))
-					if err := tmpl.Execute(&buf, s[0].Data); err != nil {
-						t.Fatalf("failed to render template: %s", err)
-					}
+					require.NoError(t, tmpl.Execute(&buf, s[0].Data), "failed to render template")
 					if filepath.Ext(o.Path) == ".json" {
-						if err := validateSwagger(buf.Bytes()); err != nil {
-							t.Fatalf("invalid swagger: %s", err)
-						}
+						require.NoError(t, validateSwagger(buf.Bytes()), "invalid swagger")
 					}
 
 					golden := filepath.Join(goldenPath, fmt.Sprintf("%s_%s.golden", c.Name, tname))
 					if *update {
-						if err := os.WriteFile(golden, buf.Bytes(), 0644); err != nil {
-							t.Fatalf("failed to update golden file: %s", err)
-						}
+						require.NoError(t, os.WriteFile(golden, buf.Bytes(), 0644), "failed to update golden file")
+						return
 					}
 
 					want, err := os.ReadFile(golden)
 					want = bytes.ReplaceAll(want, []byte{'\r', '\n'}, []byte{'\n'})
-					if err != nil {
-						t.Fatalf("failed to read golden file: %s", err)
-					}
-					if !bytes.Equal(buf.Bytes(), want) {
-						t.Errorf("result do not match the golden file:\n--BEGIN--\n%s\n--END--\n", buf.Bytes())
-					}
+					require.NoError(t, err, "failed to read golden file")
+					assert.Equal(t, string(want), buf.String())
 				})
 			}
 		})
diff --git a/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file0.golden b/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file0.golden
index 18132c67..14d126b7 100644
--- a/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1","x-test-api":"API"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"operationId":"testService#testEndpoint","parameters":[{"in":"body","name":"TestEndpointRequestBody","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody"}}},"schemes":["https"],"summary":"testEndpoint testService","tags":["testService"],"x-test-operation":"Operation"},"x-test-foo":"bar"}},"definitions":{"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Payload"}},"example":{"string":""}},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Result"}},"example":{"string":""}}},"tags":[{"description":"Description of Backend","externalDocs":{"description":"See more docs here","url":"http://example.com"},"name":"Backend","x-data":{"foo":"bar"}}]}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1","x-test-api":"API"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"operationId":"testService#testEndpoint","parameters":[{"in":"body","name":"TestEndpointRequestBody","required":true,"schema":{"$ref":"#/definitions/Payload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/Result"}}},"schemes":["https"],"summary":"testEndpoint testService","tags":["testService"],"x-test-operation":"Operation"},"x-test-foo":"bar"}},"definitions":{"Payload":{"title":"Payload","type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Payload"}},"example":{"string":""}},"Result":{"title":"Result","type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Result"}},"example":{"string":""}}},"tags":[{"description":"Description of Backend","externalDocs":{"description":"See more docs here","url":"http://example.com"},"name":"Backend","x-data":{"foo":"bar"}}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file1.golden b/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file1.golden
index d0eb1854..7c85ad49 100644
--- a/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestExtensions/endpoint_file1.golden
@@ -21,12 +21,12 @@ paths:
                   name: TestEndpointRequestBody
                   required: true
                   schema:
-                    $ref: '#/definitions/TestServiceTestEndpointRequestBody'
+                    $ref: '#/definitions/Payload'
             responses:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointResponseBody'
+                        $ref: '#/definitions/Result'
             schemes:
                 - https
             summary: testEndpoint testService
@@ -35,8 +35,8 @@ paths:
             x-test-operation: Operation
         x-test-foo: bar
 definitions:
-    TestServiceTestEndpointRequestBody:
-        title: TestServiceTestEndpointRequestBody
+    Payload:
+        title: Payload
         type: object
         properties:
             string:
@@ -45,8 +45,8 @@ definitions:
                 x-test-schema: Payload
         example:
             string: ""
-    TestServiceTestEndpointResponseBody:
-        title: TestServiceTestEndpointResponseBody
+    Result:
+        title: Result
         type: object
         properties:
             string:
diff --git a/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file0.golden
index 8ad6be14..9da17a81 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody"}}},"schemes":["https"]},"post":{"tags":["anotherTestService"],"summary":"testEndpoint anotherTestService","operationId":"anotherTestService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/AnotherTestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/AnotherTestServiceTestEndpointResponseBody"}}},"schemes":["https"]}}},"definitions":{"AnotherTestServiceTestEndpointRequestBody":{"title":"AnotherTestServiceTestEndpointRequestBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"AnotherTestServiceTestEndpointResponseBody":{"title":"AnotherTestServiceTestEndpointResponseBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/Payload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/Result"}}},"schemes":["https"]},"post":{"tags":["anotherTestService"],"summary":"testEndpoint anotherTestService","operationId":"anotherTestService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/Payload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/Result"}}},"schemes":["https"]}}},"definitions":{"Payload":{"title":"Payload","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"Result":{"title":"Result","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file1.golden
index 73788918..4cb4faef 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/multiple-services_file1.golden
@@ -23,12 +23,12 @@ paths:
                   in: body
                   required: true
                   schema:
-                    $ref: '#/definitions/TestServiceTestEndpointRequestBody'
+                    $ref: '#/definitions/Payload'
             responses:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointResponseBody'
+                        $ref: '#/definitions/Result'
             schemes:
                 - https
         post:
@@ -41,17 +41,17 @@ paths:
                   in: body
                   required: true
                   schema:
-                    $ref: '#/definitions/AnotherTestServiceTestEndpointRequestBody'
+                    $ref: '#/definitions/Payload'
             responses:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/AnotherTestServiceTestEndpointResponseBody'
+                        $ref: '#/definitions/Result'
             schemes:
                 - https
 definitions:
-    AnotherTestServiceTestEndpointRequestBody:
-        title: AnotherTestServiceTestEndpointRequestBody
+    Payload:
+        title: Payload
         type: object
         properties:
             string:
@@ -59,26 +59,8 @@ definitions:
                 example: ""
         example:
             string: ""
-    AnotherTestServiceTestEndpointResponseBody:
-        title: AnotherTestServiceTestEndpointResponseBody
-        type: object
-        properties:
-            string:
-                type: string
-                example: ""
-        example:
-            string: ""
-    TestServiceTestEndpointRequestBody:
-        title: TestServiceTestEndpointRequestBody
-        type: object
-        properties:
-            string:
-                type: string
-                example: ""
-        example:
-            string: ""
-    TestServiceTestEndpointResponseBody:
-        title: TestServiceTestEndpointResponseBody
+    Result:
+        title: Result
         type: object
         properties:
             string:
diff --git a/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file0.golden
index 7c7f02ea..bc2d0300 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpointDefault testService","operationId":"testService#testEndpointDefault","produces":["application/custom+json"],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointDefaultResponseBody"}}},"schemes":["http"]}},"/tiny":{"get":{"tags":["testService"],"summary":"testEndpointTiny testService","operationId":"testService#testEndpointTiny","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointTinyResponseBodyTiny"}}},"schemes":["http"]}}},"definitions":{"TestServiceTestEndpointDefaultResponseBody":{"title":"Mediatype identifier: application/json; view=default","type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"description":"TestEndpointDefaultResponseBody result type (default view)","example":{"int":1,"string":""}},"TestServiceTestEndpointTinyResponseBodyTiny":{"title":"Mediatype identifier: application/json; view=tiny","type":"object","properties":{"string":{"type":"string","example":""}},"description":"TestEndpointTinyResponseBody result type (tiny view) (default view)","example":{"string":""}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpointDefault testService","operationId":"testService#testEndpointDefault","produces":["application/custom+json"],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/JSON"}}},"schemes":["http"]}},"/tiny":{"get":{"tags":["testService"],"summary":"testEndpointTiny testService","operationId":"testService#testEndpointTiny","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointTinyResponseBodyTiny"}}},"schemes":["http"]}}},"definitions":{"JSON":{"title":"Mediatype identifier: application/json; view=default","type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"description":"TestEndpointDefaultResponseBody result type (default view)","example":{"int":1,"string":""}},"TestServiceTestEndpointTinyResponseBodyTiny":{"title":"Mediatype identifier: application/json; view=tiny","type":"object","properties":{"string":{"type":"string","example":""}},"description":"TestEndpointTinyResponseBody result type (tiny view) (default view)","example":{"string":""}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file1.golden
index 11c11b7c..4e5ac7ee 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/multiple-views_file1.golden
@@ -24,7 +24,7 @@ paths:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointDefaultResponseBody'
+                        $ref: '#/definitions/JSON'
             schemes:
                 - http
     /tiny:
@@ -41,7 +41,7 @@ paths:
             schemes:
                 - http
 definitions:
-    TestServiceTestEndpointDefaultResponseBody:
+    JSON:
         title: 'Mediatype identifier: application/json; view=default'
         type: object
         properties:
diff --git a/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file0.golden
index 735354eb..1414a501 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody","required":["required_string"]}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody","required":["required_int"]}}},"schemes":["https"]}}},"definitions":{"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"required_string":{"type":"string","example":""},"string":{"type":"string","example":""}},"example":{"required_string":"","string":""},"required":["required_string"]},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"int":{"type":"integer","example":0,"format":"int64"},"required_int":{"type":"integer","example":0,"format":"int64"}},"example":{"int":0,"required_int":0},"required":["required_int"]}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/Payload","required":["required_string"]}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/Result","required":["required_int"]}}},"schemes":["https"]}}},"definitions":{"Payload":{"title":"Payload","type":"object","properties":{"required_string":{"type":"string","example":""},"string":{"type":"string","example":""}},"example":{"required_string":"","string":""},"required":["required_string"]},"Result":{"title":"Result","type":"object","properties":{"int":{"type":"integer","example":0,"format":"int64"},"required_int":{"type":"integer","example":0,"format":"int64"}},"example":{"int":0,"required_int":0},"required":["required_int"]}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file1.golden
index ac7d0e28..7a4441f5 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/not-generate-attribute_file1.golden
@@ -23,21 +23,21 @@ paths:
                   in: body
                   required: true
                   schema:
-                    $ref: '#/definitions/TestServiceTestEndpointRequestBody'
+                    $ref: '#/definitions/Payload'
                     required:
                         - required_string
             responses:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointResponseBody'
+                        $ref: '#/definitions/Result'
                         required:
                             - required_int
             schemes:
                 - https
 definitions:
-    TestServiceTestEndpointRequestBody:
-        title: TestServiceTestEndpointRequestBody
+    Payload:
+        title: Payload
         type: object
         properties:
             required_string:
@@ -51,8 +51,8 @@ definitions:
             string: ""
         required:
             - required_string
-    TestServiceTestEndpointResponseBody:
-        title: TestServiceTestEndpointResponseBody
+    Result:
+        title: Result
         type: object
         properties:
             int:
diff --git a/http/codegen/openapi/v2/testdata/TestSections/typename_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/typename_file0.golden
index e2df081e..a56ab831 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/typename_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/typename_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/bar":{"post":{"tags":["testService"],"summary":"bar testService","operationId":"testService#bar","parameters":[{"name":"BarRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/BarPayload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/BarResult"}}},"schemes":["https"]}},"/baz":{"post":{"tags":["testService"],"summary":"baz testService","operationId":"testService#baz","parameters":[{"name":"BazRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/BazPayload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/BazResult"}}},"schemes":["https"]}},"/foo":{"post":{"tags":["testService"],"summary":"foo testService","operationId":"testService#foo","parameters":[{"name":"FooRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/FooPayload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/FooResult"}}},"schemes":["https"]}}},"definitions":{"BarPayload":{"title":"BarPayload","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BarResult":{"title":"Mediatype identifier: application/vnd.goa.example.bar; view=default","type":"object","properties":{"value":{"type":"string","example":""}},"description":"BarResponseBody result type (default view)","example":{"value":""}},"BazPayload":{"title":"BazPayload","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazResult":{"title":"BazResult","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"FooPayload":{"title":"FooPayload","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"FooResult":{"title":"Mediatype identifier: application/vnd.goa.example.bar; view=default","type":"object","properties":{"value":{"type":"string","example":""}},"description":"FooResponseBody result type (default view)","example":{"value":""}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/bar":{"post":{"tags":["testService"],"summary":"bar testService","operationId":"testService#bar","parameters":[{"name":"BarRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/BarPayload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/GoaExampleBar"}}},"schemes":["https"]}},"/baz":{"post":{"tags":["testService"],"summary":"baz testService","operationId":"testService#baz","parameters":[{"name":"BazRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/BazPayload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/BazResult"}}},"schemes":["https"]}},"/foo":{"post":{"tags":["testService"],"summary":"foo testService","operationId":"testService#foo","parameters":[{"name":"FooRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/Foo"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/FooResult"}}},"schemes":["https"]}}},"definitions":{"BarPayload":{"title":"BarPayload","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazPayload":{"title":"BazPayload","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazResult":{"title":"BazResult","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"Foo":{"title":"Foo","type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"FooResult":{"title":"Mediatype identifier: application/vnd.goa.example.bar; view=default","type":"object","properties":{"value":{"type":"string","example":""}},"description":"FooResponseBody result type (default view)","example":{"value":""}},"GoaExampleBar":{"title":"Mediatype identifier: application/vnd.goa.example.bar; view=default","type":"object","properties":{"value":{"type":"string","example":""}},"description":"BarResponseBody result type (default view)","example":{"value":""}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/typename_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/typename_file1.golden
index 0c8cf242..61890672 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/typename_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/typename_file1.golden
@@ -28,7 +28,7 @@ paths:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/BarResult'
+                        $ref: '#/definitions/GoaExampleBar'
             schemes:
                 - https
     /baz:
@@ -61,7 +61,7 @@ paths:
                   in: body
                   required: true
                   schema:
-                    $ref: '#/definitions/FooPayload'
+                    $ref: '#/definitions/Foo'
             responses:
                 "200":
                     description: OK response.
@@ -79,18 +79,17 @@ definitions:
                 example: ""
         example:
             value: ""
-    BarResult:
-        title: 'Mediatype identifier: application/vnd.goa.example.bar; view=default'
+    BazPayload:
+        title: BazPayload
         type: object
         properties:
             value:
                 type: string
                 example: ""
-        description: BarResponseBody result type (default view)
         example:
             value: ""
-    BazPayload:
-        title: BazPayload
+    BazResult:
+        title: BazResult
         type: object
         properties:
             value:
@@ -98,8 +97,8 @@ definitions:
                 example: ""
         example:
             value: ""
-    BazResult:
-        title: BazResult
+    Foo:
+        title: Foo
         type: object
         properties:
             value:
@@ -107,22 +106,23 @@ definitions:
                 example: ""
         example:
             value: ""
-    FooPayload:
-        title: FooPayload
+    FooResult:
+        title: 'Mediatype identifier: application/vnd.goa.example.bar; view=default'
         type: object
         properties:
             value:
                 type: string
                 example: ""
+        description: FooResponseBody result type (default view)
         example:
             value: ""
-    FooResult:
+    GoaExampleBar:
         title: 'Mediatype identifier: application/vnd.goa.example.bar; view=default'
         type: object
         properties:
             value:
                 type: string
                 example: ""
-        description: FooResponseBody result type (default view)
+        description: BarResponseBody result type (default view)
         example:
             value: ""
diff --git a/http/codegen/openapi/v2/testdata/TestSections/valid_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/valid_file0.golden
index a6e33862..a75972bd 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/valid_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/valid_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody"}}},"schemes":["https"]}}},"definitions":{"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/Payload"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/Result"}}},"schemes":["https"]}}},"definitions":{"Payload":{"title":"Payload","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"Result":{"title":"Result","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/valid_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/valid_file1.golden
index b17bdb82..3302ff90 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/valid_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/valid_file1.golden
@@ -23,17 +23,17 @@ paths:
                   in: body
                   required: true
                   schema:
-                    $ref: '#/definitions/TestServiceTestEndpointRequestBody'
+                    $ref: '#/definitions/Payload'
             responses:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointResponseBody'
+                        $ref: '#/definitions/Result'
             schemes:
                 - https
 definitions:
-    TestServiceTestEndpointRequestBody:
-        title: TestServiceTestEndpointRequestBody
+    Payload:
+        title: Payload
         type: object
         properties:
             string:
@@ -41,8 +41,8 @@ definitions:
                 example: ""
         example:
             string: ""
-    TestServiceTestEndpointResponseBody:
-        title: TestServiceTestEndpointResponseBody
+    Result:
+        title: Result
         type: object
         properties:
             string:
diff --git a/http/codegen/openapi/v2/testdata/TestSections/with-map_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/with-map_file0.golden
index 76e9627d..13a42ca2 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/with-map_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/with-map_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"Test EndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody"}}},"schemes":["http"]}}},"definitions":{"FooBarResponseBody":{"title":"Mediatype identifier: application/vnd.goa.foobar; view=default","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/barResponseBody"},"example":[{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"description":"Foo BarResponseBody result type (default view)","example":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"int_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}},"type_map":{"type":"object","example":{"":{"string":""}},"additionalProperties":{"$ref":"#/definitions/barRequestBody"}},"uint_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"int_map":{"":1},"type_map":{"":{"string":""}},"uint_map":{"":1}}},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"resulttype_map":{"type":"object","example":{"":{"bar":[{"string":""},{"string":""}],"foo":""}},"additionalProperties":{"$ref":"#/definitions/FooBarResponseBody"}},"uint32_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int32"}},"uint64_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"resulttype_map":{"":{"bar":[{"string":""},{"string":""}],"foo":""}},"uint32_map":{"":1},"uint64_map":{"":1}}},"barRequestBody":{"title":"barRequestBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"barResponseBody":{"title":"barResponseBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"Test EndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody"}}},"schemes":["http"]}}},"definitions":{"Bar":{"title":"Bar","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"GoaFoobar":{"title":"Mediatype identifier: application/vnd.goa.foobar; view=default","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/Bar"},"example":[{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"description":"Foo BarResponseBody result type (default view)","example":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"int_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}},"type_map":{"type":"object","example":{"":{"string":""}},"additionalProperties":{"$ref":"#/definitions/Bar"}},"uint_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"int_map":{"":1},"type_map":{"":{"string":""}},"uint_map":{"":1}}},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"resulttype_map":{"type":"object","example":{"":{"bar":[{"string":""},{"string":""}],"foo":""}},"additionalProperties":{"$ref":"#/definitions/GoaFoobar"}},"uint32_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int32"}},"uint64_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"resulttype_map":{"":{"bar":[{"string":""},{"string":""}],"foo":""}},"uint32_map":{"":1},"uint64_map":{"":1}}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/with-map_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/with-map_file1.golden
index 18313f4e..6b9e4d2d 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/with-map_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/with-map_file1.golden
@@ -32,14 +32,23 @@ paths:
             schemes:
                 - http
 definitions:
-    FooBarResponseBody:
+    Bar:
+        title: Bar
+        type: object
+        properties:
+            string:
+                type: string
+                example: ""
+        example:
+            string: ""
+    GoaFoobar:
         title: 'Mediatype identifier: application/vnd.goa.foobar; view=default'
         type: object
         properties:
             bar:
                 type: array
                 items:
-                    $ref: '#/definitions/barResponseBody'
+                    $ref: '#/definitions/Bar'
                 example:
                     - string: ""
                     - string: ""
@@ -72,7 +81,7 @@ definitions:
                     "":
                         string: ""
                 additionalProperties:
-                    $ref: '#/definitions/barRequestBody'
+                    $ref: '#/definitions/Bar'
             uint_map:
                 type: object
                 example:
@@ -102,7 +111,7 @@ definitions:
                             - string: ""
                         foo: ""
                 additionalProperties:
-                    $ref: '#/definitions/FooBarResponseBody'
+                    $ref: '#/definitions/GoaFoobar'
             uint32_map:
                 type: object
                 example:
@@ -130,21 +139,3 @@ definitions:
                 "": 1
             uint64_map:
                 "": 1
-    barRequestBody:
-        title: barRequestBody
-        type: object
-        properties:
-            string:
-                type: string
-                example: ""
-        example:
-            string: ""
-    barResponseBody:
-        title: barResponseBody
-        type: object
-        properties:
-            string:
-                type: string
-                example: ""
-        example:
-            string: ""
diff --git a/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file0.golden b/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file0.golden
index e33188de..a987ef7a 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"Test EndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointOKResponseBody"}},"404":{"description":"Not Found response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointNotFoundResponseBody"}}},"schemes":["http"]}}},"definitions":{"TestServiceTestEndpointNotFoundResponseBody":{"title":"Mediatype identifier: application/vnd.goa.foobar; view=default","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/barResponseBody"},"example":[{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"description":"Test EndpointNot FoundResponseBody result type (default view)","example":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"TestServiceTestEndpointOKResponseBody":{"title":"Mediatype identifier: application/vnd.goa.foobar; view=default","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/barResponseBody"},"example":[{"string":""},{"string":""},{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"description":"Test EndpointOKResponseBody result type (default view)","example":{"bar":[{"string":""},{"string":""}],"foo":""}},"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"barResponseBody":{"title":"barResponseBody","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"Test EndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/Bar"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/GoaFoobar"}},"404":{"description":"Not Found response.","schema":{"$ref":"#/definitions/GoaFoobar"}}},"schemes":["http"]}}},"definitions":{"Bar":{"title":"Bar","type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"GoaFoobar":{"title":"Mediatype identifier: application/vnd.goa.foobar; view=default","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/Bar"},"example":[{"string":""},{"string":""},{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"description":"Test EndpointOKResponseBody result type (default view)","example":{"bar":[{"string":""},{"string":""}],"foo":""}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file1.golden b/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file1.golden
index 69d90c79..fa4eb782 100644
--- a/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestSections/with-spaces_file1.golden
@@ -23,49 +23,36 @@ paths:
                   in: body
                   required: true
                   schema:
-                    $ref: '#/definitions/TestServiceTestEndpointRequestBody'
+                    $ref: '#/definitions/Bar'
             responses:
                 "200":
                     description: OK response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointOKResponseBody'
+                        $ref: '#/definitions/GoaFoobar'
                 "404":
                     description: Not Found response.
                     schema:
-                        $ref: '#/definitions/TestServiceTestEndpointNotFoundResponseBody'
+                        $ref: '#/definitions/GoaFoobar'
             schemes:
                 - http
 definitions:
-    TestServiceTestEndpointNotFoundResponseBody:
-        title: 'Mediatype identifier: application/vnd.goa.foobar; view=default'
+    Bar:
+        title: Bar
         type: object
         properties:
-            bar:
-                type: array
-                items:
-                    $ref: '#/definitions/barResponseBody'
-                example:
-                    - string: ""
-                    - string: ""
-            foo:
+            string:
                 type: string
                 example: ""
-        description: Test EndpointNot FoundResponseBody result type (default view)
         example:
-            bar:
-                - string: ""
-                - string: ""
-                - string: ""
-                - string: ""
-            foo: ""
-    TestServiceTestEndpointOKResponseBody:
+            string: ""
+    GoaFoobar:
         title: 'Mediatype identifier: application/vnd.goa.foobar; view=default'
         type: object
         properties:
             bar:
                 type: array
                 items:
-                    $ref: '#/definitions/barResponseBody'
+                    $ref: '#/definitions/Bar'
                 example:
                     - string: ""
                     - string: ""
@@ -80,21 +67,3 @@ definitions:
                 - string: ""
                 - string: ""
             foo: ""
-    TestServiceTestEndpointRequestBody:
-        title: TestServiceTestEndpointRequestBody
-        type: object
-        properties:
-            string:
-                type: string
-                example: ""
-        example:
-            string: ""
-    barResponseBody:
-        title: barResponseBody
-        type: object
-        properties:
-            string:
-                type: string
-                example: ""
-        example:
-            string: ""
diff --git a/http/codegen/openapi/v2/testdata/TestValidations/array_file0.golden b/http/codegen/openapi/v2/testdata/TestValidations/array_file0.golden
index 3f84b254..6b024d8d 100644
--- a/http/codegen/openapi/v2/testdata/TestValidations/array_file0.golden
+++ b/http/codegen/openapi/v2/testdata/TestValidations/array_file0.golden
@@ -1,1 +1,1 @@
-{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"array","in":"body","required":true,"schema":{"type":"array","items":{"$ref":"#/definitions/foobarRequestBody"}}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","minLength":0,"maxLength":42}}},"schemes":["https"]}}},"definitions":{"barRequestBody":{"title":"barRequestBody","type":"object","properties":{"string":{"type":"string","example":"","minLength":0,"maxLength":42}},"example":{"string":""}},"foobarRequestBody":{"title":"foobarRequestBody","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/barRequestBody"},"example":[{"string":""},{"string":""}],"minItems":0,"maxItems":42},"foo":{"type":"array","items":{"type":"string","example":"Beatae non id consequatur."},"example":[],"minItems":0,"maxItems":42}},"example":{"bar":[{"string":""},{"string":""}],"foo":["Repudiandae sit.","Asperiores fuga qui rem qui earum eos."]}}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"goa.design","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"array","in":"body","required":true,"schema":{"type":"array","items":{"$ref":"#/definitions/Foobar"}}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","minLength":0,"maxLength":42}}},"schemes":["https"]}}},"definitions":{"Bar":{"title":"Bar","type":"object","properties":{"string":{"type":"string","example":"","minLength":0,"maxLength":42}},"example":{"string":""}},"Foobar":{"title":"Foobar","type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/definitions/Bar"},"example":[{"string":""},{"string":""}],"minItems":0,"maxItems":42},"foo":{"type":"array","items":{"type":"string","example":"Beatae non id consequatur."},"example":[],"minItems":0,"maxItems":42}},"example":{"bar":[{"string":""},{"string":""}],"foo":["Repudiandae sit.","Asperiores fuga qui rem qui earum eos."]}}}}
\ No newline at end of file
diff --git a/http/codegen/openapi/v2/testdata/TestValidations/array_file1.golden b/http/codegen/openapi/v2/testdata/TestValidations/array_file1.golden
index 4ba9abf9..b1f591f0 100644
--- a/http/codegen/openapi/v2/testdata/TestValidations/array_file1.golden
+++ b/http/codegen/openapi/v2/testdata/TestValidations/array_file1.golden
@@ -25,7 +25,7 @@ paths:
                   schema:
                     type: array
                     items:
-                        $ref: '#/definitions/foobarRequestBody'
+                        $ref: '#/definitions/Foobar'
             responses:
                 "200":
                     description: OK response.
@@ -36,8 +36,8 @@ paths:
             schemes:
                 - https
 definitions:
-    barRequestBody:
-        title: barRequestBody
+    Bar:
+        title: Bar
         type: object
         properties:
             string:
@@ -47,14 +47,14 @@ definitions:
                 maxLength: 42
         example:
             string: ""
-    foobarRequestBody:
-        title: foobarRequestBody
+    Foobar:
+        title: Foobar
         type: object
         properties:
             bar:
                 type: array
                 items:
-                    $ref: '#/definitions/barRequestBody'
+                    $ref: '#/definitions/Bar'
                 example:
                     - string: ""
                     - string: ""
diff --git a/http/codegen/openapi/v3/testdata/golden/endpoint_file0.golden b/http/codegen/openapi/v3/testdata/golden/endpoint_file0.golden
index 1f734b51..eedc1ec0 100644
--- a/http/codegen/openapi/v3/testdata/golden/endpoint_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/endpoint_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1","x-test-api":"API"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"post":{"operationId":"testService#testEndpoint","requestBody":{"content":{"application/json":{"example":{"string":""},"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"}}},"required":true},"responses":{"200":{"content":{"application/json":{"example":{"string":""},"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"}}},"description":"OK response."}},"summary":"testEndpoint testService","tags":["testService"],"x-test-operation":"Operation"},"x-test-foo":"bar"}},"components":{"schemas":{"TestEndpointRequestBody":{"type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Payload"}},"example":{"string":""}}}},"tags":[{"description":"Description of Backend","externalDocs":{"description":"See more docs here","url":"http://example.com"},"name":"Backend","x-data":{"foo":"bar"}}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1","x-test-api":"API"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"post":{"operationId":"testService#testEndpoint","requestBody":{"content":{"application/json":{"example":{"string":""},"schema":{"$ref":"#/components/schemas/Payload"}}},"required":true},"responses":{"200":{"content":{"application/json":{"example":{"string":""},"schema":{"$ref":"#/components/schemas/Result"}}},"description":"OK response."}},"summary":"testEndpoint testService","tags":["testService"],"x-test-operation":"Operation"},"x-test-foo":"bar"}},"components":{"schemas":{"Payload":{"type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Payload"}},"example":{"string":""}},"Result":{"type":"object","properties":{"string":{"example":"","type":"string","x-test-schema":"Result"}},"example":{"string":""}}}},"tags":[{"description":"Description of Backend","externalDocs":{"description":"See more docs here","url":"http://example.com"},"name":"Backend","x-data":{"foo":"bar"}}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/endpoint_file1.golden b/http/codegen/openapi/v3/testdata/golden/endpoint_file1.golden
index eb1991da..0931f612 100644
--- a/http/codegen/openapi/v3/testdata/golden/endpoint_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/endpoint_file1.golden
@@ -15,7 +15,7 @@ paths:
                         example:
                             string: ""
                         schema:
-                            $ref: '#/components/schemas/TestEndpointRequestBody'
+                            $ref: '#/components/schemas/Payload'
                 required: true
             responses:
                 "200":
@@ -24,7 +24,7 @@ paths:
                             example:
                                 string: ""
                             schema:
-                                $ref: '#/components/schemas/TestEndpointRequestBody'
+                                $ref: '#/components/schemas/Result'
                     description: OK response.
             summary: testEndpoint testService
             tags:
@@ -33,7 +33,7 @@ paths:
         x-test-foo: bar
 components:
     schemas:
-        TestEndpointRequestBody:
+        Payload:
             type: object
             properties:
                 string:
@@ -42,6 +42,15 @@ components:
                     x-test-schema: Payload
             example:
                 string: ""
+        Result:
+            type: object
+            properties:
+                string:
+                    example: ""
+                    type: string
+                    x-test-schema: Result
+            example:
+                string: ""
 tags:
     - description: Description of Backend
       externalDocs:
diff --git a/http/codegen/openapi/v3/testdata/golden/error-examples_file0.golden b/http/codegen/openapi/v3/testdata/golden/error-examples_file0.golden
index b5d0402a..fa076183 100644
--- a/http/codegen/openapi/v3/testdata/golden/error-examples_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/error-examples_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"get":{"tags":["Errors"],"summary":"Error Errors","operationId":"Errors#Error","responses":{"204":{"description":"No Content response."},"400":{"description":"bad_request: Bad Request response.","content":{"application/vnd.goa.error":{"schema":{"$ref":"#/components/schemas/Error"},"example":{"fault":false,"id":"foo","message":"request is invalid","name":"bad_request","temporary":false,"timeout":false}}}},"404":{"description":"not_found: Not Found response.","content":{"application/vnd.goa.error":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"custom: Conflict response.","content":{"application/vnd.goa.custom-error":{"schema":{"$ref":"#/components/schemas/CustomError"},"example":{"message":"error message","name":"custom"}}}}}}}},"components":{"schemas":{"CustomError":{"type":"object","properties":{"message":{"type":"string","example":"error message"},"name":{"type":"string","example":"custom"}},"example":{"message":"error message","name":"custom"},"required":["name","message"]},"Error":{"type":"object","properties":{"fault":{"type":"boolean","description":"Is the error a server-side fault?","example":true},"id":{"type":"string","description":"ID is a unique identifier for this particular occurrence of the problem.","example":"123abc"},"message":{"type":"string","description":"Message is a human-readable explanation specific to this occurrence of the problem.","example":"parameter 'p' must be an integer"},"name":{"type":"string","description":"Name is the name of this class of errors.","example":"bad_request"},"temporary":{"type":"boolean","description":"Is the error temporary?","example":true},"timeout":{"type":"boolean","description":"Is the error a timeout?","example":false}},"example":{"fault":true,"id":"123abc","message":"parameter 'p' must be an integer","name":"bad_request","temporary":true,"timeout":true},"required":["name","id","message","temporary","timeout","fault"]}}},"tags":[{"name":"Errors"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"get":{"tags":["Errors"],"summary":"Error Errors","operationId":"Errors#Error","responses":{"204":{"description":"No Content response."},"400":{"description":"bad_request: Bad Request response.","content":{"application/vnd.goa.error":{"schema":{"$ref":"#/components/schemas/Error"},"example":{"fault":false,"id":"foo","message":"request is invalid","name":"bad_request","temporary":false,"timeout":false}}}},"404":{"description":"not_found: Not Found response.","content":{"application/vnd.goa.error":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"custom: Conflict response.","content":{"application/vnd.goa.custom-error":{"schema":{"$ref":"#/components/schemas/GoaCustomError"},"example":{"message":"error message","name":"custom"}}}}}}}},"components":{"schemas":{"Error":{"type":"object","properties":{"fault":{"type":"boolean","description":"Is the error a server-side fault?","example":true},"id":{"type":"string","description":"ID is a unique identifier for this particular occurrence of the problem.","example":"123abc"},"message":{"type":"string","description":"Message is a human-readable explanation specific to this occurrence of the problem.","example":"parameter 'p' must be an integer"},"name":{"type":"string","description":"Name is the name of this class of errors.","example":"bad_request"},"temporary":{"type":"boolean","description":"Is the error temporary?","example":true},"timeout":{"type":"boolean","description":"Is the error a timeout?","example":false}},"example":{"fault":true,"id":"123abc","message":"parameter 'p' must be an integer","name":"bad_request","temporary":true,"timeout":true},"required":["name","id","message","temporary","timeout","fault"]},"GoaCustomError":{"type":"object","properties":{"message":{"type":"string","example":"error message"},"name":{"type":"string","example":"custom"}},"example":{"message":"error message","name":"custom"},"required":["name","message"]}}},"tags":[{"name":"Errors"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/error-examples_file1.golden b/http/codegen/openapi/v3/testdata/golden/error-examples_file1.golden
index 51a1cbde..b765774d 100644
--- a/http/codegen/openapi/v3/testdata/golden/error-examples_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/error-examples_file1.golden
@@ -39,27 +39,12 @@ paths:
                     content:
                         application/vnd.goa.custom-error:
                             schema:
-                                $ref: '#/components/schemas/CustomError'
+                                $ref: '#/components/schemas/GoaCustomError'
                             example:
                                 message: error message
                                 name: custom
 components:
     schemas:
-        CustomError:
-            type: object
-            properties:
-                message:
-                    type: string
-                    example: error message
-                name:
-                    type: string
-                    example: custom
-            example:
-                message: error message
-                name: custom
-            required:
-                - name
-                - message
         Error:
             type: object
             properties:
@@ -101,5 +86,20 @@ components:
                 - temporary
                 - timeout
                 - fault
+        GoaCustomError:
+            type: object
+            properties:
+                message:
+                    type: string
+                    example: error message
+                name:
+                    type: string
+                    example: custom
+            example:
+                message: error message
+                name: custom
+            required:
+                - name
+                - message
 tags:
     - name: Errors
diff --git a/http/codegen/openapi/v3/testdata/golden/explicit-view_file0.golden b/http/codegen/openapi/v3/testdata/golden/explicit-view_file0.golden
index afc8b2dc..2dea23fe 100644
--- a/http/codegen/openapi/v3/testdata/golden/explicit-view_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/explicit-view_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpointDefault testService","operationId":"testService#testEndpointDefault","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointDefaultResponseBody"},"example":{"int":1,"string":""}}}}}}},"/tiny":{"get":{"tags":["testService"],"summary":"testEndpointTiny testService","operationId":"testService#testEndpointTiny","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointTinyResponseBodyTiny"},"example":{"string":""}}}}}}}},"components":{"schemas":{"TestEndpointDefaultResponseBody":{"type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"description":"TestEndpointDefaultResponseBody result type (default view)","example":{"int":1,"string":""}},"TestEndpointTinyResponseBodyTiny":{"type":"object","properties":{"string":{"type":"string","example":""}},"description":"TestEndpointTinyResponseBody result type (tiny view)","example":{"string":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpointDefault testService","operationId":"testService#testEndpointDefault","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointDefaultResponseBody"},"example":{"int":1,"string":""}}}}}}},"/tiny":{"get":{"tags":["testService"],"summary":"testEndpointTiny testService","operationId":"testService#testEndpointTiny","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointTinyResponseBodyTiny"},"example":{"string":""}}}}}}}},"components":{"schemas":{"JSON":{"type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"example":{"int":1,"string":""}},"TestEndpointDefaultResponseBody":{"type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"description":"TestEndpointDefaultResponseBody result type (default view)","example":{"int":1,"string":""}},"TestEndpointTinyResponseBodyTiny":{"type":"object","properties":{"string":{"type":"string","example":""}},"description":"TestEndpointTinyResponseBody result type (tiny view)","example":{"string":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/explicit-view_file1.golden b/http/codegen/openapi/v3/testdata/golden/explicit-view_file1.golden
index 9799aa1f..3ab4d313 100644
--- a/http/codegen/openapi/v3/testdata/golden/explicit-view_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/explicit-view_file1.golden
@@ -39,6 +39,19 @@ paths:
                                 string: ""
 components:
     schemas:
+        JSON:
+            type: object
+            properties:
+                int:
+                    type: integer
+                    example: 1
+                    format: int64
+                string:
+                    type: string
+                    example: ""
+            example:
+                int: 1
+                string: ""
         TestEndpointDefaultResponseBody:
             type: object
             properties:
diff --git a/http/codegen/openapi/v3/testdata/golden/multiple-services_file0.golden b/http/codegen/openapi/v3/testdata/golden/multiple-services_file0.golden
index 6cd52e9a..7f387e74 100644
--- a/http/codegen/openapi/v3/testdata/golden/multiple-services_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/multiple-services_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}}}},"post":{"tags":["anotherTestService"],"summary":"testEndpoint anotherTestService","operationId":"anotherTestService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}}}}}},"components":{"schemas":{"TestEndpointRequestBody":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}},"tags":[{"name":"testService"},{"name":"anotherTestService"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payload"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Result"},"example":{"string":""}}}}}},"post":{"tags":["anotherTestService"],"summary":"testEndpoint anotherTestService","operationId":"anotherTestService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payload"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Result"},"example":{"string":""}}}}}}}},"components":{"schemas":{"Payload":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"Result":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}},"tags":[{"name":"testService"},{"name":"anotherTestService"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/multiple-services_file1.golden b/http/codegen/openapi/v3/testdata/golden/multiple-services_file1.golden
index e02b0a85..6957aea4 100644
--- a/http/codegen/openapi/v3/testdata/golden/multiple-services_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/multiple-services_file1.golden
@@ -16,7 +16,7 @@ paths:
                 content:
                     application/json:
                         schema:
-                            $ref: '#/components/schemas/TestEndpointRequestBody'
+                            $ref: '#/components/schemas/Payload'
                         example:
                             string: ""
             responses:
@@ -25,7 +25,7 @@ paths:
                     content:
                         application/json:
                             schema:
-                                $ref: '#/components/schemas/TestEndpointRequestBody'
+                                $ref: '#/components/schemas/Result'
                             example:
                                 string: ""
         post:
@@ -38,7 +38,7 @@ paths:
                 content:
                     application/json:
                         schema:
-                            $ref: '#/components/schemas/TestEndpointRequestBody'
+                            $ref: '#/components/schemas/Payload'
                         example:
                             string: ""
             responses:
@@ -47,12 +47,20 @@ paths:
                     content:
                         application/json:
                             schema:
-                                $ref: '#/components/schemas/TestEndpointRequestBody'
+                                $ref: '#/components/schemas/Result'
                             example:
                                 string: ""
 components:
     schemas:
-        TestEndpointRequestBody:
+        Payload:
+            type: object
+            properties:
+                string:
+                    type: string
+                    example: ""
+            example:
+                string: ""
+        Result:
             type: object
             properties:
                 string:
diff --git a/http/codegen/openapi/v3/testdata/golden/multiple-views_file0.golden b/http/codegen/openapi/v3/testdata/golden/multiple-views_file0.golden
index a9dc1f71..1d2d6032 100644
--- a/http/codegen/openapi/v3/testdata/golden/multiple-views_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/multiple-views_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpointDefault testService","operationId":"testService#testEndpointDefault","responses":{"200":{"description":"OK response.","content":{"application/custom+json":{"schema":{"$ref":"#/components/schemas/Result"},"example":{"int":1,"string":""}}}}}}},"/tiny":{"get":{"tags":["testService"],"summary":"testEndpointTiny testService","operationId":"testService#testEndpointTiny","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointTinyResponseBodyTiny"},"example":{"string":""}}}}}}}},"components":{"schemas":{"Result":{"type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"example":{"int":1,"string":""}},"TestEndpointTinyResponseBodyTiny":{"type":"object","properties":{"string":{"type":"string","example":""}},"description":"TestEndpointTinyResponseBody result type (tiny view)","example":{"string":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpointDefault testService","operationId":"testService#testEndpointDefault","responses":{"200":{"description":"OK response.","content":{"application/custom+json":{"schema":{"$ref":"#/components/schemas/JSON"},"example":{"int":1,"string":""}}}}}}},"/tiny":{"get":{"tags":["testService"],"summary":"testEndpointTiny testService","operationId":"testService#testEndpointTiny","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointTinyResponseBodyTiny"},"example":{"string":""}}}}}}}},"components":{"schemas":{"JSON":{"type":"object","properties":{"int":{"type":"integer","example":1,"format":"int64"},"string":{"type":"string","example":""}},"example":{"int":1,"string":""}},"TestEndpointTinyResponseBodyTiny":{"type":"object","properties":{"string":{"type":"string","example":""}},"description":"TestEndpointTinyResponseBody result type (tiny view)","example":{"string":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/multiple-views_file1.golden b/http/codegen/openapi/v3/testdata/golden/multiple-views_file1.golden
index a657b177..ea6360e7 100644
--- a/http/codegen/openapi/v3/testdata/golden/multiple-views_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/multiple-views_file1.golden
@@ -18,7 +18,7 @@ paths:
                     content:
                         application/custom+json:
                             schema:
-                                $ref: '#/components/schemas/Result'
+                                $ref: '#/components/schemas/JSON'
                             example:
                                 int: 1
                                 string: ""
@@ -39,7 +39,7 @@ paths:
                                 string: ""
 components:
     schemas:
-        Result:
+        JSON:
             type: object
             properties:
                 int:
diff --git a/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file0.golden b/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file0.golden
index 99bc23b9..950b38fa 100644
--- a/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"required_string":"","string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Result"},"example":{"int":0,"required_int":0}}}}}}}},"components":{"schemas":{"Result":{"type":"object","properties":{"int":{"type":"integer","example":0,"format":"int64"},"required_int":{"type":"integer","example":0,"format":"int64"}},"example":{"int":0,"required_int":0},"required":["required_int"]},"TestEndpointRequestBody":{"type":"object","properties":{"required_string":{"type":"string","example":""},"string":{"type":"string","example":""}},"example":{"required_string":"","string":""},"required":["required_string"]}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payload"},"example":{"required_string":"","string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Result"},"example":{"int":0,"required_int":0}}}}}}}},"components":{"schemas":{"Payload":{"type":"object","properties":{"required_string":{"type":"string","example":""},"string":{"type":"string","example":""}},"example":{"required_string":"","string":""},"required":["required_string"]},"Result":{"type":"object","properties":{"int":{"type":"integer","example":0,"format":"int64"},"required_int":{"type":"integer","example":0,"format":"int64"}},"example":{"int":0,"required_int":0},"required":["required_int"]}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file1.golden b/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file1.golden
index 02f5d2cc..6dfd9831 100644
--- a/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/not-generate-attribute_file1.golden
@@ -16,7 +16,7 @@ paths:
                 content:
                     application/json:
                         schema:
-                            $ref: '#/components/schemas/TestEndpointRequestBody'
+                            $ref: '#/components/schemas/Payload'
                         example:
                             required_string: ""
                             string: ""
@@ -32,6 +32,20 @@ paths:
                                 required_int: 0
 components:
     schemas:
+        Payload:
+            type: object
+            properties:
+                required_string:
+                    type: string
+                    example: ""
+                string:
+                    type: string
+                    example: ""
+            example:
+                required_string: ""
+                string: ""
+            required:
+                - required_string
         Result:
             type: object
             properties:
@@ -48,19 +62,5 @@ components:
                 required_int: 0
             required:
                 - required_int
-        TestEndpointRequestBody:
-            type: object
-            properties:
-                required_string:
-                    type: string
-                    example: ""
-                string:
-                    type: string
-                    example: ""
-            example:
-                required_string: ""
-                string: ""
-            required:
-                - required_string
 tags:
     - name: testService
diff --git a/http/codegen/openapi/v3/testdata/golden/typename_file0.golden b/http/codegen/openapi/v3/testdata/golden/typename_file0.golden
index cf5a10ca..56162ea8 100644
--- a/http/codegen/openapi/v3/testdata/golden/typename_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/typename_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/bar":{"post":{"tags":["testService"],"summary":"bar testService","operationId":"testService#bar","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BarPayload"},"example":{"value":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BarResult"},"example":{"value":""}}}}}}},"/baz":{"post":{"tags":["testService"],"summary":"baz testService","operationId":"testService#baz","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BazPayload"},"example":{"value":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BazResult"},"example":{"value":""}}}}}}},"/foo":{"post":{"tags":["testService"],"summary":"foo testService","operationId":"testService#foo","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FooPayload"},"example":{"value":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FooResult"},"example":{"value":""}}}}}}}},"components":{"schemas":{"BarPayload":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BarResult":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazPayload":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazResult":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"FooPayload":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"FooResult":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/bar":{"post":{"tags":["testService"],"summary":"bar testService","operationId":"testService#bar","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BarPayload"},"example":{"value":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoaExampleBar"},"example":{"value":""}}}}}}},"/baz":{"post":{"tags":["testService"],"summary":"baz testService","operationId":"testService#baz","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BazPayload"},"example":{"value":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BazResult"},"example":{"value":""}}}}}}},"/foo":{"post":{"tags":["testService"],"summary":"foo testService","operationId":"testService#foo","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Foo"},"example":{"value":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FooResult"},"example":{"value":""}}}}}}}},"components":{"schemas":{"BarPayload":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazPayload":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"BazResult":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"Foo":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"FooResult":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}},"GoaExampleBar":{"type":"object","properties":{"value":{"type":"string","example":""}},"example":{"value":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/typename_file1.golden b/http/codegen/openapi/v3/testdata/golden/typename_file1.golden
index 958dd085..238a5121 100644
--- a/http/codegen/openapi/v3/testdata/golden/typename_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/typename_file1.golden
@@ -25,7 +25,7 @@ paths:
                     content:
                         application/json:
                             schema:
-                                $ref: '#/components/schemas/BarResult'
+                                $ref: '#/components/schemas/GoaExampleBar'
                             example:
                                 value: ""
     /baz:
@@ -62,7 +62,7 @@ paths:
                 content:
                     application/json:
                         schema:
-                            $ref: '#/components/schemas/FooPayload'
+                            $ref: '#/components/schemas/Foo'
                         example:
                             value: ""
             responses:
@@ -84,7 +84,7 @@ components:
                     example: ""
             example:
                 value: ""
-        BarResult:
+        BazPayload:
             type: object
             properties:
                 value:
@@ -92,7 +92,7 @@ components:
                     example: ""
             example:
                 value: ""
-        BazPayload:
+        BazResult:
             type: object
             properties:
                 value:
@@ -100,7 +100,7 @@ components:
                     example: ""
             example:
                 value: ""
-        BazResult:
+        Foo:
             type: object
             properties:
                 value:
@@ -108,7 +108,7 @@ components:
                     example: ""
             example:
                 value: ""
-        FooPayload:
+        FooResult:
             type: object
             properties:
                 value:
@@ -116,7 +116,7 @@ components:
                     example: ""
             example:
                 value: ""
-        FooResult:
+        GoaExampleBar:
             type: object
             properties:
                 value:
diff --git a/http/codegen/openapi/v3/testdata/golden/valid_file0.golden b/http/codegen/openapi/v3/testdata/golden/valid_file0.golden
index 29a7f4f0..41201a1b 100644
--- a/http/codegen/openapi/v3/testdata/golden/valid_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/valid_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}}}}}},"components":{"schemas":{"TestEndpointRequestBody":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"https://goa.design"}],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payload"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Result"},"example":{"string":""}}}}}}}},"components":{"schemas":{"Payload":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"Result":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}},"tags":[{"name":"testService"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/valid_file1.golden b/http/codegen/openapi/v3/testdata/golden/valid_file1.golden
index 6ed094f0..fcb03770 100644
--- a/http/codegen/openapi/v3/testdata/golden/valid_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/valid_file1.golden
@@ -16,7 +16,7 @@ paths:
                 content:
                     application/json:
                         schema:
-                            $ref: '#/components/schemas/TestEndpointRequestBody'
+                            $ref: '#/components/schemas/Payload'
                         example:
                             string: ""
             responses:
@@ -25,12 +25,20 @@ paths:
                     content:
                         application/json:
                             schema:
-                                $ref: '#/components/schemas/TestEndpointRequestBody'
+                                $ref: '#/components/schemas/Result'
                             example:
                                 string: ""
 components:
     schemas:
-        TestEndpointRequestBody:
+        Payload:
+            type: object
+            properties:
+                string:
+                    type: string
+                    example: ""
+            example:
+                string: ""
+        Result:
             type: object
             properties:
                 string:
diff --git a/http/codegen/openapi/v3/testdata/golden/with-map_file0.golden b/http/codegen/openapi/v3/testdata/golden/with-map_file0.golden
index ab968e9b..a14e9d9f 100644
--- a/http/codegen/openapi/v3/testdata/golden/with-map_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/with-map_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"int_map":{"":1},"type_map":{"":{"string":""}},"uint_map":{"":1}}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointResponseBody"},"example":{"resulttype_map":{"":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"uint32_map":{"":1},"uint64_map":{"":1}}}}}}}}},"components":{"schemas":{"Bar":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"GoaFoobar":{"type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/components/schemas/Bar"},"example":[{"string":""},{"string":""},{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"example":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"TestEndpointRequestBody":{"type":"object","properties":{"int_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}},"type_map":{"type":"object","example":{"":{"string":""}},"additionalProperties":{"$ref":"#/components/schemas/Bar"}},"uint_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"int_map":{"":1},"type_map":{"":{"string":""}},"uint_map":{"":1}}},"TestEndpointResponseBody":{"type":"object","properties":{"resulttype_map":{"type":"object","example":{"":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"additionalProperties":{"$ref":"#/components/schemas/GoaFoobar"}},"uint32_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int32"}},"uint64_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"resulttype_map":{"":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"uint32_map":{"":1},"uint64_map":{"":1}}}}},"tags":[{"name":"test service"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"int_map":{"":1},"type_map":{"":{"string":""}},"uint_map":{"":1}}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointResponseBody"},"example":{"resulttype_map":{"":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"uint32_map":{"":1},"uint64_map":{"":1}}}}}}}}},"components":{"schemas":{"Bar":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"GoaFoobar":{"type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/components/schemas/Bar"},"example":[{"string":""},{"string":""},{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"example":{"bar":[{"string":""},{"string":""}],"foo":""}},"TestEndpointRequestBody":{"type":"object","properties":{"int_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}},"type_map":{"type":"object","example":{"":{"string":""}},"additionalProperties":{"$ref":"#/components/schemas/Bar"}},"uint_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"int_map":{"":1},"type_map":{"":{"string":""}},"uint_map":{"":1}}},"TestEndpointResponseBody":{"type":"object","properties":{"resulttype_map":{"type":"object","example":{"":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"additionalProperties":{"$ref":"#/components/schemas/GoaFoobar"}},"uint32_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int32"}},"uint64_map":{"type":"object","example":{"":1},"additionalProperties":{"type":"integer","example":1,"format":"int64"}}},"example":{"resulttype_map":{"":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}},"uint32_map":{"":1},"uint64_map":{"":1}}}}},"tags":[{"name":"test service"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/with-map_file1.golden b/http/codegen/openapi/v3/testdata/golden/with-map_file1.golden
index 468936f4..52493c9d 100644
--- a/http/codegen/openapi/v3/testdata/golden/with-map_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/with-map_file1.golden
@@ -75,8 +75,6 @@ components:
                 bar:
                     - string: ""
                     - string: ""
-                    - string: ""
-                    - string: ""
                 foo: ""
         TestEndpointRequestBody:
             type: object
diff --git a/http/codegen/openapi/v3/testdata/golden/with-spaces_file0.golden b/http/codegen/openapi/v3/testdata/golden/with-spaces_file0.golden
index 21bb5ade..171b96de 100644
--- a/http/codegen/openapi/v3/testdata/golden/with-spaces_file0.golden
+++ b/http/codegen/openapi/v3/testdata/golden/with-spaces_file0.golden
@@ -1,1 +1,1 @@
-{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FooBar"},"example":{"bar":[{"string":""},{"string":""}],"foo":""}}}},"404":{"description":"Not Found response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FooBar"},"example":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}}}}}}}},"components":{"schemas":{"FooBar":{"type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":[{"string":""},{"string":""},{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"example":{"bar":[{"string":""},{"string":""}],"foo":""}},"TestEndpointRequestBody":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}}}},"tags":[{"name":"test service"}]}
\ No newline at end of file
+{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Bar"},"example":{"string":""}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoaFoobar"},"example":{"bar":[{"string":""},{"string":""}],"foo":""}}}},"404":{"description":"Not Found response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoaFoobar"},"example":{"bar":[{"string":""},{"string":""},{"string":""},{"string":""}],"foo":""}}}}}}}},"components":{"schemas":{"Bar":{"type":"object","properties":{"string":{"type":"string","example":""}},"example":{"string":""}},"GoaFoobar":{"type":"object","properties":{"bar":{"type":"array","items":{"$ref":"#/components/schemas/Bar"},"example":[{"string":""},{"string":""},{"string":""},{"string":""}]},"foo":{"type":"string","example":""}},"example":{"bar":[{"string":""},{"string":""}],"foo":""}}}},"tags":[{"name":"test service"}]}
\ No newline at end of file
diff --git a/http/codegen/openapi/v3/testdata/golden/with-spaces_file1.golden b/http/codegen/openapi/v3/testdata/golden/with-spaces_file1.golden
index 76c43e25..8feadf09 100644
--- a/http/codegen/openapi/v3/testdata/golden/with-spaces_file1.golden
+++ b/http/codegen/openapi/v3/testdata/golden/with-spaces_file1.golden
@@ -17,7 +17,7 @@ paths:
                 content:
                     application/json:
                         schema:
-                            $ref: '#/components/schemas/TestEndpointRequestBody'
+                            $ref: '#/components/schemas/Bar'
                         example:
                             string: ""
             responses:
@@ -26,7 +26,7 @@ paths:
                     content:
                         application/json:
                             schema:
-                                $ref: '#/components/schemas/FooBar'
+                                $ref: '#/components/schemas/GoaFoobar'
                             example:
                                 bar:
                                     - string: ""
@@ -37,7 +37,7 @@ paths:
                     content:
                         application/json:
                             schema:
-                                $ref: '#/components/schemas/FooBar'
+                                $ref: '#/components/schemas/GoaFoobar'
                             example:
                                 bar:
                                     - string: ""
@@ -47,13 +47,21 @@ paths:
                                 foo: ""
 components:
     schemas:
-        FooBar:
+        Bar:
+            type: object
+            properties:
+                string:
+                    type: string
+                    example: ""
+            example:
+                string: ""
+        GoaFoobar:
             type: object
             properties:
                 bar:
                     type: array
                     items:
-                        $ref: '#/components/schemas/TestEndpointRequestBody'
+                        $ref: '#/components/schemas/Bar'
                     example:
                         - string: ""
                         - string: ""
@@ -67,13 +75,5 @@ components:
                     - string: ""
                     - string: ""
                 foo: ""
-        TestEndpointRequestBody:
-            type: object
-            properties:
-                string:
-                    type: string
-                    example: ""
-            example:
-                string: ""
 tags:
     - name: test service