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
20 changes: 11 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download dashboard
uses: actions/download-artifact@v4
- uses: actions/setup-go@v5
with:
name: dashboard
path: webui/dist
go-version: 1.25.5
- uses: ./.github/actions/build-release-notes
- uses: actions/setup-node@v4
with:
node-version: 23
registry-url: 'https://registry.npmjs.org'
- run: npm install
- name: Install taskfile
run: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
- name: Build
run: task build-vue-app
env:
CGO_ENABLED: 0
- name: Publish
run: task publish-npm-package VERSION=${GITHUB_REF##*/v}
run: task publish-npm-package VERSION=${GITHUB_REF##*/v}
env:
CGO_ENABLED: 0
4 changes: 4 additions & 0 deletions providers/openapi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ func setResponseRebuild(response *common.HttpEventResponse, request *common.Http
panic(err)
}

if contentType != "" {
response.Headers["Content-Type"] = contentType
}

err = setResponseHeader(response, res.Headers)
if err != nil {
panic(err)
Expand Down
58 changes: 58 additions & 0 deletions providers/openapi/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,64 @@ func TestHandler_Event_TypeScript(t *testing.T) {
require.Equal(t, "no configuration was found for HTTP status code 404, https://swagger.io/docs/specification/describing-responses", log.Actions[0].Error.Message)
},
},
{
name: "rebuild different content-type",
test: func(t *testing.T) {
e := enginetest.NewEngine()
err := e.AddScript(newScript(fmt.Sprintf("%s.ts", t.Name()), `
import {on, sleep} from 'mokapi'
export default function() {
on('http', async (request, response) => {
response.rebuild(200, 'application/xml');
});
}
`))
require.NoError(t, err)

config := &openapi.Config{
Info: openapi.Info{Name: "Testing"},
Servers: []*openapi.Server{{Url: "http://localhost"}},
}

h := func(rw http.ResponseWriter, r *http.Request) {
sm := &events.StoreManager{}
sm.SetStore(10, events.NewTraits().WithNamespace("http"))
h := openapi.NewHandler(config, e, sm)
err = h.ServeHTTP(rw, r)
require.Nil(t, err)
}

op := openapitest.NewOperation(
openapitest.WithResponse(http.StatusOK,
openapitest.WithContent("application/json",
openapitest.NewContent(openapitest.WithSchema(
schematest.New(
"object",
schematest.WithProperty("foo", schematest.New("string")),
schematest.WithRequired("foo"),
),
)),
),
openapitest.WithContent("application/xml",
openapitest.NewContent(openapitest.WithSchema(
schematest.New(
"object",
schematest.WithProperty("foo", schematest.New("string")),
schematest.WithRequired("foo"),
),
)),
),
),
)
openapitest.AppendPath("/foo", config, openapitest.WithOperation("get", op))
r := httptest.NewRequest("get", "http://localhost/foo", nil)
r.Header.Set("accept", "application/json")
rr := httptest.NewRecorder()
h(rr, r)
require.Equal(t, http.StatusOK, rr.Code)
require.Contains(t, rr.Body.String(), `<data><foo>`)
},
},
{
name: "rebuild content type not in specification",
test: func(t *testing.T) {
Expand Down
Loading