Skip to content
Merged
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

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

10 changes: 10 additions & 0 deletions internal/test/bodies/content_types/text_non_string/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=../../../../../configuration-schema.json
# From issue-1897
package: textnonstring
output: text_non_string.gen.go
generate:
std-http-server: true
strict-server: true
models: true
output-options:
skip-prune: true
12 changes: 12 additions & 0 deletions internal/test/bodies/content_types/text_non_string/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package textnonstring verifies strict-server codegen for text/plain
// responses whose schema is a non-string primitive (integer, boolean).
// The generated Visit* method must compile and write the value's decimal /
// literal text form. Before the fix, the generated code did
// []byte(response) on a non-string-underlying type, which either failed to
// compile (integer, boolean) or, on the fiber/iris path, string(response)
// silently produced a single rune instead of the number.
//
// From issue-1897.
package textnonstring

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=../../../../../../configuration-schema.json
# From issue-1897 — fiber (ctx.WriteString) backend coverage
package: textnonstringfiber
output: fiber.gen.go
generate:
fiber-server: true
strict-server: true
models: true
output-options:
skip-prune: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package textnonstringfiber

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../spec.yaml

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package textnonstringfiber

import (
"context"
"testing"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/adaptor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/oapi-codegen/testutil"
)

type server struct{}

func (server) GetPing(_ context.Context, _ GetPingRequestObject) (GetPingResponseObject, error) {
return GetPing201TextResponse(201), nil
}

// TestFiberIntegerTextResponse is the fiber-path (ctx.WriteString) regression
// test for issue-1897: an integer text/plain response must serialize as the
// decimal "201", not the single Unicode code-point that string(response)
// previously produced.
func TestFiberIntegerTextResponse(t *testing.T) {
app := fiber.New()
RegisterHandlers(app, NewStrictHandler(server{}, nil))

rr := testutil.NewRequest().Get("/ping").GoWithHTTPHandler(t, adaptor.FiberApp(app)).Recorder
require.Equal(t, 201, rr.Code)
assert.Equal(t, "text/plain", rr.Header().Get("Content-Type"))
assert.Equal(t, "201", rr.Body.String())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=../../../../../../configuration-schema.json
# From issue-1897 — iris (ctx.WriteString) backend coverage
package: textnonstringiris
output: iris.gen.go
generate:
iris-server: true
strict-server: true
models: true
output-options:
skip-prune: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package textnonstringiris

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../spec.yaml
Loading