Repository: go-swagger/go-swagger (go)

Issue:
custom tags are not added to instances of objects when specified
## Problem statement

I'm trying to use the `x-go-custom-tag` extension to add a tag to an object in my schema, but when a model is generated that has an instance of that object in it, the instance does not have any custom tags applied. 

When applying the `x-go-custom-tag` as seen in the sample spec below, this is the code generated:
```
...

// ObjWithCustomTag obj with custom tag
//
// swagger:model ObjWithCustomTag
type ObjWithCustomTag struct {

    // custom tag
    CustomTag *ObjWithCustomTagCustomTag `json:"customTag,omitempty"`

}

...
```

### Expected Result
```
...

// ObjWithCustomTag obj with custom tag
//
// swagger:model ObjWithCustomTag
type ObjWithCustomTag struct {

    // custom tag
    CustomTag *ObjWithCustomTagCustomTag `json:"customTag,omitempty" myobjtag:"foo,bar"`

}

...
```

## Swagger specification

```
ObjWithCustomTag:
  type: object
  properties:
    customTag:
      type: object
      x-go-custom-tag: myobjtag:"foo,bar"
      properties: 
        something:
          type: string
```

## Steps to reproduce

`swagger generate model -M ObjWithCustomTag -f spec.yml -t src/generated/`

## Environment
swagger version: 0.25.0
go version: 1.15.6
OS: macOS 11.0.1


Pull request description:
ensure custom tag is applied to object in generated model (#2457)
* object properties now have custom tags appended to generated models
* fixes #2457 

Signed-off-by: Bob Callaway <bcallawa@redhat.com>

Patch:
diff --git a/fixtures/bugs/2457/fixture-2457.yaml b/fixtures/bugs/2457/fixture-2457.yaml
new file mode 100644
index 00000000..46a15fed
--- /dev/null
+++ b/fixtures/bugs/2457/fixture-2457.yaml
@@ -0,0 +1,36 @@
+swagger: '2.0'
+
+info:
+  version: "1.0.0"
+  title: Private to-do list
+  description: |
+    A very simple api description that makes a json only API to submit to do's.
+
+produces:
+  - application/json
+
+consumes:
+  - application/json
+
+paths:
+  /models:
+    get:
+      operationId: modelOp
+      summary: many model variations
+      description: Used to see if a codegen can render all the possible parameter variations for a header param
+      tags:
+        - testcgen
+      responses:
+        default:
+          description: Generic Out
+
+definitions:
+  ObjWithCustomTag:
+    type: object
+    properties:
+      customTag:
+        type: object
+        x-go-custom-tag: myobjtag:"foo,bar"
+        properties:
+          value:
+            type: string
diff --git a/generator/model.go b/generator/model.go
index 2f6acb4a..21d1ffb9 100644
--- a/generator/model.go
+++ b/generator/model.go
@@ -917,8 +917,13 @@ func (sg *schemaGenContext) buildProperties() error {
 		emprop.GenSchema.Extensions = emprop.Schema.Extensions
 
 		// set custom serializer tag
-		if customTag, found := emprop.Schema.Extensions[xGoCustomTag]; found {
-			emprop.GenSchema.CustomTag = customTag.(string)
+		if customTag, found := tpe.Extensions[xGoCustomTag]; found {
+			tagAsStr, ok := customTag.(string)
+			if ok {
+				emprop.GenSchema.CustomTag = tagAsStr
+			} else {
+				log.Printf("warning: expect %s extension to be a string, got: %v. Skipped", xGoCustomTag, customTag)
+			}
 		}
 		sg.GenSchema.Properties = append(sg.GenSchema.Properties, emprop.GenSchema)
 	}
diff --git a/generator/types.go b/generator/types.go
index 2ffa88a3..c3c839c6 100644
--- a/generator/types.go
+++ b/generator/types.go
@@ -1244,6 +1244,13 @@ func (rt *resolvedType) setExtensions(schema *spec.Schema, origType string) {
 	rt.IsEnumCI = hasEnumCI(schema.Extensions)
 	rt.setIsEmptyOmitted(schema, origType)
 	rt.setIsJSONString(schema, origType)
+
+	if customTag, found := schema.Extensions[xGoCustomTag]; found {
+		if rt.Extensions == nil {
+			rt.Extensions = make(spec.Extensions)
+		}
+		rt.Extensions[xGoCustomTag] = customTag
+	}
 }
 
 func (rt *resolvedType) setIsEmptyOmitted(schema *spec.Schema, tpe string) {


Test patch:
diff --git a/generator/model_test.go b/generator/model_test.go
index da9cd09d..cadafcbe 100644
--- a/generator/model_test.go
+++ b/generator/model_test.go
@@ -2485,6 +2485,23 @@ func TestGenModel_Issue1623(t *testing.T) {
 
 }
 
+func TestGenerateModel_Issue2457(t *testing.T) {
+	specDoc, err := loads.Spec("../fixtures/bugs/2457/fixture-2457.yaml")
+	require.NoError(t, err)
+
+	definitions := specDoc.Spec().Definitions
+	k := "ObjWithCustomTag"
+	schema := definitions[k]
+	opts := opts()
+	genModel, err := makeGenDefinition(k, "models", schema, specDoc, opts)
+	require.NoError(t, err)
+
+	buf := bytes.NewBuffer(nil)
+	require.NoError(t, opts.templates.MustGet("model").Execute(buf, genModel))
+
+	assertInCode(t, "myobjtag:\"foo,bar\"", buf.String())
+}
+
 func TestGenModel_KeepSpecPropertiesOrder(t *testing.T) {
 	ymlFile := "../fixtures/codegen/keep-spec-order.yml"
 	opts := opts()