Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/petstore-expanded/chi/api/petstore.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/petstore-expanded/chi/api/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *PetStore) FindPets(w http.ResponseWriter, r *http.Request, params FindP
for _, pet := range p.Pets {
if params.Tags != nil {
// If we have tags, filter pets by tag
for _, t := range *params.Tags {
for _, t := range params.Tags {
if pet.Tag != nil && (*pet.Tag == t) {
result = append(result, pet)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/petstore-expanded/echo/api/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *PetStore) FindPets(ctx echo.Context, params FindPetsParams) error {
for _, pet := range p.Pets {
if params.Tags != nil {
// If we have tags, filter pets by tag
for _, t := range *params.Tags {
for _, t := range params.Tags {
if pet.Tag != nil && (*pet.Tag == t) {
result = append(result, pet)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/petstore-expanded/petstore-client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions internal/test/parameters/parameters.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions internal/test/parameters/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func (t *testServer) GetSimplePrimitive(ctx echo.Context, param int32) error {
func (t *testServer) GetQueryForm(ctx echo.Context, params GetQueryFormParams) error {
t.queryParams = &params
if params.Ea != nil {
t.array = *params.Ea
t.array = params.Ea
}
if params.A != nil {
t.array = *params.A
t.array = params.A
}
if params.Eo != nil {
t.object = params.Eo
Expand Down Expand Up @@ -186,10 +186,10 @@ func (t *testServer) GetHeader(ctx echo.Context, params GetHeaderParams) error {
t.primitive = params.XPrimitiveExploded
}
if params.XArray != nil {
t.array = *params.XArray
t.array = params.XArray
}
if params.XArrayExploded != nil {
t.array = *params.XArrayExploded
t.array = params.XArrayExploded
}
if params.XObject != nil {
t.object = params.XObject
Expand All @@ -210,10 +210,10 @@ func (t *testServer) GetHeader(ctx echo.Context, params GetHeaderParams) error {
func (t *testServer) GetCookie(ctx echo.Context, params GetCookieParams) error {
t.cookieParams = &params
if params.Ea != nil {
t.array = *params.Ea
t.array = params.Ea
}
if params.A != nil {
t.array = *params.A
t.array = params.A
}
if params.Eo != nil {
t.object = params.Eo
Expand Down Expand Up @@ -677,8 +677,8 @@ func TestClientQueryParams(t *testing.T) {

// Check query params
qParams := GetQueryFormParams{
Ea: &expectedArray1,
A: &expectedArray2,
Ea: expectedArray1,
A: expectedArray2,
Eo: &expectedObject1,
O: &expectedObject2,
Ep: &expectedPrimitive1,
Expand All @@ -697,8 +697,8 @@ func TestClientQueryParams(t *testing.T) {

// Check cookie params
cParams := GetCookieParams{
Ea: &expectedArray1,
A: &expectedArray2,
Ea: expectedArray1,
A: expectedArray2,
Eo: &expectedObject1,
O: &expectedObject2,
Ep: &expectedPrimitive1,
Expand All @@ -715,8 +715,8 @@ func TestClientQueryParams(t *testing.T) {

// Check Header parameters
hParams := GetHeaderParams{
XArrayExploded: &expectedArray1,
XArray: &expectedArray2,
XArrayExploded: expectedArray1,
XArray: expectedArray2,
XObjectExploded: &expectedObject1,
XObject: &expectedObject2,
XPrimitiveExploded: &expectedPrimitive1,
Expand Down
4 changes: 2 additions & 2 deletions internal/test/server/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error) {
outType = "interface{}"
}
outSchema.GoType = outType
outSchema.SkipOptionalPointer = true
} else {
// We've got an object with some properties.
for _, pName := range SortedSchemaKeys(schema.Properties) {
Expand Down Expand Up @@ -341,6 +342,7 @@ func resolveType(schema *openapi3.Schema, path []string, outSchema *Schema) erro
outSchema.AdditionalTypes = append(outSchema.AdditionalTypes, additionalTypes...)
}
outSchema.Properties = arrayType.Properties
outSchema.SkipOptionalPointer = true
case "integer":
// We default to int if format doesn't ask for something else.
if f == "int64" {
Expand Down
14 changes: 7 additions & 7 deletions pkg/codegen/templates/chi-middleware.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
if paramValue := r.URL.Query().Get("{{.ParamName}}"); paramValue != "" {

{{if .IsPassThrough}}
params.{{.GoName}} = {{if not .Required}}&{{end}}paramValue
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}paramValue
{{end}}

{{if .IsJson}}
Expand All @@ -61,7 +61,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
return
}

params.{{.GoName}} = {{if not .Required}}&{{end}}value
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}value
{{end}}
}{{if .Required}} else {
http.Error(w, "Query argument {{.ParamName}} is required, but not found", http.StatusBadRequest)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
}

{{if .IsPassThrough}}
params.{{.GoName}} = {{if not .Required}}&{{end}}valueList[0]
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}valueList[0]
{{end}}

{{if .IsJson}}
Expand All @@ -108,7 +108,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
}
{{end}}

params.{{.GoName}} = {{if not .Required}}&{{end}}{{.GoName}}
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}{{.GoName}}

} {{if .Required}}else {
http.Error(w, fmt.Sprintf("Header parameter {{.ParamName}} is required, but not found: %s", err), http.StatusBadRequest)
Expand All @@ -124,7 +124,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
if cookie, err = r.Cookie("{{.ParamName}}"); err == nil {

{{- if .IsPassThrough}}
params.{{.GoName}} = {{if not .Required}}&{{end}}cookie.Value
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}cookie.Value
{{end}}

{{- if .IsJson}}
Expand All @@ -142,7 +142,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
return
}

params.{{.GoName}} = {{if not .Required}}&{{end}}value
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}value
{{end}}

{{- if .IsStyled}}
Expand All @@ -152,7 +152,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
http.Error(w, "Invalid format for parameter {{.ParamName}}: %s", http.StatusBadRequest)
return
}
params.{{.GoName}} = {{if not .Required}}&{{end}}value
params.{{.GoName}} = {{if .IndirectOptional}}&{{end}}value
{{end}}

}
Expand Down
Loading