From 80b258c00e69dbaead03ce8115fe45ee4729ee8d Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Sun, 27 Nov 2022 14:41:09 +0000 Subject: [PATCH 1/8] rew! allow content to be empty rew! handle absent content/mediaType --- pkg/codegen/operations.go | 2 +- pkg/codegen/utils.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/codegen/operations.go b/pkg/codegen/operations.go index 314e89462d..4b76521638 100644 --- a/pkg/codegen/operations.go +++ b/pkg/codegen/operations.go @@ -650,7 +650,7 @@ func GenerateBodyDefinitions(operationID string, bodyOrRef *openapi3.RequestBody } // If the body is a pre-defined type - if IsGoTypeReference(content.Schema.Ref) { + if content.Schema != nil && IsGoTypeReference(content.Schema.Ref) { // Convert the reference path to Go type refType, err := RefPathToGoType(content.Schema.Ref) if err != nil { diff --git a/pkg/codegen/utils.go b/pkg/codegen/utils.go index 52274c0a67..da6df761c8 100644 --- a/pkg/codegen/utils.go +++ b/pkg/codegen/utils.go @@ -718,6 +718,9 @@ func EscapePathElements(path string) string { // x-go-name, the new name is returned, otherwise, the original name is // returned. func renameSchema(schemaName string, schemaRef *openapi3.SchemaRef) (string, error) { + if schemaRef == nil { + return schemaName, nil + } // References will not change type names. if schemaRef.Ref != "" { return SchemaNameToTypeName(schemaName), nil From 4d9a2d5f5cf7f1e36d95e526ee8835ff38fa35c0 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Sat, 26 Nov 2022 08:50:20 +0000 Subject: [PATCH 2/8] Fix typo in `openapi` in spec --- internal/test/issues/issue-removed-external-ref/spec-base.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/test/issues/issue-removed-external-ref/spec-base.yaml b/internal/test/issues/issue-removed-external-ref/spec-base.yaml index 36f285cc30..d6e519aa8c 100644 --- a/internal/test/issues/issue-removed-external-ref/spec-base.yaml +++ b/internal/test/issues/issue-removed-external-ref/spec-base.yaml @@ -1,4 +1,4 @@ -eopenapi: 3.0.2 +openapi: 3.0.2 info: version: "0.0.1" paths: From 7504d9b44e761473405ee962260cf6f7345aaa7e Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Fri, 25 Nov 2022 17:46:09 +0000 Subject: [PATCH 3/8] Generate raw types for non-JSON `responses` As part of future changes we need to be able to reference all the types in the defined `responses` of a specification. However, as we're currently only rendering `application/json` media types, this fails. Instead, we can generate `json.RawMessage` (which is an alias of `[]byte`) for these types, which allow referencing them, and (un)marshaling data to the types. --- pkg/codegen/codegen.go | 53 ++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index 50866917e8..65095b6138 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -507,17 +507,13 @@ func GenerateTypesForResponses(t *template.Template, responses openapi3.Response for _, responseName := range SortedResponsesKeys(responses) { responseOrRef := responses[responseName] - // We have to generate the response object. We're only going to - // handle application/json media types here. Other responses should - // simply be specified as strings or byte arrays. + // We have to generate the response object. We're only going to provide a + // struct for application/json media types here. Other responses will be + // generated as byte arrays response := responseOrRef.Value jsonResponse, found := response.Content["application/json"] - if found { - goType, err := GenerateGoSchema(jsonResponse.Schema, []string{responseName}) - if err != nil { - return nil, fmt.Errorf("error generating Go type for schema in response %s: %w", responseName, err) - } + if !found { goTypeName, err := renameResponse(responseName, responseOrRef) if err != nil { return nil, fmt.Errorf("error making name for components/responses/%s: %w", responseName, err) @@ -525,21 +521,44 @@ func GenerateTypesForResponses(t *template.Template, responses openapi3.Response typeDef := TypeDefinition{ JsonName: responseName, - Schema: goType, + Schema: Schema{ + GoType: "json.RawMessage", + SkipOptionalPointer: true, + }, TypeName: goTypeName, } - if responseOrRef.Ref != "" { - // Generate a reference type for referenced parameters - refType, err := RefPathToGoType(responseOrRef.Ref) - if err != nil { - return nil, fmt.Errorf("error generating Go type for (%s) in parameter %s: %w", responseOrRef.Ref, responseName, err) - } - typeDef.TypeName = SchemaNameToTypeName(refType) - } types = append(types, typeDef) + continue + } + + goType, err := GenerateGoSchema(jsonResponse.Schema, []string{responseName}) + if err != nil { + return nil, fmt.Errorf("error generating Go type for schema in response %s: %w", responseName, err) + } + + goTypeName, err := renameResponse(responseName, responseOrRef) + if err != nil { + return nil, fmt.Errorf("error making name for components/responses/%s: %w", responseName, err) + } + + typeDef := TypeDefinition{ + JsonName: responseName, + Schema: goType, + TypeName: goTypeName, + } + + if responseOrRef.Ref != "" { + // Generate a reference type for referenced parameters + refType, err := RefPathToGoType(responseOrRef.Ref) + if err != nil { + return nil, fmt.Errorf("error generating Go type for (%s) in parameter %s: %w", responseOrRef.Ref, responseName, err) + } + typeDef.TypeName = SchemaNameToTypeName(refType) } + types = append(types, typeDef) } + return types, nil } From fe82a4b0051904a6ad9339cb619f985d9d81fa7e Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Fri, 25 Nov 2022 17:51:20 +0000 Subject: [PATCH 4/8] make-generate --- internal/test/parameters/parameters.gen.go | 3 +++ internal/test/strict-server/chi/types.gen.go | 7 +++++++ internal/test/strict-server/client/client.gen.go | 3 +++ internal/test/strict-server/echo/types.gen.go | 7 +++++++ internal/test/strict-server/gin/types.gen.go | 7 +++++++ 5 files changed, 27 insertions(+) diff --git a/internal/test/parameters/parameters.gen.go b/internal/test/parameters/parameters.gen.go index 45d11b462c..bdd5290e23 100644 --- a/internal/test/parameters/parameters.gen.go +++ b/internal/test/parameters/parameters.gen.go @@ -40,6 +40,9 @@ type Object struct { Role string `json:"role"` } +// SimpleResponse defines model for SimpleResponse. +type SimpleResponse json.RawMessage + // GetCookieParams defines parameters for GetCookie. type GetCookieParams struct { // P primitive diff --git a/internal/test/strict-server/chi/types.gen.go b/internal/test/strict-server/chi/types.gen.go index 33827cb7a4..639d43c248 100644 --- a/internal/test/strict-server/chi/types.gen.go +++ b/internal/test/strict-server/chi/types.gen.go @@ -3,11 +3,18 @@ // Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT. package api +import ( + "encoding/json" +) + // Example defines model for example. type Example struct { Value *string `json:"value,omitempty"` } +// Badrequest defines model for badrequest. +type Badrequest json.RawMessage + // Reusableresponse defines model for reusableresponse. type Reusableresponse = Example diff --git a/internal/test/strict-server/client/client.gen.go b/internal/test/strict-server/client/client.gen.go index 68105f2f24..055f4964dc 100644 --- a/internal/test/strict-server/client/client.gen.go +++ b/internal/test/strict-server/client/client.gen.go @@ -21,6 +21,9 @@ type Example struct { Value *string `json:"value,omitempty"` } +// Badrequest defines model for badrequest. +type Badrequest json.RawMessage + // Reusableresponse defines model for reusableresponse. type Reusableresponse = Example diff --git a/internal/test/strict-server/echo/types.gen.go b/internal/test/strict-server/echo/types.gen.go index 33827cb7a4..639d43c248 100644 --- a/internal/test/strict-server/echo/types.gen.go +++ b/internal/test/strict-server/echo/types.gen.go @@ -3,11 +3,18 @@ // Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT. package api +import ( + "encoding/json" +) + // Example defines model for example. type Example struct { Value *string `json:"value,omitempty"` } +// Badrequest defines model for badrequest. +type Badrequest json.RawMessage + // Reusableresponse defines model for reusableresponse. type Reusableresponse = Example diff --git a/internal/test/strict-server/gin/types.gen.go b/internal/test/strict-server/gin/types.gen.go index 33827cb7a4..639d43c248 100644 --- a/internal/test/strict-server/gin/types.gen.go +++ b/internal/test/strict-server/gin/types.gen.go @@ -3,11 +3,18 @@ // Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT. package api +import ( + "encoding/json" +) + // Example defines model for example. type Example struct { Value *string `json:"value,omitempty"` } +// Badrequest defines model for badrequest. +type Badrequest json.RawMessage + // Reusableresponse defines model for reusableresponse. type Reusableresponse = Example From 1c016f960531b759947152cbf123ae3def116260 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Fri, 25 Nov 2022 17:46:09 +0000 Subject: [PATCH 5/8] rew!!!Generate raw types for non-JSON `requestBodies` As part of future changes we need to be able to reference all the types in the defined `requestBodies` of a specification. However, as we're currently only rendering `application/json` media types, this fails. Instead, we can generate `json.RawMessage` (which is an alias of `[]byte`) for these types, which allow referencing them, and (un)marshaling data to the types. --- pkg/codegen/codegen.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index 65095b6138..4dab471eb9 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -574,6 +574,25 @@ func GenerateTypesForRequestBodies(t *template.Template, bodies map[string]*open // the other body formats are up to the user. response := requestBodyRef.Value jsonBody, found := response.Content["application/json"] + if !found { + goTypeName, err := renameRequestBody(requestBodyName, requestBodyRef) + if err != nil { + return nil, fmt.Errorf("error making name for components/requestBodies/%s: %w", requestBodyName, err) + } + + typeDef := TypeDefinition{ + JsonName: requestBodyName, + Schema: Schema{ + GoType: "json.RawMessage", + SkipOptionalPointer: true, + }, + TypeName: goTypeName, + } + + types = append(types, typeDef) + continue + } + if found { goType, err := GenerateGoSchema(jsonBody.Schema, []string{requestBodyName}) if err != nil { From ab1ddd05ed5681db4d94d56f65ba95f8e0e8d062 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Sun, 27 Nov 2022 16:12:28 +0000 Subject: [PATCH 6/8] prefactor into `generateTypesForRequestBody` --- pkg/codegen/codegen.go | 100 ++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index 4dab471eb9..889c7497e8 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -562,64 +562,74 @@ func GenerateTypesForResponses(t *template.Template, responses openapi3.Response return types, nil } -// GenerateTypesForRequestBodies generates type definitions for any custom types defined in the -// components/requestBodies section of the Swagger spec. -func GenerateTypesForRequestBodies(t *template.Template, bodies map[string]*openapi3.RequestBodyRef) ([]TypeDefinition, error) { +func generateTypesForRequestBody(requestBodyName string, requestBodyRef *openapi3.RequestBodyRef) ([]TypeDefinition, error) { var types []TypeDefinition - for _, requestBodyName := range SortedRequestBodyKeys(bodies) { - requestBodyRef := bodies[requestBodyName] + // As for responses, we will only generate Go code for JSON bodies, + // the other body formats are up to the user. + response := requestBodyRef.Value + jsonBody, found := response.Content["application/json"] + if !found { + goTypeName, err := renameRequestBody(requestBodyName, requestBodyRef) + if err != nil { + return nil, fmt.Errorf("error making name for components/requestBodies/%s: %w", requestBodyName, err) + } - // As for responses, we will only generate Go code for JSON bodies, - // the other body formats are up to the user. - response := requestBodyRef.Value - jsonBody, found := response.Content["application/json"] - if !found { - goTypeName, err := renameRequestBody(requestBodyName, requestBodyRef) - if err != nil { - return nil, fmt.Errorf("error making name for components/requestBodies/%s: %w", requestBodyName, err) - } + typeDef := TypeDefinition{ + JsonName: requestBodyName, + Schema: Schema{ + GoType: "json.RawMessage", + SkipOptionalPointer: true, + }, + TypeName: goTypeName, + } - typeDef := TypeDefinition{ - JsonName: requestBodyName, - Schema: Schema{ - GoType: "json.RawMessage", - SkipOptionalPointer: true, - }, - TypeName: goTypeName, - } + types = append(types, typeDef) + } - types = append(types, typeDef) - continue + if found { + goType, err := GenerateGoSchema(jsonBody.Schema, []string{requestBodyName}) + if err != nil { + return nil, fmt.Errorf("error generating Go type for schema in body %s: %w", requestBodyName, err) } - if found { - goType, err := GenerateGoSchema(jsonBody.Schema, []string{requestBodyName}) - if err != nil { - return nil, fmt.Errorf("error generating Go type for schema in body %s: %w", requestBodyName, err) - } + goTypeName, err := renameRequestBody(requestBodyName, requestBodyRef) + if err != nil { + return nil, fmt.Errorf("error making name for components/schemas/%s: %w", requestBodyName, err) + } + + typeDef := TypeDefinition{ + JsonName: requestBodyName, + Schema: goType, + TypeName: goTypeName, + } - goTypeName, err := renameRequestBody(requestBodyName, requestBodyRef) + if requestBodyRef.Ref != "" { + // Generate a reference type for referenced bodies + refType, err := RefPathToGoType(requestBodyRef.Ref) if err != nil { - return nil, fmt.Errorf("error making name for components/schemas/%s: %w", requestBodyName, err) + return nil, fmt.Errorf("error generating Go type for (%s) in body %s: %w", requestBodyRef.Ref, requestBodyName, err) } + typeDef.TypeName = SchemaNameToTypeName(refType) + } + types = append(types, typeDef) + } - typeDef := TypeDefinition{ - JsonName: requestBodyName, - Schema: goType, - TypeName: goTypeName, - } + return types, nil +} - if requestBodyRef.Ref != "" { - // Generate a reference type for referenced bodies - refType, err := RefPathToGoType(requestBodyRef.Ref) - if err != nil { - return nil, fmt.Errorf("error generating Go type for (%s) in body %s: %w", requestBodyRef.Ref, requestBodyName, err) - } - typeDef.TypeName = SchemaNameToTypeName(refType) - } - types = append(types, typeDef) +// GenerateTypesForRequestBodies generates type definitions for any custom types defined in the +// components/requestBodies section of the Swagger spec. +func GenerateTypesForRequestBodies(t *template.Template, bodies map[string]*openapi3.RequestBodyRef) ([]TypeDefinition, error) { + var types []TypeDefinition + + for _, requestBodyName := range SortedRequestBodyKeys(bodies) { + requestBodyRef := bodies[requestBodyName] + requestBodyTypes, err := generateTypesForRequestBody(requestBodyName, requestBodyRef) + if err != nil { + return nil, err } + types = append(types, requestBodyTypes...) } return types, nil } From 7a28d911b3c236150f5721d282e39ed3fce6bb29 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Wed, 23 Nov 2022 09:35:43 +0000 Subject: [PATCH 7/8] REW!!!! Generate anonymous objects referenced in `paths` Previously, there was no way to render any anonymous types that are referenced in the `paths` of an OpenAPI specification. Although there is a strong preference in the community to use the `/components/schemas/`, there are times that it's out of our control to move objects around. This generates both the `requestBody` and `responses`. TODO Closes 626 TODO --- internal/test/issues/issue-626/config.yaml | 4 + internal/test/issues/issue-626/doc.go | 3 + internal/test/issues/issue-626/issue.gen.go | 36 ++++++ internal/test/issues/issue-626/spec.yaml | 109 +++++++++++++++++ pkg/codegen/codegen.go | 129 +++++++++++++++++++- pkg/codegen/template_helpers.go | 8 ++ 6 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 internal/test/issues/issue-626/config.yaml create mode 100644 internal/test/issues/issue-626/doc.go create mode 100644 internal/test/issues/issue-626/issue.gen.go create mode 100644 internal/test/issues/issue-626/spec.yaml diff --git a/internal/test/issues/issue-626/config.yaml b/internal/test/issues/issue-626/config.yaml new file mode 100644 index 0000000000..d5d18664d4 --- /dev/null +++ b/internal/test/issues/issue-626/config.yaml @@ -0,0 +1,4 @@ +package: issue626 +generate: + models: true +output: issue.gen.go diff --git a/internal/test/issues/issue-626/doc.go b/internal/test/issues/issue-626/doc.go new file mode 100644 index 0000000000..516dd9e39f --- /dev/null +++ b/internal/test/issues/issue-626/doc.go @@ -0,0 +1,3 @@ +package issue626 + +//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml diff --git a/internal/test/issues/issue-626/issue.gen.go b/internal/test/issues/issue-626/issue.gen.go new file mode 100644 index 0000000000..ca196dbb81 --- /dev/null +++ b/internal/test/issues/issue-626/issue.gen.go @@ -0,0 +1,36 @@ +// Package issue626 provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT. +package issue626 + +// NewPetResponseBody200ApplicationJson defines model for the response body for POST /pets (200, application/json). +type NewPetResponseBody200ApplicationJson struct { + // Names The names of the pets. + Names []string `json:"names"` +} + +// NewPetResponseBody200ApplicationYaml defines model for the response body for POST /pets (200, application/yaml). +type NewPetResponseBody200ApplicationYaml = map[string]interface{} + +// NewPetResponseBody200TextPlain defines model for the response body for POST /pets (200, text/plain). +type NewPetResponseBody200TextPlain = map[string]interface{} + +// NewPetJSONBody defines parameters for NewPet. +type NewPetJSONBody struct { + // Names The names of the pets. + Names []string `json:"names"` +} + +// NewPetTextBody defines parameters for NewPet. +type NewPetTextBody = string + +// NewPetParams defines parameters for NewPet. +type NewPetParams struct { + Tags []string `form:"tags" json:"tags"` +} + +// NewPetJSONRequestBody defines body for NewPet for application/json ContentType. +type NewPetJSONRequestBody NewPetJSONBody + +// NewPetTextRequestBody defines body for NewPet for text/plain ContentType. +type NewPetTextRequestBody = NewPetTextBody diff --git a/internal/test/issues/issue-626/spec.yaml b/internal/test/issues/issue-626/spec.yaml new file mode 100644 index 0000000000..23d854808d --- /dev/null +++ b/internal/test/issues/issue-626/spec.yaml @@ -0,0 +1,109 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Issue 626 test + description: Checks that anonymously defined objects are created +paths: + + /no-content-defined: + get: + responses: + content: {} + /no-response-schema: + get: + responses: + content: + application/json: {} + /requestBody-is-ref: + post: + requestBody: + $ref: '#/components/requestBodies/RequiredBody' + /requestBody-conflicts: + post: + operationId: requestBodyConflicts + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RequestBodyConflictsRequestBody' + /pets: + post: + operationId: newPet + parameters: + - name: tags + in: query + required: true + style: form + schema: + type: array + items: + type: string + requestBody: + required: true + content: + text/plain: + schema: + type: string + application/yaml: + schema: + type: object + # will conflict + # application/vnd.api+json: + # schema: + # type: object + application/json: + schema: + type: object + required: + - names + properties: + names: + type: array + description: The names of the pets. + items: + type: string + responses: + '200': + description: valid pets + content: + text/plain: + schema: + type: object + application/yaml: + schema: + type: object + # will conflict + # application/vnd.api+json: {} + application/json: + schema: + type: object + required: + - names + properties: + names: + type: array + description: The names of the pets. + items: + type: string +components: + requestBodies: + RequiredBody: + content: + application/json: + schema: + properties: + Field: + type: string + required: [ Field ] + text/plain: + schema: + type: string + schemas: + # a warning that types may clash + RequestBodyConflictsRequestBody: + x-go-name: Renamed_RequestBodyConflictsRequestBody + schema: + properties: + Field: + type: string + required: [ Field ] diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index 889c7497e8..4bec95c6b3 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -344,11 +344,17 @@ func GenerateTypeDefinitions(t *template.Template, swagger *openapi3.T, ops []Op return "", fmt.Errorf("error generating Go types for component schemas: %w", err) } + pathsTypes, err := GenerateTypesForPaths(t, swagger.Paths, excludeSchemas) + if err != nil { + return "", fmt.Errorf("error generating Go types for paths: %w", err) + } + allTypes := append(schemaTypes, pathsTypes...) + paramTypes, err := GenerateTypesForParameters(t, swagger.Components.Parameters) if err != nil { return "", fmt.Errorf("error generating Go types for component parameters: %w", err) } - allTypes := append(schemaTypes, paramTypes...) + allTypes = append(allTypes, paramTypes...) responseTypes, err := GenerateTypesForResponses(t, swagger.Components.Responses) if err != nil { @@ -462,6 +468,127 @@ func GenerateTypesForSchemas(t *template.Template, schemas map[string]*openapi3. return types, nil } +// GenerateTypesForPaths generates type definitions for any custom types defined in the +// paths section of the Swagger spec. +func GenerateTypesForPaths(t *template.Template, paths openapi3.Paths, excludeSchemas []string) ([]TypeDefinition, error) { + excludeSchemasMap := make(map[string]bool) + for _, schema := range excludeSchemas { + excludeSchemasMap[schema] = true + } + + types := make([]TypeDefinition, 0) + + // We're going to define Go types for every object under paths + for _, pathName := range SortedPathsKeys(paths) { + for _, operationName := range SortedOperationsKeys(paths[pathName].Operations()) { + operation := paths[pathName].Operations()[operationName] + // starting with request bodies + if operation.RequestBody != nil { + sortedContentKeys := SortedContentKeys(operation.RequestBody.Value.Content) + for _, mediaTypeStr := range sortedContentKeys { + mediaType := operation.RequestBody.Value.Content.Get(mediaTypeStr) + + typeName := "" + if operation.OperationID != "" { + typeName += ToCamelCase(operation.OperationID) + } else { + typeName += ToCamelCase(strings.ToLower(operationName)) + ToCamelCase(pathName) + } + typeName += "RequestBody" + + // when there are multiple media types provided for the Response, add a suffix for the media type + if len(sortedContentKeys) > 1 { + typeName += mediaTypeToGoName(mediaTypeStr) + } + + goSchema, err := GenerateGoSchema(mediaType.Schema, []string{typeName}) + if err != nil { + return nil, fmt.Errorf("error converting Schema for %s %s to Go type:: %w", operationName, pathName, err) + } + + goTypeName, err := renameSchema(typeName, mediaType.Schema) + if err != nil { + return nil, fmt.Errorf("error generating a Go type name for %s %s with provided typeName %s: %w", operationName, pathName, typeName, err) + } + + typeDef := TypeDefinition{ + JsonName: fmt.Sprintf("the request body for %s %s (%s)", operationName, pathName, mediaTypeStr), + TypeName: goTypeName, + Schema: goSchema, + } + + if operation.RequestBody.Ref != "" { + // Generate a reference type for referenced types + refType, err := RefPathToGoType(operation.RequestBody.Ref) + if err != nil { + return nil, fmt.Errorf("error generating Go type for %s %s: %w", operationName, pathName, err) + } + typeDef.Schema = Schema{ + RefType: refType, + } + } + + types = append(types, typeDef) + types = append(types, goSchema.GetAdditionalTypeDefs()...) + } + } + + // then with response bodies + for _, statusCodeOrDefault := range SortedResponsesKeys(operation.Responses) { + v := operation.Responses[statusCodeOrDefault] + sortedContentKeys := SortedContentKeys(v.Value.Content) + for _, mediaTypeStr := range sortedContentKeys { + mediaType := v.Value.Content.Get(mediaTypeStr) + + typeName := "" + if operation.OperationID != "" { + typeName += ToCamelCase(operation.OperationID) + } else { + typeName += ToCamelCase(strings.ToLower(operationName)) + ToCamelCase(pathName) + } + typeName += fmt.Sprintf("ResponseBody%s", ToCamelCase(statusCodeOrDefault)) + + // when there are multiple media types provided for the Response, add a suffix for the media type + if len(sortedContentKeys) > 1 { + typeName += mediaTypeToGoName(mediaTypeStr) + } + + goSchema, err := GenerateGoSchema(mediaType.Schema, []string{typeName}) + if err != nil { + return nil, fmt.Errorf("error converting Schema for %s %s to Go type:: %w", operationName, pathName, err) + } + + goTypeName, err := renameSchema(typeName, mediaType.Schema) + if err != nil { + return nil, fmt.Errorf("error generating a Go type name for %s %s with provided typeName %s: %w", operationName, pathName, typeName, err) + } + + typeDef := TypeDefinition{ + JsonName: fmt.Sprintf("the response body for %s %s (%s, %s)", operationName, pathName, statusCodeOrDefault, mediaTypeStr), + TypeName: goTypeName, + Schema: goSchema, + } + + if v.Ref != "" { + // Generate a reference type for referenced types + refType, err := RefPathToGoType(v.Ref) + if err != nil { + return nil, fmt.Errorf("error generating Go type for %s %s: %w", operationName, pathName, err) + } + typeDef.Schema = Schema{ + RefType: refType, + } + } + + types = append(types, typeDef) + types = append(types, goSchema.GetAdditionalTypeDefs()...) + } + } + } + } + return types, nil +} + // GenerateTypesForParameters generates type definitions for any custom types defined in the // components/parameters section of the Swagger spec. func GenerateTypesForParameters(t *template.Template, params map[string]*openapi3.ParameterRef) ([]TypeDefinition, error) { diff --git a/pkg/codegen/template_helpers.go b/pkg/codegen/template_helpers.go index 7585a26801..941b59acad 100644 --- a/pkg/codegen/template_helpers.go +++ b/pkg/codegen/template_helpers.go @@ -17,6 +17,7 @@ import ( "bytes" "fmt" "os" + "regexp" "strings" "text/template" @@ -41,6 +42,8 @@ var ( responseTypeSuffix = "Response" titleCaser = cases.Title(language.English) + + mediaTypeToGoNameRe = regexp.MustCompile(`[^a-zA-Z]`) ) // This function takes an array of Parameter definition, and generates a valid @@ -271,6 +274,11 @@ func stripNewLines(s string) string { return r.Replace(s) } +func mediaTypeToGoName(mediaType string) string { + s := titleCaser.String(mediaType) + return mediaTypeToGoNameRe.ReplaceAllString(s, "") +} + // TemplateFunctions is passed to the template engine, and we can call each // function here by keyName from the template code. var TemplateFunctions = template.FuncMap{ From aa7cfeee84b95ab89695599c61644f4d626fb2e0 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Fri, 25 Nov 2022 17:52:36 +0000 Subject: [PATCH 8/8] make-generate --- .../authenticated-api/echo/api/api.gen.go | 9 + .../custom-client-type.gen.go | 3 + .../petstore-expanded/chi/api/petstore.gen.go | 24 +++ .../echo/api/models/models.gen.go | 24 +++ .../gin/api/petstore-types.gen.go | 24 +++ .../gorilla/api/petstore.gen.go | 24 +++ .../petstore-expanded/petstore-client.gen.go | 24 +++ .../strict/api/petstore-types.gen.go | 24 +++ internal/test/all_of/v1/openapi.gen.go | 4 + internal/test/all_of/v2/openapi.gen.go | 4 + internal/test/client/client.gen.go | 17 ++ internal/test/components/components.gen.go | 165 ++++++++++++++++++ internal/test/issues/issue-312/issue.gen.go | 12 ++ internal/test/issues/issue-52/issue.gen.go | 3 + internal/test/issues/issue-579/issue.gen.go | 3 + internal/test/issues/issue-626/issue.gen.go | 46 +++++ internal/test/issues/issue-832/issue.gen.go | 6 + .../issue-grab_import_names/issue.gen.go | 3 + .../issue-illegal_enum_names/issue.gen.go | 3 + .../gen/spec_base/issue.gen.go | 11 ++ internal/test/parameters/parameters.gen.go | 60 +++++++ internal/test/schemas/schemas.gen.go | 38 ++++ internal/test/server/server.gen.go | 45 +++++ internal/test/strict-server/chi/types.gen.go | 78 +++++++++ .../test/strict-server/client/client.gen.go | 78 +++++++++ internal/test/strict-server/echo/types.gen.go | 78 +++++++++ internal/test/strict-server/gin/types.gen.go | 78 +++++++++ 27 files changed, 888 insertions(+) diff --git a/examples/authenticated-api/echo/api/api.gen.go b/examples/authenticated-api/echo/api/api.gen.go index 1433f2d5fd..f9b71fa8c5 100644 --- a/examples/authenticated-api/echo/api/api.gen.go +++ b/examples/authenticated-api/echo/api/api.gen.go @@ -44,6 +44,15 @@ type ThingWithID struct { Name string `json:"name"` } +// ListThingsResponseBody200 defines model for the response body for GET /things (200, application/json). +type ListThingsResponseBody200 = []ThingWithID + +// AddThingRequestBody defines model for the request body for POST /things (application/json). +type AddThingRequestBody = Thing + +// AddThingResponseBody201 defines model for the response body for POST /things (201, application/json). +type AddThingResponseBody201 = []ThingWithID + // AddThingJSONRequestBody defines body for AddThing for application/json ContentType. type AddThingJSONRequestBody = Thing diff --git a/examples/custom-client-type/custom-client-type.gen.go b/examples/custom-client-type/custom-client-type.gen.go index 34c34ea99e..e7d119b01d 100644 --- a/examples/custom-client-type/custom-client-type.gen.go +++ b/examples/custom-client-type/custom-client-type.gen.go @@ -18,6 +18,9 @@ type Client struct { Name string `json:"name"` } +// GetClientResponseBody200 defines model for the response body for GET /client (200, application/json). +type GetClientResponseBody200 = Client + // RequestEditorFn is the function signature for the RequestEditor callback function type RequestEditorFn func(ctx context.Context, req *http.Request) error diff --git a/examples/petstore-expanded/chi/api/petstore.gen.go b/examples/petstore-expanded/chi/api/petstore.gen.go index 66505c564f..287a02cd0d 100644 --- a/examples/petstore-expanded/chi/api/petstore.gen.go +++ b/examples/petstore-expanded/chi/api/petstore.gen.go @@ -48,6 +48,30 @@ type Pet struct { Tag *string `json:"tag,omitempty"` } +// FindPetsResponseBody200 defines model for the response body for GET /pets (200, application/json). +type FindPetsResponseBody200 = []Pet + +// FindPetsResponseBodyDefault defines model for the response body for GET /pets (default, application/json). +type FindPetsResponseBodyDefault = Error + +// AddPetRequestBody defines model for the request body for POST /pets (application/json). +type AddPetRequestBody = NewPet + +// AddPetResponseBody200 defines model for the response body for POST /pets (200, application/json). +type AddPetResponseBody200 = Pet + +// AddPetResponseBodyDefault defines model for the response body for POST /pets (default, application/json). +type AddPetResponseBodyDefault = Error + +// DeletePetResponseBodyDefault defines model for the response body for DELETE /pets/{id} (default, application/json). +type DeletePetResponseBodyDefault = Error + +// FindPetByIDResponseBody200 defines model for the response body for GET /pets/{id} (200, application/json). +type FindPetByIDResponseBody200 = Pet + +// FindPetByIDResponseBodyDefault defines model for the response body for GET /pets/{id} (default, application/json). +type FindPetByIDResponseBodyDefault = Error + // FindPetsParams defines parameters for FindPets. type FindPetsParams struct { // Tags tags to filter by diff --git a/examples/petstore-expanded/echo/api/models/models.gen.go b/examples/petstore-expanded/echo/api/models/models.gen.go index f15f25527b..dc1b461f45 100644 --- a/examples/petstore-expanded/echo/api/models/models.gen.go +++ b/examples/petstore-expanded/echo/api/models/models.gen.go @@ -33,6 +33,30 @@ type Pet struct { Tag *string `json:"tag,omitempty"` } +// FindPetsResponseBody200 defines model for the response body for GET /pets (200, application/json). +type FindPetsResponseBody200 = []Pet + +// FindPetsResponseBodyDefault defines model for the response body for GET /pets (default, application/json). +type FindPetsResponseBodyDefault = Error + +// AddPetRequestBody defines model for the request body for POST /pets (application/json). +type AddPetRequestBody = NewPet + +// AddPetResponseBody200 defines model for the response body for POST /pets (200, application/json). +type AddPetResponseBody200 = Pet + +// AddPetResponseBodyDefault defines model for the response body for POST /pets (default, application/json). +type AddPetResponseBodyDefault = Error + +// DeletePetResponseBodyDefault defines model for the response body for DELETE /pets/{id} (default, application/json). +type DeletePetResponseBodyDefault = Error + +// FindPetByIDResponseBody200 defines model for the response body for GET /pets/{id} (200, application/json). +type FindPetByIDResponseBody200 = Pet + +// FindPetByIDResponseBodyDefault defines model for the response body for GET /pets/{id} (default, application/json). +type FindPetByIDResponseBodyDefault = Error + // FindPetsParams defines parameters for FindPets. type FindPetsParams struct { // Tags tags to filter by diff --git a/examples/petstore-expanded/gin/api/petstore-types.gen.go b/examples/petstore-expanded/gin/api/petstore-types.gen.go index 16bbe200cf..5b010bb44e 100644 --- a/examples/petstore-expanded/gin/api/petstore-types.gen.go +++ b/examples/petstore-expanded/gin/api/petstore-types.gen.go @@ -33,6 +33,30 @@ type Pet struct { Tag *string `json:"tag,omitempty"` } +// FindPetsResponseBody200 defines model for the response body for GET /pets (200, application/json). +type FindPetsResponseBody200 = []Pet + +// FindPetsResponseBodyDefault defines model for the response body for GET /pets (default, application/json). +type FindPetsResponseBodyDefault = Error + +// AddPetRequestBody defines model for the request body for POST /pets (application/json). +type AddPetRequestBody = NewPet + +// AddPetResponseBody200 defines model for the response body for POST /pets (200, application/json). +type AddPetResponseBody200 = Pet + +// AddPetResponseBodyDefault defines model for the response body for POST /pets (default, application/json). +type AddPetResponseBodyDefault = Error + +// DeletePetResponseBodyDefault defines model for the response body for DELETE /pets/{id} (default, application/json). +type DeletePetResponseBodyDefault = Error + +// FindPetByIDResponseBody200 defines model for the response body for GET /pets/{id} (200, application/json). +type FindPetByIDResponseBody200 = Pet + +// FindPetByIDResponseBodyDefault defines model for the response body for GET /pets/{id} (default, application/json). +type FindPetByIDResponseBodyDefault = Error + // FindPetsParams defines parameters for FindPets. type FindPetsParams struct { // Tags tags to filter by diff --git a/examples/petstore-expanded/gorilla/api/petstore.gen.go b/examples/petstore-expanded/gorilla/api/petstore.gen.go index deac9824ad..df38ae79e0 100644 --- a/examples/petstore-expanded/gorilla/api/petstore.gen.go +++ b/examples/petstore-expanded/gorilla/api/petstore.gen.go @@ -48,6 +48,30 @@ type Pet struct { Tag *string `json:"tag,omitempty"` } +// FindPetsResponseBody200 defines model for the response body for GET /pets (200, application/json). +type FindPetsResponseBody200 = []Pet + +// FindPetsResponseBodyDefault defines model for the response body for GET /pets (default, application/json). +type FindPetsResponseBodyDefault = Error + +// AddPetRequestBody defines model for the request body for POST /pets (application/json). +type AddPetRequestBody = NewPet + +// AddPetResponseBody200 defines model for the response body for POST /pets (200, application/json). +type AddPetResponseBody200 = Pet + +// AddPetResponseBodyDefault defines model for the response body for POST /pets (default, application/json). +type AddPetResponseBodyDefault = Error + +// DeletePetResponseBodyDefault defines model for the response body for DELETE /pets/{id} (default, application/json). +type DeletePetResponseBodyDefault = Error + +// FindPetByIDResponseBody200 defines model for the response body for GET /pets/{id} (200, application/json). +type FindPetByIDResponseBody200 = Pet + +// FindPetByIDResponseBodyDefault defines model for the response body for GET /pets/{id} (default, application/json). +type FindPetByIDResponseBodyDefault = Error + // FindPetsParams defines parameters for FindPets. type FindPetsParams struct { // Tags tags to filter by diff --git a/examples/petstore-expanded/petstore-client.gen.go b/examples/petstore-expanded/petstore-client.gen.go index 0929a64096..de5bda9773 100644 --- a/examples/petstore-expanded/petstore-client.gen.go +++ b/examples/petstore-expanded/petstore-client.gen.go @@ -46,6 +46,30 @@ type Pet struct { Tag *string `json:"tag,omitempty"` } +// FindPetsResponseBody200 defines model for the response body for GET /pets (200, application/json). +type FindPetsResponseBody200 = []Pet + +// FindPetsResponseBodyDefault defines model for the response body for GET /pets (default, application/json). +type FindPetsResponseBodyDefault = Error + +// AddPetRequestBody defines model for the request body for POST /pets (application/json). +type AddPetRequestBody = NewPet + +// AddPetResponseBody200 defines model for the response body for POST /pets (200, application/json). +type AddPetResponseBody200 = Pet + +// AddPetResponseBodyDefault defines model for the response body for POST /pets (default, application/json). +type AddPetResponseBodyDefault = Error + +// DeletePetResponseBodyDefault defines model for the response body for DELETE /pets/{id} (default, application/json). +type DeletePetResponseBodyDefault = Error + +// FindPetByIDResponseBody200 defines model for the response body for GET /pets/{id} (200, application/json). +type FindPetByIDResponseBody200 = Pet + +// FindPetByIDResponseBodyDefault defines model for the response body for GET /pets/{id} (default, application/json). +type FindPetByIDResponseBodyDefault = Error + // FindPetsParams defines parameters for FindPets. type FindPetsParams struct { // Tags tags to filter by diff --git a/examples/petstore-expanded/strict/api/petstore-types.gen.go b/examples/petstore-expanded/strict/api/petstore-types.gen.go index 16bbe200cf..5b010bb44e 100644 --- a/examples/petstore-expanded/strict/api/petstore-types.gen.go +++ b/examples/petstore-expanded/strict/api/petstore-types.gen.go @@ -33,6 +33,30 @@ type Pet struct { Tag *string `json:"tag,omitempty"` } +// FindPetsResponseBody200 defines model for the response body for GET /pets (200, application/json). +type FindPetsResponseBody200 = []Pet + +// FindPetsResponseBodyDefault defines model for the response body for GET /pets (default, application/json). +type FindPetsResponseBodyDefault = Error + +// AddPetRequestBody defines model for the request body for POST /pets (application/json). +type AddPetRequestBody = NewPet + +// AddPetResponseBody200 defines model for the response body for POST /pets (200, application/json). +type AddPetResponseBody200 = Pet + +// AddPetResponseBodyDefault defines model for the response body for POST /pets (default, application/json). +type AddPetResponseBodyDefault = Error + +// DeletePetResponseBodyDefault defines model for the response body for DELETE /pets/{id} (default, application/json). +type DeletePetResponseBodyDefault = Error + +// FindPetByIDResponseBody200 defines model for the response body for GET /pets/{id} (200, application/json). +type FindPetByIDResponseBody200 = Pet + +// FindPetByIDResponseBodyDefault defines model for the response body for GET /pets/{id} (default, application/json). +type FindPetByIDResponseBodyDefault = Error + // FindPetsParams defines parameters for FindPets. type FindPetsParams struct { // Tags tags to filter by diff --git a/internal/test/all_of/v1/openapi.gen.go b/internal/test/all_of/v1/openapi.gen.go index 0023261252..8d06743f4a 100644 --- a/internal/test/all_of/v1/openapi.gen.go +++ b/internal/test/all_of/v1/openapi.gen.go @@ -38,6 +38,10 @@ type PersonWithID struct { ID int64 `json:"ID"` } +// PlaceholderResponseBodyDefault This is a person record as returned from a Create endpoint. It contains +// all the fields of a Person, with an additional resource UUID. +type PlaceholderResponseBodyDefault = PersonWithID + // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ diff --git a/internal/test/all_of/v2/openapi.gen.go b/internal/test/all_of/v2/openapi.gen.go index 3222dcf0a6..f73c4d9ec7 100644 --- a/internal/test/all_of/v2/openapi.gen.go +++ b/internal/test/all_of/v2/openapi.gen.go @@ -38,6 +38,10 @@ type PersonWithID struct { LastName string `json:"LastName"` } +// PlaceholderResponseBodyDefault This is a person record as returned from a Create endpoint. It contains +// all the fields of a Person, with an additional resource UUID. +type PlaceholderResponseBodyDefault = PersonWithID + // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ diff --git a/internal/test/client/client.gen.go b/internal/test/client/client.gen.go index 865727b6ac..1be8a51901 100644 --- a/internal/test/client/client.gen.go +++ b/internal/test/client/client.gen.go @@ -12,6 +12,8 @@ import ( "net/http" "net/url" "strings" + + openapi_types "github.com/deepmap/oapi-codegen/pkg/types" ) const ( @@ -24,6 +26,21 @@ type SchemaObject struct { Role string `json:"role"` } +// PostBothRequestBodyApplicationJson defines model for the request body for POST /with_both_bodies (application/json). +type PostBothRequestBodyApplicationJson = SchemaObject + +// PostBothRequestBodyApplicationOctetStream defines model for the request body for POST /with_both_bodies (application/octet-stream). +type PostBothRequestBodyApplicationOctetStream = openapi_types.File + +// PostJsonRequestBody defines model for the request body for POST /with_json_body (application/json). +type PostJsonRequestBody = SchemaObject + +// PostOtherRequestBody defines model for the request body for POST /with_other_body (application/octet-stream). +type PostOtherRequestBody = openapi_types.File + +// PostVendorJsonRequestBody defines model for the request body for POST /with_vendor_json (application/vnd.api+json). +type PostVendorJsonRequestBody = map[string]interface{} + // PostVendorJsonJSONBody defines parameters for PostVendorJson. type PostVendorJsonJSONBody = map[string]interface{} diff --git a/internal/test/components/components.gen.go b/internal/test/components/components.gen.go index d7e23d31c9..c69160b66a 100644 --- a/internal/test/components/components.gen.go +++ b/internal/test/components/components.gen.go @@ -330,6 +330,92 @@ type SchemaObject struct { WriteOnlyRequiredProp *int `json:"writeOnlyRequiredProp,omitempty"` } +// EnsureEverythingIsReferencedRequestBodyApplicationJson defines model for the request body for GET /ensure-everything-is-referenced (application/json). +type EnsureEverythingIsReferencedRequestBodyApplicationJson RenamedRequestBody + +// EnsureEverythingIsReferencedRequestBodyTextPlain defines model for the request body for GET /ensure-everything-is-referenced (text/plain). +type EnsureEverythingIsReferencedRequestBodyTextPlain RenamedRequestBody + +// EnsureEverythingIsReferencedResponseBody200 defines model for the response body for GET /ensure-everything-is-referenced (200, application/json). +type EnsureEverythingIsReferencedResponseBody200 struct { + // AnyOf1 simple anyOf case + AnyOf1 *AnyOfObject1 `json:"anyOf1,omitempty"` + + // Five Has additional properties with schema for dictionaries + Five *AdditionalPropertiesObject5 `json:"five,omitempty"` + + // Four Has anonymous field which has additional properties + Four *AdditionalPropertiesObject4 `json:"four,omitempty"` + JsonField *ObjectWithJsonField `json:"jsonField,omitempty"` + + // One Has additional properties of type int + One *AdditionalPropertiesObject1 `json:"one,omitempty"` + + // OneOf1 oneOf with references and no disciminator + OneOf1 *OneOfObject1 `json:"oneOf1,omitempty"` + + // OneOf10 fixed properties, variable required - will compile, but not much sense + OneOf10 *OneOfObject10 `json:"oneOf10,omitempty"` + + // OneOf11 additional properties of oneOf + OneOf11 *OneOfObject11 `json:"oneOf11,omitempty"` + + // OneOf12 allOf of oneOfs + OneOf12 *OneOfObject12 `json:"oneOf12,omitempty"` + + // OneOf2 oneOf with inline elements + OneOf2 *OneOfObject2 `json:"oneOf2,omitempty"` + + // OneOf3 inline OneOf + OneOf3 *OneOfObject3 `json:"oneOf3,omitempty"` + + // OneOf4 oneOf plus fixed type - custom marshaling/unmarshalling + OneOf4 *OneOfObject4 `json:"oneOf4,omitempty"` + + // OneOf5 oneOf with disciminator but no mapping + OneOf5 *OneOfObject5 `json:"oneOf5,omitempty"` + + // OneOf6 oneOf with discriminator and mapping + OneOf6 *OneOfObject6 `json:"oneOf6,omitempty"` + + // OneOf7 array of oneOf + OneOf7 *OneOfObject7 `json:"oneOf7,omitempty"` + + // OneOf8 oneOf with fixed properties + OneOf8 *OneOfObject8 `json:"oneOf8,omitempty"` + + // OneOf9 oneOf with fixed descriminator + OneOf9 *OneOfObject9 `json:"oneOf9,omitempty"` + + // Six Array of object with additional properties + Six *AdditionalPropertiesObject6 `json:"six,omitempty"` + + // Three Allows any additional property + Three *AdditionalPropertiesObject3 `json:"three,omitempty"` + + // Two Does not allow additional properties + Two *AdditionalPropertiesObject2 `json:"two,omitempty"` +} + +// EnsureEverythingIsReferencedResponseBodyDefaultApplicationJson defines model for the response body for GET /ensure-everything-is-referenced (default, application/json). +type EnsureEverythingIsReferencedResponseBodyDefaultApplicationJson RenamedResponseObject + +// EnsureEverythingIsReferencedResponseBodyDefaultTextPlain defines model for the response body for GET /ensure-everything-is-referenced (default, text/plain). +type EnsureEverythingIsReferencedResponseBodyDefaultTextPlain RenamedResponseObject + +// ParamsWithAddPropsResponseBodyDefault defines model for the response body for GET /params_with_add_props (default, text/plain). +type ParamsWithAddPropsResponseBodyDefault = string + +// BodyWithAddPropsRequestBody defines model for the request body for POST /params_with_add_props (application/json). +type BodyWithAddPropsRequestBody struct { + Inner map[string]int `json:"inner"` + Name string `json:"name"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// BodyWithAddPropsResponseBodyDefault defines model for the response body for POST /params_with_add_props (default, text/plain). +type BodyWithAddPropsResponseBodyDefault = string + // EnumParam1 defines model for EnumParam1. type EnumParam1 string @@ -772,6 +858,85 @@ func (a AdditionalPropertiesObject4_Inner) MarshalJSON() ([]byte, error) { return json.Marshal(object) } +// Getter for additional properties for BodyWithAddPropsRequestBody. Returns the specified +// element and whether it was found +func (a BodyWithAddPropsRequestBody) Get(fieldName string) (value interface{}, found bool) { + if a.AdditionalProperties != nil { + value, found = a.AdditionalProperties[fieldName] + } + return +} + +// Setter for additional properties for BodyWithAddPropsRequestBody +func (a *BodyWithAddPropsRequestBody) Set(fieldName string, value interface{}) { + if a.AdditionalProperties == nil { + a.AdditionalProperties = make(map[string]interface{}) + } + a.AdditionalProperties[fieldName] = value +} + +// Override default JSON handling for BodyWithAddPropsRequestBody to handle AdditionalProperties +func (a *BodyWithAddPropsRequestBody) UnmarshalJSON(b []byte) error { + object := make(map[string]json.RawMessage) + err := json.Unmarshal(b, &object) + if err != nil { + return err + } + + if raw, found := object["inner"]; found { + err = json.Unmarshal(raw, &a.Inner) + if err != nil { + return fmt.Errorf("error reading 'inner': %w", err) + } + delete(object, "inner") + } + + if raw, found := object["name"]; found { + err = json.Unmarshal(raw, &a.Name) + if err != nil { + return fmt.Errorf("error reading 'name': %w", err) + } + delete(object, "name") + } + + if len(object) != 0 { + a.AdditionalProperties = make(map[string]interface{}) + for fieldName, fieldBuf := range object { + var fieldVal interface{} + err := json.Unmarshal(fieldBuf, &fieldVal) + if err != nil { + return fmt.Errorf("error unmarshalling field %s: %w", fieldName, err) + } + a.AdditionalProperties[fieldName] = fieldVal + } + } + return nil +} + +// Override default JSON handling for BodyWithAddPropsRequestBody to handle AdditionalProperties +func (a BodyWithAddPropsRequestBody) MarshalJSON() ([]byte, error) { + var err error + object := make(map[string]json.RawMessage) + + object["inner"], err = json.Marshal(a.Inner) + if err != nil { + return nil, fmt.Errorf("error marshaling 'inner': %w", err) + } + + object["name"], err = json.Marshal(a.Name) + if err != nil { + return nil, fmt.Errorf("error marshaling 'name': %w", err) + } + + for fieldName, field := range a.AdditionalProperties { + object[fieldName], err = json.Marshal(field) + if err != nil { + return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err) + } + } + return json.Marshal(object) +} + // AsOneOfVariant4 returns the union data inside the AnyOfObject1 as a OneOfVariant4 func (t AnyOfObject1) AsOneOfVariant4() (OneOfVariant4, error) { var body OneOfVariant4 diff --git a/internal/test/issues/issue-312/issue.gen.go b/internal/test/issues/issue-312/issue.gen.go index c077475b24..a62d0ee5fe 100644 --- a/internal/test/issues/issue-312/issue.gen.go +++ b/internal/test/issues/issue-312/issue.gen.go @@ -42,6 +42,18 @@ type PetNames struct { Names []string `json:"names"` } +// GetPetResponseBody200 defines model for the response body for GET /pets/{petId} (200, application/json). +type GetPetResponseBody200 = Pet + +// ValidatePetsRequestBody defines model for the request body for POST /pets:validate (application/json). +type ValidatePetsRequestBody = PetNames + +// ValidatePetsResponseBody200 defines model for the response body for POST /pets:validate (200, application/json). +type ValidatePetsResponseBody200 = []Pet + +// ValidatePetsResponseBodyDefault defines model for the response body for POST /pets:validate (default, application/json). +type ValidatePetsResponseBodyDefault = Error + // ValidatePetsJSONRequestBody defines body for ValidatePets for application/json ContentType. type ValidatePetsJSONRequestBody = PetNames diff --git a/internal/test/issues/issue-52/issue.gen.go b/internal/test/issues/issue-52/issue.gen.go index d3f1a236da..eaa2833f67 100644 --- a/internal/test/issues/issue-52/issue.gen.go +++ b/internal/test/issues/issue-52/issue.gen.go @@ -34,6 +34,9 @@ type Value struct { StringValue *string `json:"stringValue,omitempty"` } +// ExampleGetResponseBody200 defines model for the response body for GET /example (200, application/json). +type ExampleGetResponseBody200 = Document + // RequestEditorFn is the function signature for the RequestEditor callback function type RequestEditorFn func(ctx context.Context, req *http.Request) error diff --git a/internal/test/issues/issue-579/issue.gen.go b/internal/test/issues/issue-579/issue.gen.go index b7284ffee8..3f44c2b513 100644 --- a/internal/test/issues/issue-579/issue.gen.go +++ b/internal/test/issues/issue-579/issue.gen.go @@ -15,3 +15,6 @@ type Pet struct { Born *AliasedDate `json:"born,omitempty"` BornAt *openapi_types.Date `json:"born_at,omitempty"` } + +// GetPlaceholderResponseBody200 defines model for the response body for GET /placeholder (200, text/plain). +type GetPlaceholderResponseBody200 = string diff --git a/internal/test/issues/issue-626/issue.gen.go b/internal/test/issues/issue-626/issue.gen.go index ca196dbb81..2a38de98f8 100644 --- a/internal/test/issues/issue-626/issue.gen.go +++ b/internal/test/issues/issue-626/issue.gen.go @@ -3,6 +3,21 @@ // Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT. package issue626 +// Renamed_RequestBodyConflictsRequestBody defines model for RequestBodyConflictsRequestBody. +type Renamed_RequestBodyConflictsRequestBody = interface{} + +// NewPetRequestBodyApplicationJson defines model for the request body for POST /pets (application/json). +type NewPetRequestBodyApplicationJson struct { + // Names The names of the pets. + Names []string `json:"names"` +} + +// NewPetRequestBodyApplicationYaml defines model for the request body for POST /pets (application/yaml). +type NewPetRequestBodyApplicationYaml = map[string]interface{} + +// NewPetRequestBodyTextPlain defines model for the request body for POST /pets (text/plain). +type NewPetRequestBodyTextPlain = string + // NewPetResponseBody200ApplicationJson defines model for the response body for POST /pets (200, application/json). type NewPetResponseBody200ApplicationJson struct { // Names The names of the pets. @@ -15,6 +30,20 @@ type NewPetResponseBody200ApplicationYaml = map[string]interface{} // NewPetResponseBody200TextPlain defines model for the response body for POST /pets (200, text/plain). type NewPetResponseBody200TextPlain = map[string]interface{} +// RequestBodyConflictsRequestBody defines model for the request body for POST /requestBody-conflicts (application/json). +type RequestBodyConflictsRequestBody = Renamed_RequestBodyConflictsRequestBody + +// PostRequestBodyIsRefRequestBodyApplicationJson defines model for the request body for POST /requestBody-is-ref (application/json). +type PostRequestBodyIsRefRequestBodyApplicationJson RequiredBody + +// PostRequestBodyIsRefRequestBodyTextPlain defines model for the request body for POST /requestBody-is-ref (text/plain). +type PostRequestBodyIsRefRequestBodyTextPlain RequiredBody + +// RequiredBody defines model for RequiredBody. +type RequiredBody struct { + Field string `json:"Field"` +} + // NewPetJSONBody defines parameters for NewPet. type NewPetJSONBody struct { // Names The names of the pets. @@ -29,8 +58,25 @@ type NewPetParams struct { Tags []string `form:"tags" json:"tags"` } +// PostRequestBodyIsRefJSONBody defines parameters for PostRequestBodyIsRef. +type PostRequestBodyIsRefJSONBody struct { + Field string `json:"Field"` +} + +// PostRequestBodyIsRefTextBody defines parameters for PostRequestBodyIsRef. +type PostRequestBodyIsRefTextBody = string + // NewPetJSONRequestBody defines body for NewPet for application/json ContentType. type NewPetJSONRequestBody NewPetJSONBody // NewPetTextRequestBody defines body for NewPet for text/plain ContentType. type NewPetTextRequestBody = NewPetTextBody + +// RequestBodyConflictsJSONRequestBody defines body for RequestBodyConflicts for application/json ContentType. +type RequestBodyConflictsJSONRequestBody = Renamed_RequestBodyConflictsRequestBody + +// PostRequestBodyIsRefJSONRequestBody defines body for PostRequestBodyIsRef for application/json ContentType. +type PostRequestBodyIsRefJSONRequestBody PostRequestBodyIsRefJSONBody + +// PostRequestBodyIsRefTextRequestBody defines body for PostRequestBodyIsRef for text/plain ContentType. +type PostRequestBodyIsRefTextRequestBody = PostRequestBodyIsRefTextBody diff --git a/internal/test/issues/issue-832/issue.gen.go b/internal/test/issues/issue-832/issue.gen.go index 6bad2fbda1..b5fc42da00 100644 --- a/internal/test/issues/issue-832/issue.gen.go +++ b/internal/test/issues/issue-832/issue.gen.go @@ -37,6 +37,12 @@ type DocumentStatus struct { Value *string `json:"value,omitempty"` } +// ExampleGetResponseBody200 defines model for the response body for GET /example (200, application/json). +type ExampleGetResponseBody200 = Document + +// ExampleGet2ResponseBody200 defines model for the response body for GET /example2 (200, application/json). +type ExampleGet2ResponseBody200 = DocumentStatus + // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ diff --git a/internal/test/issues/issue-grab_import_names/issue.gen.go b/internal/test/issues/issue-grab_import_names/issue.gen.go index 6378e57dfb..a1883df6e5 100644 --- a/internal/test/issues/issue-grab_import_names/issue.gen.go +++ b/internal/test/issues/issue-grab_import_names/issue.gen.go @@ -21,6 +21,9 @@ import ( "github.com/labstack/echo/v4" ) +// GetFooResponseBody200 defines model for the response body for GET /foo (200, application/json). +type GetFooResponseBody200 = string + // GetFooParams defines parameters for GetFoo. type GetFooParams struct { // Foo base64. bytes. chi. context. echo. errors. fmt. gzip. http. io. json. openapi3. diff --git a/internal/test/issues/issue-illegal_enum_names/issue.gen.go b/internal/test/issues/issue-illegal_enum_names/issue.gen.go index 3f0d8e0803..aa1814e4b0 100644 --- a/internal/test/issues/issue-illegal_enum_names/issue.gen.go +++ b/internal/test/issues/issue-illegal_enum_names/issue.gen.go @@ -37,6 +37,9 @@ const ( // Bar defines model for Bar. type Bar string +// GetFooResponseBody200 defines model for the response body for GET /foo (200, application/json). +type GetFooResponseBody200 = []Bar + // RequestEditorFn is the function signature for the RequestEditor callback function type RequestEditorFn func(ctx context.Context, req *http.Request) error diff --git a/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go b/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go index 09e8df32f5..8fc70bccee 100644 --- a/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go +++ b/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go @@ -23,6 +23,17 @@ type PackedBar struct { Id *string `json:"id,omitempty"` } +// PostInvalidExtRefTroubleResponseBody300 defines model for the response body for POST /invalidExtRefTrouble (300, application/json). +type PostInvalidExtRefTroubleResponseBody300 externalRef0.Pascal + +// PostNoTroubleResponseBody200 defines model for the response body for POST /noTrouble (200, application/json). +type PostNoTroubleResponseBody200 struct { + DirectBar *DirectBar `json:"directBar,omitempty"` + DirectFoo *externalRef0.Foo `json:"directFoo,omitempty"` + IndirectFoo *PackedBar `json:"indirectFoo,omitempty"` + Name *string `json:"name,omitempty"` +} + // ServerInterface represents all server handlers. type ServerInterface interface { diff --git a/internal/test/parameters/parameters.gen.go b/internal/test/parameters/parameters.gen.go index bdd5290e23..e66bc63bbc 100644 --- a/internal/test/parameters/parameters.gen.go +++ b/internal/test/parameters/parameters.gen.go @@ -40,6 +40,66 @@ type Object struct { Role string `json:"role"` } +// GetContentObjectResponseBody200 defines model for the response body for GET /contentObject/{param} (200, text/plain). +type GetContentObjectResponseBody200 SimpleResponse + +// GetCookieResponseBodyDefault defines model for the response body for GET /cookie (default, text/plain). +type GetCookieResponseBodyDefault SimpleResponse + +// GetHeaderResponseBodyDefault defines model for the response body for GET /header (default, text/plain). +type GetHeaderResponseBodyDefault SimpleResponse + +// GetLabelExplodeArrayResponseBody200 defines model for the response body for GET /labelExplodeArray/{.param*} (200, text/plain). +type GetLabelExplodeArrayResponseBody200 SimpleResponse + +// GetLabelExplodeObjectResponseBody200 defines model for the response body for GET /labelExplodeObject/{.param*} (200, text/plain). +type GetLabelExplodeObjectResponseBody200 SimpleResponse + +// GetLabelNoExplodeArrayResponseBody200 defines model for the response body for GET /labelNoExplodeArray/{.param} (200, text/plain). +type GetLabelNoExplodeArrayResponseBody200 SimpleResponse + +// GetLabelNoExplodeObjectResponseBody200 defines model for the response body for GET /labelNoExplodeObject/{.param} (200, text/plain). +type GetLabelNoExplodeObjectResponseBody200 SimpleResponse + +// GetMatrixExplodeArrayResponseBody200 defines model for the response body for GET /matrixExplodeArray/{.id*} (200, text/plain). +type GetMatrixExplodeArrayResponseBody200 SimpleResponse + +// GetMatrixExplodeObjectResponseBody200 defines model for the response body for GET /matrixExplodeObject/{.id*} (200, text/plain). +type GetMatrixExplodeObjectResponseBody200 SimpleResponse + +// GetMatrixNoExplodeArrayResponseBody200 defines model for the response body for GET /matrixNoExplodeArray/{.id} (200, text/plain). +type GetMatrixNoExplodeArrayResponseBody200 SimpleResponse + +// GetMatrixNoExplodeObjectResponseBody200 defines model for the response body for GET /matrixNoExplodeObject/{.id} (200, text/plain). +type GetMatrixNoExplodeObjectResponseBody200 SimpleResponse + +// GetPassThroughResponseBody200 defines model for the response body for GET /passThrough/{param} (200, text/plain). +type GetPassThroughResponseBody200 SimpleResponse + +// GetDeepObjectResponseBodyDefault defines model for the response body for GET /queryDeepObject (default, text/plain). +type GetDeepObjectResponseBodyDefault SimpleResponse + +// GetQueryFormResponseBody200 defines model for the response body for GET /queryForm (200, text/plain). +type GetQueryFormResponseBody200 SimpleResponse + +// GetSimpleExplodeArrayResponseBody200 defines model for the response body for GET /simpleExplodeArray/{param*} (200, text/plain). +type GetSimpleExplodeArrayResponseBody200 SimpleResponse + +// GetSimpleExplodeObjectResponseBody200 defines model for the response body for GET /simpleExplodeObject/{param*} (200, text/plain). +type GetSimpleExplodeObjectResponseBody200 SimpleResponse + +// GetSimpleNoExplodeArrayResponseBody200 defines model for the response body for GET /simpleNoExplodeArray/{param} (200, text/plain). +type GetSimpleNoExplodeArrayResponseBody200 SimpleResponse + +// GetSimpleNoExplodeObjectResponseBody200 defines model for the response body for GET /simpleNoExplodeObject/{param} (200, text/plain). +type GetSimpleNoExplodeObjectResponseBody200 SimpleResponse + +// GetSimplePrimitiveResponseBody200 defines model for the response body for GET /simplePrimitive/{param} (200, text/plain). +type GetSimplePrimitiveResponseBody200 SimpleResponse + +// GetStartingWithNumberResponseBody200 defines model for the response body for GET /startingWithNumber/{1param} (200, text/plain). +type GetStartingWithNumberResponseBody200 SimpleResponse + // SimpleResponse defines model for SimpleResponse. type SimpleResponse json.RawMessage diff --git a/internal/test/schemas/schemas.gen.go b/internal/test/schemas/schemas.gen.go index b6a9f2086b..e7383f5280 100644 --- a/internal/test/schemas/schemas.gen.go +++ b/internal/test/schemas/schemas.gen.go @@ -67,6 +67,44 @@ type NullableProperties struct { RequiredAndNullable *string `json:"requiredAndNullable"` } +// EnsureEverythingIsReferencedResponseBody200 defines model for the response body for GET /ensure-everything-is-referenced (200, application/json). +type EnsureEverythingIsReferencedResponseBody200 struct { + AnyType1 *AnyType1 `json:"anyType1,omitempty"` + + // AnyType2 AnyType2 represents any type. + // + // This should be an interface{} + AnyType2 *AnyType2 `json:"anyType2,omitempty"` + CustomStringType *CustomStringType `foo:"bar" json:"customStringType,omitempty"` +} + +// Issue127ResponseBody200ApplicationJson defines model for the response body for GET /issues/127 (200, application/json). +type Issue127ResponseBody200ApplicationJson = GenericObject + +// Issue127ResponseBody200ApplicationXml defines model for the response body for GET /issues/127 (200, application/xml). +type Issue127ResponseBody200ApplicationXml = GenericObject + +// Issue127ResponseBody200TextMarkdown defines model for the response body for GET /issues/127 (200, text/markdown). +type Issue127ResponseBody200TextMarkdown = GenericObject + +// Issue127ResponseBody200TextYaml defines model for the response body for GET /issues/127 (200, text/yaml). +type Issue127ResponseBody200TextYaml = GenericObject + +// Issue127ResponseBodyDefaultApplicationJson defines model for the response body for GET /issues/127 (default, application/json). +type Issue127ResponseBodyDefaultApplicationJson = GenericObject + +// Issue127ResponseBodyDefaultTextMarkdown defines model for the response body for GET /issues/127 (default, text/markdown). +type Issue127ResponseBodyDefaultTextMarkdown = GenericObject + +// Issue185RequestBody defines model for the request body for GET /issues/185 (application/json). +type Issue185RequestBody = NullableProperties + +// GetIssues375ResponseBody200 defines model for the response body for GET /issues/375 (200, application/json). +type GetIssues375ResponseBody200 = EnumInObjInArray + +// Issue9RequestBody defines model for the request body for GET /issues/9 (application/json). +type Issue9RequestBody = interface{} + // StringInPath defines model for StringInPath. type StringInPath = string diff --git a/internal/test/server/server.gen.go b/internal/test/server/server.gen.go index d43de70d1a..da62d6503e 100644 --- a/internal/test/server/server.gen.go +++ b/internal/test/server/server.gen.go @@ -80,6 +80,51 @@ type SomeObject struct { Name string `json:"name"` } +// GetEveryTypeOptionalResponseBody200 defines model for the response body for GET /every-type-optional (200, application/json). +type GetEveryTypeOptionalResponseBody200 = EveryTypeOptional + +// GetSimpleResponseBody200 defines model for the response body for GET /get-simple (200, application/json). +type GetSimpleResponseBody200 = SomeObject + +// GetWithArgsResponseBody200 defines model for the response body for GET /get-with-args (200, application/json). +type GetWithArgsResponseBody200 SimpleResponse + +// GetWithReferencesResponseBody200 defines model for the response body for GET /get-with-references/{global_argument}/{argument} (200, application/json). +type GetWithReferencesResponseBody200 SimpleResponse + +// GetWithContentTypeResponseBody200ApplicationJson defines model for the response body for GET /get-with-type/{content_type} (200, application/json). +type GetWithContentTypeResponseBody200ApplicationJson = SomeObject + +// GetWithContentTypeResponseBody200TextPlain defines model for the response body for GET /get-with-type/{content_type} (200, text/plain). +type GetWithContentTypeResponseBody200TextPlain = string + +// GetReservedKeywordResponseBody200 defines model for the response body for GET /reserved-keyword (200, application/json). +type GetReservedKeywordResponseBody200 = ReservedKeyword + +// CreateResourceRequestBody defines model for the request body for POST /resource/{argument} (application/json). +type CreateResourceRequestBody = EveryTypeRequired + +// CreateResourceResponseBody200 defines model for the response body for POST /resource/{argument} (200, application/json). +type CreateResourceResponseBody200 SimpleResponse + +// CreateResource2RequestBody defines model for the request body for POST /resource2/{inline_argument} (application/json). +type CreateResource2RequestBody = Resource + +// CreateResource2ResponseBody200 defines model for the response body for POST /resource2/{inline_argument} (200, application/json). +type CreateResource2ResponseBody200 SimpleResponse + +// UpdateResource3RequestBody defines model for the request body for PUT /resource3/{fallthrough} (application/json). +type UpdateResource3RequestBody struct { + Id *int `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} + +// UpdateResource3ResponseBody200 defines model for the response body for PUT /resource3/{fallthrough} (200, application/json). +type UpdateResource3ResponseBody200 SimpleResponse + +// GetResponseWithReferenceResponseBody200 defines model for the response body for GET /response-with-reference (200, application/json). +type GetResponseWithReferenceResponseBody200 ResponseWithReference + // Argument defines model for argument. type Argument = string diff --git a/internal/test/strict-server/chi/types.gen.go b/internal/test/strict-server/chi/types.gen.go index 639d43c248..159ef6333b 100644 --- a/internal/test/strict-server/chi/types.gen.go +++ b/internal/test/strict-server/chi/types.gen.go @@ -12,6 +12,84 @@ type Example struct { Value *string `json:"value,omitempty"` } +// JSONExampleRequestBody defines model for the request body for POST /json (application/json). +type JSONExampleRequestBody = Example + +// JSONExampleResponseBody200 defines model for the response body for POST /json (200, application/json). +type JSONExampleResponseBody200 = Example + +// MultipartExampleRequestBody defines model for the request body for POST /multipart (multipart/form-data). +type MultipartExampleRequestBody = Example + +// MultipartExampleResponseBody200 defines model for the response body for POST /multipart (200, multipart/form-data). +type MultipartExampleResponseBody200 = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationJson defines model for the request body for POST /multiple (application/json). +type MultipleRequestAndResponseTypesRequestBodyApplicationJson = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded defines model for the request body for POST /multiple (application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesRequestBodyImagePng defines model for the request body for POST /multiple (image/png). +type MultipleRequestAndResponseTypesRequestBodyImagePng = []byte + +// MultipleRequestAndResponseTypesRequestBodyMultipartFormData defines model for the request body for POST /multiple (multipart/form-data). +type MultipleRequestAndResponseTypesRequestBodyMultipartFormData = Example + +// MultipleRequestAndResponseTypesRequestBodyTextPlain defines model for the request body for POST /multiple (text/plain). +type MultipleRequestAndResponseTypesRequestBodyTextPlain = string + +// MultipleRequestAndResponseTypesResponseBody200ApplicationJson defines model for the response body for POST /multiple (200, application/json). +type MultipleRequestAndResponseTypesResponseBody200ApplicationJson = Example + +// MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded defines model for the response body for POST /multiple (200, application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesResponseBody200ImagePng defines model for the response body for POST /multiple (200, image/png). +type MultipleRequestAndResponseTypesResponseBody200ImagePng = []byte + +// MultipleRequestAndResponseTypesResponseBody200MultipartFormData defines model for the response body for POST /multiple (200, multipart/form-data). +type MultipleRequestAndResponseTypesResponseBody200MultipartFormData = Example + +// MultipleRequestAndResponseTypesResponseBody200TextPlain defines model for the response body for POST /multiple (200, text/plain). +type MultipleRequestAndResponseTypesResponseBody200TextPlain = string + +// ReusableResponsesRequestBody defines model for the request body for POST /reusable-responses (application/json). +type ReusableResponsesRequestBody = Example + +// ReusableResponsesResponseBody200 defines model for the response body for POST /reusable-responses (200, application/json). +type ReusableResponsesResponseBody200 Reusableresponse + +// TextExampleRequestBody defines model for the request body for POST /text (text/plain). +type TextExampleRequestBody = string + +// TextExampleResponseBody200 defines model for the response body for POST /text (200, text/plain). +type TextExampleResponseBody200 = string + +// UnknownExampleRequestBody defines model for the request body for POST /unknown (image/png). +type UnknownExampleRequestBody = []byte + +// UnknownExampleResponseBody200 defines model for the response body for POST /unknown (200, video/mp4). +type UnknownExampleResponseBody200 = []byte + +// UnspecifiedContentTypeRequestBody defines model for the request body for POST /unspecified-content-type (image/*). +type UnspecifiedContentTypeRequestBody = []byte + +// UnspecifiedContentTypeResponseBody200 defines model for the response body for POST /unspecified-content-type (200, video/*). +type UnspecifiedContentTypeResponseBody200 = []byte + +// URLEncodedExampleRequestBody defines model for the request body for POST /urlencoded (application/x-www-form-urlencoded). +type URLEncodedExampleRequestBody = Example + +// URLEncodedExampleResponseBody200 defines model for the response body for POST /urlencoded (200, application/x-www-form-urlencoded). +type URLEncodedExampleResponseBody200 = Example + +// HeadersExampleRequestBody defines model for the request body for POST /with-headers (application/json). +type HeadersExampleRequestBody = Example + +// HeadersExampleResponseBody200 defines model for the response body for POST /with-headers (200, application/json). +type HeadersExampleResponseBody200 = Example + // Badrequest defines model for badrequest. type Badrequest json.RawMessage diff --git a/internal/test/strict-server/client/client.gen.go b/internal/test/strict-server/client/client.gen.go index 055f4964dc..d49cb93c89 100644 --- a/internal/test/strict-server/client/client.gen.go +++ b/internal/test/strict-server/client/client.gen.go @@ -21,6 +21,84 @@ type Example struct { Value *string `json:"value,omitempty"` } +// JSONExampleRequestBody defines model for the request body for POST /json (application/json). +type JSONExampleRequestBody = Example + +// JSONExampleResponseBody200 defines model for the response body for POST /json (200, application/json). +type JSONExampleResponseBody200 = Example + +// MultipartExampleRequestBody defines model for the request body for POST /multipart (multipart/form-data). +type MultipartExampleRequestBody = Example + +// MultipartExampleResponseBody200 defines model for the response body for POST /multipart (200, multipart/form-data). +type MultipartExampleResponseBody200 = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationJson defines model for the request body for POST /multiple (application/json). +type MultipleRequestAndResponseTypesRequestBodyApplicationJson = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded defines model for the request body for POST /multiple (application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesRequestBodyImagePng defines model for the request body for POST /multiple (image/png). +type MultipleRequestAndResponseTypesRequestBodyImagePng = []byte + +// MultipleRequestAndResponseTypesRequestBodyMultipartFormData defines model for the request body for POST /multiple (multipart/form-data). +type MultipleRequestAndResponseTypesRequestBodyMultipartFormData = Example + +// MultipleRequestAndResponseTypesRequestBodyTextPlain defines model for the request body for POST /multiple (text/plain). +type MultipleRequestAndResponseTypesRequestBodyTextPlain = string + +// MultipleRequestAndResponseTypesResponseBody200ApplicationJson defines model for the response body for POST /multiple (200, application/json). +type MultipleRequestAndResponseTypesResponseBody200ApplicationJson = Example + +// MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded defines model for the response body for POST /multiple (200, application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesResponseBody200ImagePng defines model for the response body for POST /multiple (200, image/png). +type MultipleRequestAndResponseTypesResponseBody200ImagePng = []byte + +// MultipleRequestAndResponseTypesResponseBody200MultipartFormData defines model for the response body for POST /multiple (200, multipart/form-data). +type MultipleRequestAndResponseTypesResponseBody200MultipartFormData = Example + +// MultipleRequestAndResponseTypesResponseBody200TextPlain defines model for the response body for POST /multiple (200, text/plain). +type MultipleRequestAndResponseTypesResponseBody200TextPlain = string + +// ReusableResponsesRequestBody defines model for the request body for POST /reusable-responses (application/json). +type ReusableResponsesRequestBody = Example + +// ReusableResponsesResponseBody200 defines model for the response body for POST /reusable-responses (200, application/json). +type ReusableResponsesResponseBody200 Reusableresponse + +// TextExampleRequestBody defines model for the request body for POST /text (text/plain). +type TextExampleRequestBody = string + +// TextExampleResponseBody200 defines model for the response body for POST /text (200, text/plain). +type TextExampleResponseBody200 = string + +// UnknownExampleRequestBody defines model for the request body for POST /unknown (image/png). +type UnknownExampleRequestBody = []byte + +// UnknownExampleResponseBody200 defines model for the response body for POST /unknown (200, video/mp4). +type UnknownExampleResponseBody200 = []byte + +// UnspecifiedContentTypeRequestBody defines model for the request body for POST /unspecified-content-type (image/*). +type UnspecifiedContentTypeRequestBody = []byte + +// UnspecifiedContentTypeResponseBody200 defines model for the response body for POST /unspecified-content-type (200, video/*). +type UnspecifiedContentTypeResponseBody200 = []byte + +// URLEncodedExampleRequestBody defines model for the request body for POST /urlencoded (application/x-www-form-urlencoded). +type URLEncodedExampleRequestBody = Example + +// URLEncodedExampleResponseBody200 defines model for the response body for POST /urlencoded (200, application/x-www-form-urlencoded). +type URLEncodedExampleResponseBody200 = Example + +// HeadersExampleRequestBody defines model for the request body for POST /with-headers (application/json). +type HeadersExampleRequestBody = Example + +// HeadersExampleResponseBody200 defines model for the response body for POST /with-headers (200, application/json). +type HeadersExampleResponseBody200 = Example + // Badrequest defines model for badrequest. type Badrequest json.RawMessage diff --git a/internal/test/strict-server/echo/types.gen.go b/internal/test/strict-server/echo/types.gen.go index 639d43c248..159ef6333b 100644 --- a/internal/test/strict-server/echo/types.gen.go +++ b/internal/test/strict-server/echo/types.gen.go @@ -12,6 +12,84 @@ type Example struct { Value *string `json:"value,omitempty"` } +// JSONExampleRequestBody defines model for the request body for POST /json (application/json). +type JSONExampleRequestBody = Example + +// JSONExampleResponseBody200 defines model for the response body for POST /json (200, application/json). +type JSONExampleResponseBody200 = Example + +// MultipartExampleRequestBody defines model for the request body for POST /multipart (multipart/form-data). +type MultipartExampleRequestBody = Example + +// MultipartExampleResponseBody200 defines model for the response body for POST /multipart (200, multipart/form-data). +type MultipartExampleResponseBody200 = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationJson defines model for the request body for POST /multiple (application/json). +type MultipleRequestAndResponseTypesRequestBodyApplicationJson = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded defines model for the request body for POST /multiple (application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesRequestBodyImagePng defines model for the request body for POST /multiple (image/png). +type MultipleRequestAndResponseTypesRequestBodyImagePng = []byte + +// MultipleRequestAndResponseTypesRequestBodyMultipartFormData defines model for the request body for POST /multiple (multipart/form-data). +type MultipleRequestAndResponseTypesRequestBodyMultipartFormData = Example + +// MultipleRequestAndResponseTypesRequestBodyTextPlain defines model for the request body for POST /multiple (text/plain). +type MultipleRequestAndResponseTypesRequestBodyTextPlain = string + +// MultipleRequestAndResponseTypesResponseBody200ApplicationJson defines model for the response body for POST /multiple (200, application/json). +type MultipleRequestAndResponseTypesResponseBody200ApplicationJson = Example + +// MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded defines model for the response body for POST /multiple (200, application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesResponseBody200ImagePng defines model for the response body for POST /multiple (200, image/png). +type MultipleRequestAndResponseTypesResponseBody200ImagePng = []byte + +// MultipleRequestAndResponseTypesResponseBody200MultipartFormData defines model for the response body for POST /multiple (200, multipart/form-data). +type MultipleRequestAndResponseTypesResponseBody200MultipartFormData = Example + +// MultipleRequestAndResponseTypesResponseBody200TextPlain defines model for the response body for POST /multiple (200, text/plain). +type MultipleRequestAndResponseTypesResponseBody200TextPlain = string + +// ReusableResponsesRequestBody defines model for the request body for POST /reusable-responses (application/json). +type ReusableResponsesRequestBody = Example + +// ReusableResponsesResponseBody200 defines model for the response body for POST /reusable-responses (200, application/json). +type ReusableResponsesResponseBody200 Reusableresponse + +// TextExampleRequestBody defines model for the request body for POST /text (text/plain). +type TextExampleRequestBody = string + +// TextExampleResponseBody200 defines model for the response body for POST /text (200, text/plain). +type TextExampleResponseBody200 = string + +// UnknownExampleRequestBody defines model for the request body for POST /unknown (image/png). +type UnknownExampleRequestBody = []byte + +// UnknownExampleResponseBody200 defines model for the response body for POST /unknown (200, video/mp4). +type UnknownExampleResponseBody200 = []byte + +// UnspecifiedContentTypeRequestBody defines model for the request body for POST /unspecified-content-type (image/*). +type UnspecifiedContentTypeRequestBody = []byte + +// UnspecifiedContentTypeResponseBody200 defines model for the response body for POST /unspecified-content-type (200, video/*). +type UnspecifiedContentTypeResponseBody200 = []byte + +// URLEncodedExampleRequestBody defines model for the request body for POST /urlencoded (application/x-www-form-urlencoded). +type URLEncodedExampleRequestBody = Example + +// URLEncodedExampleResponseBody200 defines model for the response body for POST /urlencoded (200, application/x-www-form-urlencoded). +type URLEncodedExampleResponseBody200 = Example + +// HeadersExampleRequestBody defines model for the request body for POST /with-headers (application/json). +type HeadersExampleRequestBody = Example + +// HeadersExampleResponseBody200 defines model for the response body for POST /with-headers (200, application/json). +type HeadersExampleResponseBody200 = Example + // Badrequest defines model for badrequest. type Badrequest json.RawMessage diff --git a/internal/test/strict-server/gin/types.gen.go b/internal/test/strict-server/gin/types.gen.go index 639d43c248..159ef6333b 100644 --- a/internal/test/strict-server/gin/types.gen.go +++ b/internal/test/strict-server/gin/types.gen.go @@ -12,6 +12,84 @@ type Example struct { Value *string `json:"value,omitempty"` } +// JSONExampleRequestBody defines model for the request body for POST /json (application/json). +type JSONExampleRequestBody = Example + +// JSONExampleResponseBody200 defines model for the response body for POST /json (200, application/json). +type JSONExampleResponseBody200 = Example + +// MultipartExampleRequestBody defines model for the request body for POST /multipart (multipart/form-data). +type MultipartExampleRequestBody = Example + +// MultipartExampleResponseBody200 defines model for the response body for POST /multipart (200, multipart/form-data). +type MultipartExampleResponseBody200 = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationJson defines model for the request body for POST /multiple (application/json). +type MultipleRequestAndResponseTypesRequestBodyApplicationJson = Example + +// MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded defines model for the request body for POST /multiple (application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesRequestBodyApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesRequestBodyImagePng defines model for the request body for POST /multiple (image/png). +type MultipleRequestAndResponseTypesRequestBodyImagePng = []byte + +// MultipleRequestAndResponseTypesRequestBodyMultipartFormData defines model for the request body for POST /multiple (multipart/form-data). +type MultipleRequestAndResponseTypesRequestBodyMultipartFormData = Example + +// MultipleRequestAndResponseTypesRequestBodyTextPlain defines model for the request body for POST /multiple (text/plain). +type MultipleRequestAndResponseTypesRequestBodyTextPlain = string + +// MultipleRequestAndResponseTypesResponseBody200ApplicationJson defines model for the response body for POST /multiple (200, application/json). +type MultipleRequestAndResponseTypesResponseBody200ApplicationJson = Example + +// MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded defines model for the response body for POST /multiple (200, application/x-www-form-urlencoded). +type MultipleRequestAndResponseTypesResponseBody200ApplicationXWwwFormUrlencoded = Example + +// MultipleRequestAndResponseTypesResponseBody200ImagePng defines model for the response body for POST /multiple (200, image/png). +type MultipleRequestAndResponseTypesResponseBody200ImagePng = []byte + +// MultipleRequestAndResponseTypesResponseBody200MultipartFormData defines model for the response body for POST /multiple (200, multipart/form-data). +type MultipleRequestAndResponseTypesResponseBody200MultipartFormData = Example + +// MultipleRequestAndResponseTypesResponseBody200TextPlain defines model for the response body for POST /multiple (200, text/plain). +type MultipleRequestAndResponseTypesResponseBody200TextPlain = string + +// ReusableResponsesRequestBody defines model for the request body for POST /reusable-responses (application/json). +type ReusableResponsesRequestBody = Example + +// ReusableResponsesResponseBody200 defines model for the response body for POST /reusable-responses (200, application/json). +type ReusableResponsesResponseBody200 Reusableresponse + +// TextExampleRequestBody defines model for the request body for POST /text (text/plain). +type TextExampleRequestBody = string + +// TextExampleResponseBody200 defines model for the response body for POST /text (200, text/plain). +type TextExampleResponseBody200 = string + +// UnknownExampleRequestBody defines model for the request body for POST /unknown (image/png). +type UnknownExampleRequestBody = []byte + +// UnknownExampleResponseBody200 defines model for the response body for POST /unknown (200, video/mp4). +type UnknownExampleResponseBody200 = []byte + +// UnspecifiedContentTypeRequestBody defines model for the request body for POST /unspecified-content-type (image/*). +type UnspecifiedContentTypeRequestBody = []byte + +// UnspecifiedContentTypeResponseBody200 defines model for the response body for POST /unspecified-content-type (200, video/*). +type UnspecifiedContentTypeResponseBody200 = []byte + +// URLEncodedExampleRequestBody defines model for the request body for POST /urlencoded (application/x-www-form-urlencoded). +type URLEncodedExampleRequestBody = Example + +// URLEncodedExampleResponseBody200 defines model for the response body for POST /urlencoded (200, application/x-www-form-urlencoded). +type URLEncodedExampleResponseBody200 = Example + +// HeadersExampleRequestBody defines model for the request body for POST /with-headers (application/json). +type HeadersExampleRequestBody = Example + +// HeadersExampleResponseBody200 defines model for the response body for POST /with-headers (200, application/json). +type HeadersExampleResponseBody200 = Example + // Badrequest defines model for badrequest. type Badrequest json.RawMessage