Repository: oapi-codegen/oapi-codegen (Go)

Issue:
use of AnyOf generates struct type names starting with a number
Trying to compile my schema using this command:
`oapi-codegen -package generated openapi/api.yaml > api.gen.go`
I'm on version `v1.13.0`
openapi: 3.0.0

This error is given:
```
error generating code: error formatting Go code
: generated.go:263:16: '_' must separate successive digits (and 1 more errors)
````

I've tried to create a minimal example where this issue occurs:

This is a simple schema with cats, dogs and rats.
[api.yaml.txt](https://github.com/deepmap/oapi-codegen/files/11807506/api.was.yaml.txt)

This is what's written to stderr:
[api.gen.go.txt](https://github.com/deepmap/oapi-codegen/files/11807527/api.gen.go.txt)

You can see the error at the top and bottom of the go file. 
At line 263 and 320, invalid Go is generated.

This works up until version 1.12.1, but after that, it is broken.





Discussion: @Krulknul The issue seems to be in the client code only. Looks like client is generated by default option in `v1.13.0`. You can try skipping the client code generation by using the command 
`oapi-codegen -package generated -generate types,server,spec api.was.yaml > api.gen.new2.go`

Alternatively, if you want to generate the client as well, you can do a small refactoring in the spec file. That should also work.
[api.was.yaml.txt](https://github.com/deepmap/oapi-codegen/files/11939176/api.was.yaml.txt)

I will try to investigate and fix the root cause as my first contribution to this repo 🙂 





Fix (patch):
diff --git a/pkg/codegen/operations.go b/pkg/codegen/operations.go
index da903810d..3b0f13016 100644
--- a/pkg/codegen/operations.go
+++ b/pkg/codegen/operations.go
@@ -297,7 +297,7 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini
 				contentType := responseRef.Value.Content[contentTypeName]
 				// We can only generate a type if we have a schema:
 				if contentType.Schema != nil {
-					responseSchema, err := GenerateGoSchema(contentType.Schema, []string{responseName})
+					responseSchema, err := GenerateGoSchema(contentType.Schema, []string{o.OperationId, responseName})
 					if err != nil {
 						return nil, fmt.Errorf("Unable to determine Go type for %s.%s: %w", o.OperationId, contentTypeName, err)
 					}
@@ -331,8 +331,9 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini
 							TypeName: typeName,
 							Schema:   responseSchema,
 						},
-						ResponseName:    responseName,
-						ContentTypeName: contentTypeName,
+						ResponseName:              responseName,
+						ContentTypeName:           contentTypeName,
+						AdditionalTypeDefinitions: responseSchema.GetAdditionalTypeDefs(),
 					}
 					if IsGoTypeReference(responseRef.Ref) {
 						refType, err := RefPathToGoType(responseRef.Ref)
diff --git a/pkg/codegen/schema.go b/pkg/codegen/schema.go
index 3d4bdbbdd..c6fc5b6a9 100644
--- a/pkg/codegen/schema.go
+++ b/pkg/codegen/schema.go
@@ -199,6 +199,8 @@ type ResponseTypeDefinition struct {
 
 	// The type name of a response model.
 	ResponseName string
+
+	AdditionalTypeDefinitions []TypeDefinition
 }
 
 func (t *TypeDefinition) IsAlias() bool {
diff --git a/pkg/codegen/templates/client-with-responses.tmpl b/pkg/codegen/templates/client-with-responses.tmpl
index c0b3ca568..908f21476 100644
--- a/pkg/codegen/templates/client-with-responses.tmpl
+++ b/pkg/codegen/templates/client-with-responses.tmpl
@@ -44,14 +44,21 @@ type ClientWithResponsesInterface interface {
 }
 
 {{range .}}{{$opid := .OperationId}}{{$op := .}}
+{{$responseTypeDefinitions := getResponseTypeDefinitions .}}
 type {{genResponseTypeName $opid | ucFirst}} struct {
     Body         []byte
 	HTTPResponse *http.Response
-    {{- range getResponseTypeDefinitions .}}
+    {{- range $responseTypeDefinitions}}
     {{.TypeName}} *{{.Schema.TypeDecl}}
     {{- end}}
 }
 
+{{- range $responseTypeDefinitions}}
+  {{- range .AdditionalTypeDefinitions}}
+    type {{.TypeName}} {{if .IsAlias }}={{end}} {{.Schema.TypeDecl}}
+  {{- end}}
+{{- end}}
+
 // Status returns HTTPResponse.Status
 func (r {{genResponseTypeName $opid | ucFirst}}) Status() string {
     if r.HTTPResponse != nil {