forked from loafle/openapi-generator-original
[BUG][Go-server] attempt to fix the controller-api mustache template for a nullable bodyParam (#20478)
* go-server: attempt to fix the controller-api mustache template for a nullable bodyParam * added to petstore an example to trigger the issue which this PR fixes
This commit is contained in:
parent
cd7cdb1e24
commit
c2884b7b1a
@ -624,7 +624,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
|
|||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{/isBodyParam}}
|
{{/isBodyParam}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
result, err := c.service.{{nickname}}(r.Context(){{#allParams}}, {{paramName}}Param{{/allParams}})
|
result, err := c.service.{{nickname}}(r.Context(){{#allParams}}, {{#isNullable}}{{#isBodyParam}}&{{/isBodyParam}}{{/isNullable}}{{paramName}}Param{{/allParams}})
|
||||||
// If an error occurred, encode the error with the status code
|
// If an error occurred, encode the error with the status code
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorHandler(w, r, err, &result)
|
c.errorHandler(w, r, err, &result)
|
||||||
|
@ -582,6 +582,24 @@ paths:
|
|||||||
$ref: '#/components/schemas/User'
|
$ref: '#/components/schemas/User'
|
||||||
description: Created user object
|
description: Created user object
|
||||||
required: true
|
required: true
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Create user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: createUserNullable
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/UserNullable'
|
||||||
|
description: Created user object, with a nullable bodyParam
|
||||||
|
required: true
|
||||||
/user/createWithArray:
|
/user/createWithArray:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
@ -1052,6 +1070,66 @@ components:
|
|||||||
name: User
|
name: User
|
||||||
required:
|
required:
|
||||||
- deepSliceModel
|
- deepSliceModel
|
||||||
|
UserNullable:
|
||||||
|
title: a User
|
||||||
|
description: A User who is purchasing from the pet store
|
||||||
|
type: object
|
||||||
|
nullable: true
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
phone:
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
userStatus:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
description: User Status
|
||||||
|
deepSliceModel:
|
||||||
|
nullable: true
|
||||||
|
type: array
|
||||||
|
description: An array 1-deep.
|
||||||
|
items:
|
||||||
|
type: array
|
||||||
|
description: An array 2-deep.
|
||||||
|
items:
|
||||||
|
type: array
|
||||||
|
description: An array 3-deep.
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Tag'
|
||||||
|
deepSliceMap:
|
||||||
|
type: array
|
||||||
|
description: An array 1-deep.
|
||||||
|
items:
|
||||||
|
type: array
|
||||||
|
description: An array 2-deep.
|
||||||
|
items:
|
||||||
|
title: an Object
|
||||||
|
type: object
|
||||||
|
description: An array 3-deep.
|
||||||
|
properties:
|
||||||
|
tag:
|
||||||
|
$ref: '#/components/schemas/Tag'
|
||||||
|
Pet:
|
||||||
|
type: array
|
||||||
|
description: An array of pet.
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
xml:
|
||||||
|
name: User
|
||||||
|
required:
|
||||||
|
- deepSliceModel
|
||||||
Tag:
|
Tag:
|
||||||
title: Pet Tag
|
title: Pet Tag
|
||||||
description: A tag for a pet
|
description: A tag for a pet
|
||||||
|
@ -27,5 +27,6 @@ go/model_special_info.go
|
|||||||
go/model_species.go
|
go/model_species.go
|
||||||
go/model_tag.go
|
go/model_tag.go
|
||||||
go/model_user.go
|
go/model_user.go
|
||||||
|
go/model_user_nullable.go
|
||||||
go/routers.go
|
go/routers.go
|
||||||
main.go
|
main.go
|
||||||
|
@ -605,6 +605,24 @@ paths:
|
|||||||
summary: Create user
|
summary: Create user
|
||||||
tags:
|
tags:
|
||||||
- user
|
- user
|
||||||
|
put:
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: createUserNullable
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/UserNullable'
|
||||||
|
description: "Created user object, with a nullable bodyParam"
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
summary: Create user
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
/user/createWithArray:
|
/user/createWithArray:
|
||||||
post:
|
post:
|
||||||
description: ""
|
description: ""
|
||||||
@ -1240,6 +1258,211 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
xml:
|
xml:
|
||||||
name: User
|
name: User
|
||||||
|
UserNullable:
|
||||||
|
description: A User who is purchasing from the pet store
|
||||||
|
example:
|
||||||
|
firstName: firstName
|
||||||
|
lastName: lastName
|
||||||
|
password: password
|
||||||
|
userStatus: 6
|
||||||
|
phone: phone
|
||||||
|
deepSliceModel:
|
||||||
|
- - - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- - - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
id: 0
|
||||||
|
deepSliceMap:
|
||||||
|
- - tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- - tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
email: email
|
||||||
|
username: username
|
||||||
|
nullable: true
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
format: int64
|
||||||
|
type: integer
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
phone:
|
||||||
|
nullable: true
|
||||||
|
type: string
|
||||||
|
userStatus:
|
||||||
|
description: User Status
|
||||||
|
format: int32
|
||||||
|
type: integer
|
||||||
|
deepSliceModel:
|
||||||
|
description: An array 1-deep.
|
||||||
|
items:
|
||||||
|
description: An array 2-deep.
|
||||||
|
items:
|
||||||
|
description: An array 3-deep.
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Tag'
|
||||||
|
type: array
|
||||||
|
type: array
|
||||||
|
nullable: true
|
||||||
|
type: array
|
||||||
|
deepSliceMap:
|
||||||
|
description: An array 1-deep.
|
||||||
|
items:
|
||||||
|
description: An array 2-deep.
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/an_Object'
|
||||||
|
type: array
|
||||||
|
type: array
|
||||||
|
required:
|
||||||
|
- deepSliceModel
|
||||||
|
title: a User
|
||||||
|
type: object
|
||||||
|
xml:
|
||||||
|
name: User
|
||||||
Tag:
|
Tag:
|
||||||
description: A tag for a pet
|
description: A tag for a pet
|
||||||
example:
|
example:
|
||||||
|
@ -58,6 +58,7 @@ type StoreAPIRouter interface {
|
|||||||
// The UserAPIRouter implementation should parse necessary information from the http request,
|
// The UserAPIRouter implementation should parse necessary information from the http request,
|
||||||
// pass the data to a UserAPIServicer to perform the required actions, then write the service results to the http response.
|
// pass the data to a UserAPIServicer to perform the required actions, then write the service results to the http response.
|
||||||
type UserAPIRouter interface {
|
type UserAPIRouter interface {
|
||||||
|
CreateUserNullable(http.ResponseWriter, *http.Request)
|
||||||
CreateUser(http.ResponseWriter, *http.Request)
|
CreateUser(http.ResponseWriter, *http.Request)
|
||||||
CreateUsersWithArrayInput(http.ResponseWriter, *http.Request)
|
CreateUsersWithArrayInput(http.ResponseWriter, *http.Request)
|
||||||
CreateUsersWithListInput(http.ResponseWriter, *http.Request)
|
CreateUsersWithListInput(http.ResponseWriter, *http.Request)
|
||||||
@ -118,6 +119,7 @@ type StoreAPIServicer interface {
|
|||||||
// while the service implementation can be ignored with the .openapi-generator-ignore file
|
// while the service implementation can be ignored with the .openapi-generator-ignore file
|
||||||
// and updated with the logic required for the API.
|
// and updated with the logic required for the API.
|
||||||
type UserAPIServicer interface {
|
type UserAPIServicer interface {
|
||||||
|
CreateUserNullable(context.Context, *UserNullable) (ImplResponse, error)
|
||||||
CreateUser(context.Context, User) (ImplResponse, error)
|
CreateUser(context.Context, User) (ImplResponse, error)
|
||||||
CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error)
|
CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error)
|
||||||
CreateUsersWithListInput(context.Context, []User) (ImplResponse, error)
|
CreateUsersWithListInput(context.Context, []User) (ImplResponse, error)
|
||||||
|
@ -51,6 +51,11 @@ func NewUserAPIController(s UserAPIServicer, opts ...UserAPIOption) *UserAPICont
|
|||||||
// Routes returns all the api routes for the UserAPIController
|
// Routes returns all the api routes for the UserAPIController
|
||||||
func (c *UserAPIController) Routes() Routes {
|
func (c *UserAPIController) Routes() Routes {
|
||||||
return Routes{
|
return Routes{
|
||||||
|
"CreateUserNullable": Route{
|
||||||
|
strings.ToUpper("Put"),
|
||||||
|
"/v2/user",
|
||||||
|
c.CreateUserNullable,
|
||||||
|
},
|
||||||
"CreateUser": Route{
|
"CreateUser": Route{
|
||||||
strings.ToUpper("Post"),
|
strings.ToUpper("Post"),
|
||||||
"/v2/user",
|
"/v2/user",
|
||||||
@ -94,6 +99,33 @@ func (c *UserAPIController) Routes() Routes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateUserNullable - Create user
|
||||||
|
func (c *UserAPIController) CreateUserNullable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var userNullableParam UserNullable
|
||||||
|
d := json.NewDecoder(r.Body)
|
||||||
|
d.DisallowUnknownFields()
|
||||||
|
if err := d.Decode(&userNullableParam); err != nil {
|
||||||
|
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := AssertUserNullableRequired(userNullableParam); err != nil {
|
||||||
|
c.errorHandler(w, r, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := AssertUserNullableConstraints(userNullableParam); err != nil {
|
||||||
|
c.errorHandler(w, r, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err := c.service.CreateUserNullable(r.Context(), &userNullableParam)
|
||||||
|
// If an error occurred, encode the error with the status code
|
||||||
|
if err != nil {
|
||||||
|
c.errorHandler(w, r, err, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// If no error, encode the body and the result code
|
||||||
|
_ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUser - Create user
|
// CreateUser - Create user
|
||||||
func (c *UserAPIController) CreateUser(w http.ResponseWriter, r *http.Request) {
|
func (c *UserAPIController) CreateUser(w http.ResponseWriter, r *http.Request) {
|
||||||
var userParam User
|
var userParam User
|
||||||
|
@ -27,6 +27,17 @@ func NewUserAPIService() *UserAPIService {
|
|||||||
return &UserAPIService{}
|
return &UserAPIService{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateUserNullable - Create user
|
||||||
|
func (s *UserAPIService) CreateUserNullable(ctx context.Context, userNullable *UserNullable) (ImplResponse, error) {
|
||||||
|
// TODO - update CreateUserNullable with the required logic for this service method.
|
||||||
|
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||||
|
|
||||||
|
// TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
|
||||||
|
// return Response(0, nil),nil
|
||||||
|
|
||||||
|
return Response(http.StatusNotImplemented, nil), errors.New("CreateUserNullable method not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUser - Create user
|
// CreateUser - Create user
|
||||||
func (s *UserAPIService) CreateUser(ctx context.Context, user User) (ImplResponse, error) {
|
func (s *UserAPIService) CreateUser(ctx context.Context, user User) (ImplResponse, error) {
|
||||||
// TODO - update CreateUser with the required logic for this service method.
|
// TODO - update CreateUser with the required logic for this service method.
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OpenAPI Petstore
|
||||||
|
*
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* API version: 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package petstoreserver
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// UserNullable - A User who is purchasing from the pet store
|
||||||
|
type UserNullable struct {
|
||||||
|
|
||||||
|
Id int64 `json:"id,omitempty"`
|
||||||
|
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
|
||||||
|
FirstName string `json:"firstName,omitempty"`
|
||||||
|
|
||||||
|
LastName string `json:"lastName,omitempty"`
|
||||||
|
|
||||||
|
Email string `json:"email,omitempty"`
|
||||||
|
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
|
|
||||||
|
Phone *string `json:"phone,omitempty"`
|
||||||
|
|
||||||
|
// User Status
|
||||||
|
UserStatus int32 `json:"userStatus,omitempty"`
|
||||||
|
|
||||||
|
// An array 1-deep.
|
||||||
|
DeepSliceModel *[][][]Tag `json:"deepSliceModel"`
|
||||||
|
|
||||||
|
// An array 1-deep.
|
||||||
|
DeepSliceMap [][]AnObject `json:"deepSliceMap,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertUserNullableRequired checks if the required fields are not zero-ed
|
||||||
|
func AssertUserNullableRequired(obj UserNullable) error {
|
||||||
|
elements := map[string]interface{}{
|
||||||
|
"deepSliceModel": obj.DeepSliceModel,
|
||||||
|
}
|
||||||
|
for name, el := range elements {
|
||||||
|
if isZero := IsZeroValue(el); isZero {
|
||||||
|
return &RequiredError{Field: name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.DeepSliceModel != nil {
|
||||||
|
if err := AssertRecurseInterfaceRequired(*obj.DeepSliceModel, AssertTagRequired); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := AssertRecurseInterfaceRequired(obj.DeepSliceMap, AssertAnObjectRequired); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertUserNullableConstraints checks if the values respects the defined constraints
|
||||||
|
func AssertUserNullableConstraints(obj UserNullable) error {
|
||||||
|
if obj.DeepSliceModel != nil {
|
||||||
|
if err := AssertRecurseInterfaceRequired(*obj.DeepSliceModel, AssertTagConstraints); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := AssertRecurseInterfaceRequired(obj.DeepSliceMap, AssertAnObjectConstraints); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -27,5 +27,6 @@ go/model_special_info.go
|
|||||||
go/model_species.go
|
go/model_species.go
|
||||||
go/model_tag.go
|
go/model_tag.go
|
||||||
go/model_user.go
|
go/model_user.go
|
||||||
|
go/model_user_nullable.go
|
||||||
go/routers.go
|
go/routers.go
|
||||||
main.go
|
main.go
|
||||||
|
@ -605,6 +605,24 @@ paths:
|
|||||||
summary: Create user
|
summary: Create user
|
||||||
tags:
|
tags:
|
||||||
- user
|
- user
|
||||||
|
put:
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: createUserNullable
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/UserNullable'
|
||||||
|
description: "Created user object, with a nullable bodyParam"
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
summary: Create user
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
/user/createWithArray:
|
/user/createWithArray:
|
||||||
post:
|
post:
|
||||||
description: ""
|
description: ""
|
||||||
@ -1240,6 +1258,211 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
xml:
|
xml:
|
||||||
name: User
|
name: User
|
||||||
|
UserNullable:
|
||||||
|
description: A User who is purchasing from the pet store
|
||||||
|
example:
|
||||||
|
firstName: firstName
|
||||||
|
lastName: lastName
|
||||||
|
password: password
|
||||||
|
userStatus: 6
|
||||||
|
phone: phone
|
||||||
|
deepSliceModel:
|
||||||
|
- - - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- - - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- - name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
id: 0
|
||||||
|
deepSliceMap:
|
||||||
|
- - tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- - tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- tag:
|
||||||
|
name: name
|
||||||
|
id: 1
|
||||||
|
Pet:
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
- photoUrls:
|
||||||
|
- photoUrls
|
||||||
|
- photoUrls
|
||||||
|
name: doggie
|
||||||
|
id: 0
|
||||||
|
category:
|
||||||
|
name: name
|
||||||
|
id: 6
|
||||||
|
tags:
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
- name: name
|
||||||
|
id: 1
|
||||||
|
status: available
|
||||||
|
email: email
|
||||||
|
username: username
|
||||||
|
nullable: true
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
format: int64
|
||||||
|
type: integer
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
phone:
|
||||||
|
nullable: true
|
||||||
|
type: string
|
||||||
|
userStatus:
|
||||||
|
description: User Status
|
||||||
|
format: int32
|
||||||
|
type: integer
|
||||||
|
deepSliceModel:
|
||||||
|
description: An array 1-deep.
|
||||||
|
items:
|
||||||
|
description: An array 2-deep.
|
||||||
|
items:
|
||||||
|
description: An array 3-deep.
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Tag'
|
||||||
|
type: array
|
||||||
|
type: array
|
||||||
|
nullable: true
|
||||||
|
type: array
|
||||||
|
deepSliceMap:
|
||||||
|
description: An array 1-deep.
|
||||||
|
items:
|
||||||
|
description: An array 2-deep.
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/an_Object'
|
||||||
|
type: array
|
||||||
|
type: array
|
||||||
|
required:
|
||||||
|
- deepSliceModel
|
||||||
|
title: a User
|
||||||
|
type: object
|
||||||
|
xml:
|
||||||
|
name: User
|
||||||
Tag:
|
Tag:
|
||||||
description: A tag for a pet
|
description: A tag for a pet
|
||||||
example:
|
example:
|
||||||
|
@ -58,6 +58,7 @@ type StoreAPIRouter interface {
|
|||||||
// The UserAPIRouter implementation should parse necessary information from the http request,
|
// The UserAPIRouter implementation should parse necessary information from the http request,
|
||||||
// pass the data to a UserAPIServicer to perform the required actions, then write the service results to the http response.
|
// pass the data to a UserAPIServicer to perform the required actions, then write the service results to the http response.
|
||||||
type UserAPIRouter interface {
|
type UserAPIRouter interface {
|
||||||
|
CreateUserNullable(http.ResponseWriter, *http.Request)
|
||||||
CreateUser(http.ResponseWriter, *http.Request)
|
CreateUser(http.ResponseWriter, *http.Request)
|
||||||
CreateUsersWithArrayInput(http.ResponseWriter, *http.Request)
|
CreateUsersWithArrayInput(http.ResponseWriter, *http.Request)
|
||||||
CreateUsersWithListInput(http.ResponseWriter, *http.Request)
|
CreateUsersWithListInput(http.ResponseWriter, *http.Request)
|
||||||
@ -118,6 +119,7 @@ type StoreAPIServicer interface {
|
|||||||
// while the service implementation can be ignored with the .openapi-generator-ignore file
|
// while the service implementation can be ignored with the .openapi-generator-ignore file
|
||||||
// and updated with the logic required for the API.
|
// and updated with the logic required for the API.
|
||||||
type UserAPIServicer interface {
|
type UserAPIServicer interface {
|
||||||
|
CreateUserNullable(context.Context, *UserNullable) (ImplResponse, error)
|
||||||
CreateUser(context.Context, User) (ImplResponse, error)
|
CreateUser(context.Context, User) (ImplResponse, error)
|
||||||
CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error)
|
CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error)
|
||||||
CreateUsersWithListInput(context.Context, []User) (ImplResponse, error)
|
CreateUsersWithListInput(context.Context, []User) (ImplResponse, error)
|
||||||
|
@ -51,6 +51,11 @@ func NewUserAPIController(s UserAPIServicer, opts ...UserAPIOption) *UserAPICont
|
|||||||
// Routes returns all the api routes for the UserAPIController
|
// Routes returns all the api routes for the UserAPIController
|
||||||
func (c *UserAPIController) Routes() Routes {
|
func (c *UserAPIController) Routes() Routes {
|
||||||
return Routes{
|
return Routes{
|
||||||
|
"CreateUserNullable": Route{
|
||||||
|
strings.ToUpper("Put"),
|
||||||
|
"/v2/user",
|
||||||
|
c.CreateUserNullable,
|
||||||
|
},
|
||||||
"CreateUser": Route{
|
"CreateUser": Route{
|
||||||
strings.ToUpper("Post"),
|
strings.ToUpper("Post"),
|
||||||
"/v2/user",
|
"/v2/user",
|
||||||
@ -94,6 +99,33 @@ func (c *UserAPIController) Routes() Routes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateUserNullable - Create user
|
||||||
|
func (c *UserAPIController) CreateUserNullable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var userNullableParam UserNullable
|
||||||
|
d := json.NewDecoder(r.Body)
|
||||||
|
d.DisallowUnknownFields()
|
||||||
|
if err := d.Decode(&userNullableParam); err != nil {
|
||||||
|
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := AssertUserNullableRequired(userNullableParam); err != nil {
|
||||||
|
c.errorHandler(w, r, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := AssertUserNullableConstraints(userNullableParam); err != nil {
|
||||||
|
c.errorHandler(w, r, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err := c.service.CreateUserNullable(r.Context(), &userNullableParam)
|
||||||
|
// If an error occurred, encode the error with the status code
|
||||||
|
if err != nil {
|
||||||
|
c.errorHandler(w, r, err, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// If no error, encode the body and the result code
|
||||||
|
_ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUser - Create user
|
// CreateUser - Create user
|
||||||
func (c *UserAPIController) CreateUser(w http.ResponseWriter, r *http.Request) {
|
func (c *UserAPIController) CreateUser(w http.ResponseWriter, r *http.Request) {
|
||||||
var userParam User
|
var userParam User
|
||||||
|
@ -27,6 +27,17 @@ func NewUserAPIService() *UserAPIService {
|
|||||||
return &UserAPIService{}
|
return &UserAPIService{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateUserNullable - Create user
|
||||||
|
func (s *UserAPIService) CreateUserNullable(ctx context.Context, userNullable *UserNullable) (ImplResponse, error) {
|
||||||
|
// TODO - update CreateUserNullable with the required logic for this service method.
|
||||||
|
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||||
|
|
||||||
|
// TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
|
||||||
|
// return Response(0, nil),nil
|
||||||
|
|
||||||
|
return Response(http.StatusNotImplemented, nil), errors.New("CreateUserNullable method not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUser - Create user
|
// CreateUser - Create user
|
||||||
func (s *UserAPIService) CreateUser(ctx context.Context, user User) (ImplResponse, error) {
|
func (s *UserAPIService) CreateUser(ctx context.Context, user User) (ImplResponse, error) {
|
||||||
// TODO - update CreateUser with the required logic for this service method.
|
// TODO - update CreateUser with the required logic for this service method.
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OpenAPI Petstore
|
||||||
|
*
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* API version: 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package petstoreserver
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// UserNullable - A User who is purchasing from the pet store
|
||||||
|
type UserNullable struct {
|
||||||
|
|
||||||
|
Id int64 `json:"id,omitempty"`
|
||||||
|
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
|
||||||
|
FirstName string `json:"firstName,omitempty"`
|
||||||
|
|
||||||
|
LastName string `json:"lastName,omitempty"`
|
||||||
|
|
||||||
|
Email string `json:"email,omitempty"`
|
||||||
|
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
|
|
||||||
|
Phone *string `json:"phone,omitempty"`
|
||||||
|
|
||||||
|
// User Status
|
||||||
|
UserStatus int32 `json:"userStatus,omitempty"`
|
||||||
|
|
||||||
|
// An array 1-deep.
|
||||||
|
DeepSliceModel *[][][]Tag `json:"deepSliceModel"`
|
||||||
|
|
||||||
|
// An array 1-deep.
|
||||||
|
DeepSliceMap [][]AnObject `json:"deepSliceMap,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertUserNullableRequired checks if the required fields are not zero-ed
|
||||||
|
func AssertUserNullableRequired(obj UserNullable) error {
|
||||||
|
elements := map[string]interface{}{
|
||||||
|
"deepSliceModel": obj.DeepSliceModel,
|
||||||
|
}
|
||||||
|
for name, el := range elements {
|
||||||
|
if isZero := IsZeroValue(el); isZero {
|
||||||
|
return &RequiredError{Field: name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.DeepSliceModel != nil {
|
||||||
|
if err := AssertRecurseInterfaceRequired(*obj.DeepSliceModel, AssertTagRequired); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := AssertRecurseInterfaceRequired(obj.DeepSliceMap, AssertAnObjectRequired); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertUserNullableConstraints checks if the values respects the defined constraints
|
||||||
|
func AssertUserNullableConstraints(obj UserNullable) error {
|
||||||
|
if obj.DeepSliceModel != nil {
|
||||||
|
if err := AssertRecurseInterfaceRequired(*obj.DeepSliceModel, AssertTagConstraints); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := AssertRecurseInterfaceRequired(obj.DeepSliceMap, AssertAnObjectConstraints); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user