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
6 changes: 6 additions & 0 deletions internal/test/issues/issue-1578/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package: issue1578
generate:
models: true
echo-server: true
strict-server: true
output: issue1578.gen.go
3 changes: 3 additions & 0 deletions internal/test/issues/issue-1578/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package issue1578

//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml issue1578.yaml
199 changes: 199 additions & 0 deletions internal/test/issues/issue-1578/issue1578.gen.go

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

20 changes: 20 additions & 0 deletions internal/test/issues/issue-1578/issue1578.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
openapi: "3.0.1"
components:
schemas:
ComplexObject:
type: object
properties:
field1:
type: string
additionalProperties: {}
paths:
/test:
get:
operationId: test
responses:
200:
description: test
content:
application/json:
schema:
$ref: "#/components/schemas/ComplexObject"
36 changes: 36 additions & 0 deletions internal/test/issues/issue-1578/issue1578_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package issue1578_test

import (
"bytes"
"context"
issue1578 "github.com/deepmap/oapi-codegen/v2/internal/test/issues/issue-1578"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
"net/http/httptest"
"testing"
)

var _ issue1578.StrictServerInterface = &testStrictServerInterface{}

type testStrictServerInterface struct {
}

func (t testStrictServerInterface) Test(_ context.Context, _ issue1578.TestRequestObject) (issue1578.TestResponseObject, error) {
return issue1578.Test200JSONResponse(issue1578.ComplexObject{
AdditionalProperties: map[string]interface{}{
"message": "hello",
},
}), nil
}

func TestIssue1578(t *testing.T) {
responseObject, _ := testStrictServerInterface{}.Test(context.Background(), issue1578.TestRequestObject{})
response := &httptest.ResponseRecorder{
Body: new(bytes.Buffer),
}
err := responseObject.VisitTestResponse(response)
require.NoError(t, err)
data, _ := io.ReadAll(response.Body)
assert.JSONEq(t, `{"message":"hello"}`, string(data))
}
8 changes: 8 additions & 0 deletions internal/test/issues/issue-1578/ugly_workaround.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package issue1578

// This is an ugly workaround for the issue
//var _ json.Marshaler = Test200JSONResponse{}
//
//func (response Test200JSONResponse) MarshalJSON() ([]byte, error) {
// return json.Marshal(ComplexObject(response))
//}