diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 350f6accd..3b3e78081 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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} \ No newline at end of file + run: task publish-npm-package VERSION=${GITHUB_REF##*/v} + env: + CGO_ENABLED: 0 \ No newline at end of file diff --git a/providers/openapi/handler.go b/providers/openapi/handler.go index 2a4c70679..59ea1d151 100644 --- a/providers/openapi/handler.go +++ b/providers/openapi/handler.go @@ -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) diff --git a/providers/openapi/handler_test.go b/providers/openapi/handler_test.go index 39c601995..4fe56371a 100644 --- a/providers/openapi/handler_test.go +++ b/providers/openapi/handler_test.go @@ -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(), ``) + }, + }, { name: "rebuild content type not in specification", test: func(t *testing.T) {