Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch between mswjs/source and mswjs/http-middleware #48

Open
JeffBaumgardt opened this issue Sep 24, 2024 · 0 comments
Open

Type mismatch between mswjs/source and mswjs/http-middleware #48

JeffBaumgardt opened this issue Sep 24, 2024 · 0 comments

Comments

@JeffBaumgardt
Copy link

While I was trying to implement a standalone server for mocks I encountered a type mismatch. I had added the source package to read my openapi specs and output the generated handlers.

The type from openApi is RequestHandler<RequestHandlerDefaultInfo, any, any, RequestHandlerOptions>[] but the createServer expects handlers to be HttpHandler[]. The http hander type is an extension of Request handler, but is missing checkRedundantQueryParameters and matchMethod both of which are private on the Request Handler instance.

Example code

import {createServer} from '@mswjs/http-middleware'
import {fromOpenApi} from '@mswjs/source/open-api'
import type {OpenAPIV3} from 'openapi-types'

import balancesApi from '@tallied-technologies/services/Balances/Balances.json'

const balancesHandlers = await fromOpenApi({
    basePath: 'http://localhost/',
    ...balancesApi,
} as OpenAPIV3.Document)

const server = createServer(...balancesHandlers)
server.listen(8088)

It would also be really cool if source could re-export the OpenAPI document types as well so I don't have to install the openapi-types package just for the types.

The above code does work as written as js, this is just appeasing typescript because of the mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant