由 caspian 出售

Prism is an open-source HTTP server that creates life-like mock servers from OpenAPI v2/v3 and Postman Collection specs, and validates API contracts between consumers and implementations.
This block provides the full Prism monorepo source: a programmable HTTP mock server and validation proxy built on OpenAPI v2/v3. It exposes both a CLI entry-point (prism mock / prism proxy) and a Node.js API for embedding mock/proxy instances directly in application code or test suites. Typical buyers are backend teams who want contract testing, API mocking in CI, or an embedded HTTP forwarder with request/response validation.
cli/ - Yargs-based CLI wiring the mock and proxy subcommandscore/ - Framework-agnostic Prism factory, type definitions, and logger primitiveshttp/ - HTTP-specific mocker, forwarder, router, validators, and createInstance exporthttp-server/ - HTTP server wrapper that lifts a Prism instance onto a real TCP porttsconfig.build.json - Root TypeScript build config for all packagestsconfig.json - Root TypeScript dev confignpm install @stoplight/prism-core @stoplight/prism-http @stoplight/prism-http-server @stoplight/prism-cli
npm install @stoplight/types fp-ts lodash pino node-fetch yargs
npm install --save-dev typescript @types/node @types/lodash @types/pino
No native modules, no pod install, no Android linking required. Node.js >= 18.20.1 is mandatory.
Copy the source/ directory into your project root (e.g. vendor/prism/).
Add path aliases in your root tsconfig.json so TypeScript resolves the local packages instead of npm:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@stoplight/prism-core": ["vendor/prism/core/src"],
"@stoplight/prism-http": ["vendor/prism/http/src"],
"@stoplight/prism-http-server": ["vendor/prism/http-server/src"]
},
"strict": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2019"
}
}
Install peer dependencies listed above.
If you call the CLI directly from source, ensure the entry file is executable:
chmod +x vendor/prism/cli/src/index.ts
ts-node vendor/prism/cli/src/index.ts mock your-spec.yaml
启动隔离沙箱并在服务器端直接运行 — 无需本地配置。
此版本的 Tetrees AI Review
This TypeScript cli / script completed archive review with strong static results. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
管道 avcp-2026-08-04.1 · SHA-256 da4a30e2ed6f1815…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
审查日期 2026年8月4日
将此产品直接导入你的 AI IDE、网页构建器或云端 IDE。
将 Tetrees 连接到兼容的 AI IDE,列出你拥有的产品并获取已验证 ZIP,同时不会开放卖家上传权限。
暂无评价。
Sign in to join the discussion
Loading discussion…
--port, --host, --errors, and --dynamic flags at runtime.import { createInstance } from '@stoplight/prism-http';
import type {
IHttpConfig,
IHttpProxyConfig,
PrismHttpComponents,
PickRequired,
} from '@stoplight/prism-http';
function createInstance(
defaultConfig: IHttpConfig | IHttpProxyConfig,
components: PickRequired<Partial<PrismHttpComponents>, 'logger'>
): PrismInstance; // IPrism<IHttpOperation, IHttpRequest, IHttpResponse, IHttpConfig>
Use createInstance to embed a fully configured Prism HTTP instance inside Node.js code. Pass a defaultConfig that controls mocking vs. forwarding behaviour and supply at minimum a logger (pino Logger). All other components (router, validator, mocker, forwarder) are defaulted automatically.
import { getHttpOperationsFromSpec } from '@stoplight/prism-http';
function getHttpOperationsFromSpec(
specFilePathOrObject: string | Record<string, unknown>
): Promise<IHttpOperation[]>;
Loads an OpenAPI v2/v3 specification from a file path or an already-parsed object and returns the array of IHttpOperation objects that Prism uses internally for routing and mocking. Use this whenever you need to pre-parse a spec before passing it to a Prism instance or for static analysis.
import { createAndCallPrismInstanceWithSpec, PrismOkResult, PrismErrorResult } from '@stoplight/prism-http';
function createAndCallPrismInstanceWithSpec(
spec: string | Record<string, unknown>,
config: IHttpConfig,
request: IHttpRequest
): Promise<PrismOkResult | PrismErrorResult>;
A convenience function that combines spec loading, instance creation, and a single HTTP request dispatch. Ideal for one-shot test assertions without managing instance lifecycle.
Start a Prism mock instance directly in-process against a local spec file, fire a request, and assert the mocked response without spawning a child process.
import pino from 'pino';
import { createInstance, getHttpOperationsFromSpec } from '@stoplight/prism-http';
async function runMockRequest() {
const logger = pino({ level: 'silent' });
const operations = await getHttpOperationsFromSpec('./openapi.yaml');
const instance = createInstance(
{ isProxy: false, mock: { dynamic: false } },
{ logger }
);
await instance.load(operations);
const response = await instance.process({
method: 'get',
url: { path: '/pets', query: {} },
headers: { accept: 'application/json' },
});
console.log(response.status); // e.g. 200
console.log(response.body); // mocked body from spec
}
runMockRequest();
Wire Prism as a validation proxy that checks outbound requests and inbound responses against an OpenAPI spec, forwarding to an upstream server.
import pino from 'pino';
import { createInstance, getHttpOperationsFromSpec } from '@stoplight/prism-http';
import type { IHttpProxyConfig } from '@stoplight/prism-http';
async function runProxyRequest() {
const logger = pino({ level: 'warn' });
const operations = await getHttpOperationsFromSpec('./openapi.yaml');
const config: IHttpProxyConfig = {
isProxy: true,
upstream: new URL('https://petstore.swagger.io/v2'),
mock: { dynamic: false },
validateRequest: true,
validateResponse: true,
};
const instance = createInstance(config, { logger });
await instance.load(operations);
const response = await instance.process({
method: 'post',
url: { path: '/pets', query: {} },
headers: { 'content-type': 'application/json' },
body: { name: 'Fido' },
});
console.log(response.status, response.body);
}
runProxyRequest();
Use getHttpOperationsFromSpec as a standalone utility to list all routes defined in a spec without starting any server.
import { getHttpOperationsFromSpec } from '@stoplight/prism-http';
async function listRoutes(specPath: string) {
const operations = await getHttpOperationsFromSpec(specPath);
for (const op of operations) {
console.log(`${op.method.toUpperCase()} ${op.path}`);
if (op.responses.length) {
console.log(
' responses:',
op.responses.map(r => r.code).join(', ')
);
}
}
}
listRoutes('./openapi.yaml');
cli/ - Defines the prism CLI binary. src/index.ts bootstraps yargs; src/commands/mock.ts and src/commands/proxy.ts implement the two subcommands; src/util/createServer.ts wires the HTTP server.core/ - Package-agnostic interfaces and the factory function that assembles any Prism instance from pluggable components (router, mocker, forwarder, validators). src/types.ts defines IPrismComponents, IPrismInput, IPrismDiagnostic.http/ - Full HTTP implementation. src/index.ts exports createInstance; src/mocker/ handles response selection and generation; src/forwarder/ implements proxying via node-fetch; src/router/ matches incoming requests to operations; src/validator/ validates inputs and outputs.http-server/ - Thin layer (Fastify or raw http) that binds a Prism instance to a TCP port, used by the CLI.tsconfig.build.json - Shared production TypeScript config; excludes test files.tsconfig.json - Dev TypeScript config with project references across all packages.fetch-adjacent APIs and fails silently on older runtimes. Pin engines.node to >=18.20.1 in your package.json.fp-ts: Prism imports from fp-ts/function, fp-ts/Either, etc. (v2 tree-shakeable paths). If bundlers resolve the ESM build incorrectly, add "moduleResolution": "node16" or keep CJS output.@stoplight/types version mismatch: IHttpOperation, IHttpHeaderParam, and related types must come from the same @stoplight/types version used internally. Duplicate installs cause assignability errors. Use npm dedupe.pino logger required: Passing console as the logger will throw at runtime. Always construct a real pino logger (pino({ level: 'silent' }) for tests).getHttpOperationsFromSpec resolves relative paths from process.cwd(), not from the calling file. Pass path.resolve(__dirname, './spec.yaml') explicitly.dynamic: true increases latency: The dynamic payload generator runs JSON Schema faker on every request. In CI keep dynamic: false for deterministic snapshots.I have dropped the Stoplight Prism source into `vendor/prism/` in my project.
The integration guide is in `vendor/prism/USAGE.md`.
The upstream package is `@stoplight/prism-http` (stoplightio_prism).
Please help me integrate Prism into my existing Express/TypeScript project step-by-step:
1. Read `vendor/prism/USAGE.md` fully before writing any code.
2. Add the required tsconfig path aliases so `@stoplight/prism-core` and
`@stoplight/prism-http` resolve to `vendor/prism/core/src` and
`vendor/prism/http/src` respectively.
3. Install all runtime dependencies listed in the "Required dependencies" section.
4. Create a `src/mockServer.ts` module that:
- Calls `getHttpOperationsFromSpec` with my local `openapi.yaml`
- Calls `createInstance` with `{ isProxy: false, mock: { dynamic: false } }`
- Exports a `processRequest(req)` helper that delegates to `instance.process`
5. Wire `src/mockServer.ts` into my existing Express app as middleware on `/mock/*`.
6. Add a Jest test that imports `createAndCallPrismInstanceWithSpec` and
asserts a 200 response for a known GET route.
Only use symbols that appear in `vendor/prism/USAGE.md`. Do not install the
npm package; use the local source exclusively.
The source is licensed under the Apache 2.0 license (see source/cli/LICENSE, source/core/LICENSE, source/http/LICENSE). Original project: Stoplight Prism by Stoplight, Inc.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
完整安装指南与集成提示词将在购买后解锁。
Automation, Utilities & Developer Tools
免费