This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new @scalar/mock-server package
- Loading branch information
Showing
27 changed files
with
5,528 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ "foo": "bar" } | ||
{"foo": "bar"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import path from 'node:path' | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: '@scalar/mock-server', | ||
replacement: path.resolve(__dirname, '../mock-server/src/index.ts'), | ||
}, | ||
], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Scalar Mock Server | ||
|
||
A server returning fake data based on an OpenAPI specification | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @scalar/mock-server | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { serve } from '@hono/node-server' | ||
import { createMockServer } from '@scalar/mock-server' | ||
|
||
// Your OpenAPI specification | ||
const openapi = { | ||
openapi: '3.1.0', | ||
info: { | ||
title: 'Hello World', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/foobar': { | ||
get: { | ||
responses: { | ||
'200': { | ||
description: 'OK', | ||
content: { | ||
'application/json': { | ||
example: { | ||
foo: 'bar', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// Create the mocked routes | ||
const app = await createMockServer({ | ||
openapi, | ||
onRequest({ context, operation }) { | ||
console.log(context.req.method, context.req.path) | ||
}, | ||
}) | ||
|
||
// Start the server | ||
serve({ | ||
fetch: app.fetch, | ||
port: 3000, | ||
}, (info) => { | ||
console.log(`Listening on http://localhost:${info.port}`) | ||
}) | ||
``` |
Oops, something went wrong.