@nice2dev/ui-api 1.4.8 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +44 -0
- package/dist/apiModelBridge.d.ts +16 -0
- package/dist/core/codegen.d.ts +16 -0
- package/dist/core/curl.d.ts +32 -0
- package/dist/core/detect.d.ts +19 -0
- package/dist/core/graphql.d.ts +74 -0
- package/dist/core/har.d.ts +19 -0
- package/dist/core/index.d.ts +22 -0
- package/dist/core/markdown.d.ts +29 -0
- package/dist/core/md5.d.ts +6 -0
- package/dist/core/mock.d.ts +25 -0
- package/dist/core/model.d.ts +332 -0
- package/dist/core/openapi.d.ts +27 -0
- package/dist/core/postman.d.ts +12 -0
- package/dist/core/transport.d.ts +122 -0
- package/dist/core/url.d.ts +23 -0
- package/dist/core/variables.d.ts +25 -0
- package/dist/core/wsdl.d.ts +62 -0
- package/dist/core/yaml.d.ts +20 -0
- package/dist/core.cjs +121 -0
- package/dist/core.mjs +4215 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1314 -1008
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @nice2dev/ui-api
|
|
2
2
|
|
|
3
|
+
## 1.4.10
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 1.4.9
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 98f11b0: New `@nice2dev/ui-api/core` entry: the API tools' model, converters and transport, without React.
|
|
12
|
+
The same exports are also available from the main entry.
|
|
13
|
+
|
|
14
|
+
- **Request model:** a collection of folders and requests.
|
|
15
|
+
- Each request has one parameter list, with a location per row (query, path, header or cookie).
|
|
16
|
+
- Bodies: JSON, XML, text, form, multipart, binary, GraphQL and SOAP.
|
|
17
|
+
- Auth: inherited, API key, Bearer, Basic, Digest, OAuth 2, AWS Signature V4, HMAC, mTLS or
|
|
18
|
+
custom headers.
|
|
19
|
+
- Variables use `{{name}}`. Secrets are written only as `{{secret:KEY}}`.
|
|
20
|
+
- **Converters:**
|
|
21
|
+
- curl: reads what browsers copy (bash and cmd) and PowerShell's `curl.exe`; writes all three.
|
|
22
|
+
- OpenAPI 3.0 / 3.1 and Swagger 2.0, as JSON or YAML. `$ref`s are followed into other files
|
|
23
|
+
through `resolveRef`. Exports OpenAPI 3.1.
|
|
24
|
+
- Postman Collection v2.1 in both directions, v2.0 read-only, and Postman environments.
|
|
25
|
+
- HAR 1.2.
|
|
26
|
+
- GraphQL introspection: one request per operation, with a selection set and example variables.
|
|
27
|
+
- WSDL 1.1: SOAP 1.1 / 1.2 envelopes with a sample body built from the schema.
|
|
28
|
+
- `importApiDocument` recognises which of these a text is.
|
|
29
|
+
- **Code samples:** curl, fetch, C# HttpClient, PowerShell and Python.
|
|
30
|
+
- **Sending:**
|
|
31
|
+
- `resolveRequest` interpolates variables and signs the request: Basic, Bearer, API key,
|
|
32
|
+
Digest (MD5 or SHA-256), AWS SigV4 and HMAC, all with Web Crypto.
|
|
33
|
+
- `sendApiRequest` answers a Digest challenge.
|
|
34
|
+
- `fetchTransport` sends over `fetch`; a host can pass its own proxy transport instead.
|
|
35
|
+
- OAuth 2 helpers: client credentials, password, authorization code with PKCE, device flow and
|
|
36
|
+
refresh.
|
|
37
|
+
- **Also:**
|
|
38
|
+
- A YAML reader and writer.
|
|
39
|
+
- Mock data generated from a schema.
|
|
40
|
+
- Markdown documentation of a collection.
|
|
41
|
+
- Bridges to the NiceAPITester and NiceAPIDesigner types.
|
|
42
|
+
|
|
3
43
|
## 1.4.8
|
|
4
44
|
|
|
5
45
|
No changes in this release.
|
package/README.md
CHANGED
|
@@ -89,6 +89,50 @@ function App() {
|
|
|
89
89
|
}
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
## Core without React — `@nice2dev/ui-api/core` (1.4.9)
|
|
93
|
+
|
|
94
|
+
The model and converters the API tools are built on, usable in Node (importers in CI, generators,
|
|
95
|
+
a host's proxy). Nothing in it imports React or another package.
|
|
96
|
+
|
|
97
|
+
- **Model**: `NiceApiCollection` → folders → `NiceApiRequest` (one parameter list with a location
|
|
98
|
+
per row: query / path / header / cookie; nine body kinds incl. GraphQL and SOAP; auth `inherit`,
|
|
99
|
+
API key, Bearer, Basic, Digest, OAuth 2, AWS SigV4, HMAC, mTLS, custom), variables
|
|
100
|
+
(`{{name}}`, secrets only as `{{secret:KEY}}`), environments.
|
|
101
|
+
- **Import / export**: curl (bash, cmd, PowerShell), OpenAPI 3.0 / 3.1 and Swagger 2.0 (JSON or
|
|
102
|
+
YAML, `$ref` across files through `resolveRef`), Postman Collection v2.1 (v2.0 read) and
|
|
103
|
+
environments, HAR 1.2, GraphQL introspection, WSDL 1.1 (SOAP 1.1 / 1.2 envelopes).
|
|
104
|
+
`importApiDocument(text)` recognises the format.
|
|
105
|
+
- **Code samples**: curl, fetch, C# HttpClient, PowerShell, Python (`generateCode`).
|
|
106
|
+
- **Sending**: `resolveRequest` (variables + auth signing with Web Crypto), `sendApiRequest`
|
|
107
|
+
(answers a Digest challenge), `fetchTransport` or the host's own transport; OAuth 2 token
|
|
108
|
+
helpers (client credentials, password, authorization code with PKCE, device flow, refresh).
|
|
109
|
+
- **Also**: a YAML reader / writer, mock data from schemas, Markdown docs.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import {
|
|
113
|
+
importApiDocument,
|
|
114
|
+
exportOpenApiYaml,
|
|
115
|
+
generateCode,
|
|
116
|
+
sendApiRequest,
|
|
117
|
+
fetchTransport,
|
|
118
|
+
variableScope,
|
|
119
|
+
} from '@nice2dev/ui-api/core';
|
|
120
|
+
|
|
121
|
+
const { collection } = importApiDocument(openApiYamlText);
|
|
122
|
+
const request = collection!.items[0];
|
|
123
|
+
if (request.kind === 'request') {
|
|
124
|
+
console.log(generateCode(request, 'csharp'));
|
|
125
|
+
const { response } = await sendApiRequest(request, fetchTransport(), {
|
|
126
|
+
variables: variableScope(collection, environment),
|
|
127
|
+
resolveSecret: (key) => vault.get(key),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const yaml = exportOpenApiYaml(collection!);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`fromApiTesterCollection` / `toApiTesterCollection` (from the main entry) move collections between
|
|
134
|
+
the core model and `NiceAPITester`.
|
|
135
|
+
|
|
92
136
|
## License
|
|
93
137
|
|
|
94
138
|
See LICENSE file.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NiceApiCollection, NiceApiRequest } from './core';
|
|
2
|
+
import { APICollection, APIRequest, OpenAPISchema } from './types';
|
|
3
|
+
/** A NiceAPITester request in the core model. */
|
|
4
|
+
export declare function fromApiTesterRequest(request: APIRequest): NiceApiRequest;
|
|
5
|
+
/** A core request as a NiceAPITester request (path parameters filled into the URL). */
|
|
6
|
+
export declare function toApiTesterRequest(request: NiceApiRequest): APIRequest;
|
|
7
|
+
/** A NiceAPITester collection in the core model. */
|
|
8
|
+
export declare function fromApiTesterCollection(collection: APICollection): NiceApiCollection;
|
|
9
|
+
/** A core collection as a NiceAPITester collection (folders kept, nested ones too). */
|
|
10
|
+
export declare function toApiTesterCollection(collection: NiceApiCollection): APICollection;
|
|
11
|
+
/** Every request of a core collection, flat, as NiceAPITester requests. */
|
|
12
|
+
export declare function toApiTesterRequests(collection: NiceApiCollection): APIRequest[];
|
|
13
|
+
/** NiceAPIDesigner's OpenAPI document as a core collection. */
|
|
14
|
+
export declare function openApiSchemaToCollection(schema: OpenAPISchema): NiceApiCollection;
|
|
15
|
+
/** A core collection as an OpenAPI document NiceAPIDesigner edits. */
|
|
16
|
+
export declare function collectionToOpenApiSchema(collection: NiceApiCollection): OpenAPISchema;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NiceApiAuth, NiceApiRequest } from './model';
|
|
2
|
+
/** The languages `generateCode` writes. */
|
|
3
|
+
export type NiceApiCodeLanguage = 'curl' | 'curl-cmd' | 'curl-powershell' | 'fetch' | 'csharp' | 'powershell' | 'python';
|
|
4
|
+
export declare const NICE_API_CODE_LANGUAGES: readonly {
|
|
5
|
+
id: NiceApiCodeLanguage;
|
|
6
|
+
label: string;
|
|
7
|
+
syntax: string;
|
|
8
|
+
}[];
|
|
9
|
+
export interface NiceApiCodeOptions {
|
|
10
|
+
/** Interpolation applied to every piece; default keeps `{{variables}}` as written. */
|
|
11
|
+
transform?: (text: string) => string;
|
|
12
|
+
/** The auth to write in (pass the effective one for inherited auth); default the request's. */
|
|
13
|
+
auth?: NiceApiAuth;
|
|
14
|
+
}
|
|
15
|
+
/** A code sample that sends `request`. */
|
|
16
|
+
export declare function generateCode(request: NiceApiRequest, language: NiceApiCodeLanguage, options?: NiceApiCodeOptions): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NiceApiAuth, NiceApiRequest } from './model';
|
|
2
|
+
/** The shells a command is written for. */
|
|
3
|
+
export type NiceCurlShell = 'bash' | 'cmd' | 'powershell';
|
|
4
|
+
/** Whether `text` looks like a curl command. */
|
|
5
|
+
export declare function isCurlCommand(text: string): boolean;
|
|
6
|
+
/** Splits a command line into arguments the way the shell would. */
|
|
7
|
+
export declare function tokenizeCommand(source: string, shell?: NiceCurlShell): string[];
|
|
8
|
+
declare function decodeBase64(text: string): string;
|
|
9
|
+
declare function encodeBase64(text: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* The request a curl command describes. Unknown options are skipped (with their value when they
|
|
12
|
+
* take one); `Authorization: Bearer` / `Basic` headers become the request's auth.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseCurl(command: string): NiceApiRequest;
|
|
15
|
+
/** `GET /users/{id}` — a name for a request read from somewhere without one. */
|
|
16
|
+
export declare function requestName(method: string, url: string): string;
|
|
17
|
+
export interface NiceCurlOptions {
|
|
18
|
+
shell?: NiceCurlShell;
|
|
19
|
+
/** Applied to every text piece — interpolation of `{{variables}}`. Default: kept as written. */
|
|
20
|
+
transform?: (text: string) => string;
|
|
21
|
+
/** One option per line (default) or everything on one line. */
|
|
22
|
+
multiline?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The request as a curl command. `auth` is the auth to apply (the request's own when unset — pass
|
|
26
|
+
* the effective one for inherited auth). HMAC and OAuth 2 without a token are left out: they need
|
|
27
|
+
* a computed value.
|
|
28
|
+
*/
|
|
29
|
+
export declare function toCurl(request: NiceApiRequest, options?: NiceCurlOptions & {
|
|
30
|
+
auth?: NiceApiAuth;
|
|
31
|
+
}): string;
|
|
32
|
+
export { encodeBase64 as toBase64, decodeBase64 as fromBase64 };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NiceApiCollection, NiceApiEnvironment, NiceApiRequest } from './model';
|
|
2
|
+
import { NiceXmlParser } from './wsdl';
|
|
3
|
+
export type NiceApiDocumentKind = 'curl' | 'openapi' | 'postman' | 'postman-environment' | 'har' | 'graphql' | 'wsdl';
|
|
4
|
+
export interface NiceApiImportOptions {
|
|
5
|
+
parseYaml?: (text: string) => unknown;
|
|
6
|
+
resolveRef?: (ref: string) => unknown;
|
|
7
|
+
xmlParser?: NiceXmlParser;
|
|
8
|
+
}
|
|
9
|
+
/** What an import produced: a collection, an environment, or one request (curl). */
|
|
10
|
+
export interface NiceApiImportResult {
|
|
11
|
+
kind: NiceApiDocumentKind;
|
|
12
|
+
collection?: NiceApiCollection;
|
|
13
|
+
environment?: NiceApiEnvironment;
|
|
14
|
+
request?: NiceApiRequest;
|
|
15
|
+
}
|
|
16
|
+
/** The kind of document `text` is, or `undefined`. */
|
|
17
|
+
export declare function detectApiDocument(text: string, options?: NiceApiImportOptions): NiceApiDocumentKind | undefined;
|
|
18
|
+
/** Reads `text` as whatever it is. Throws when it is none of the known kinds. */
|
|
19
|
+
export declare function importApiDocument(text: string, options?: NiceApiImportOptions): NiceApiImportResult;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NiceApiCollection } from './model';
|
|
2
|
+
/** The standard introspection query — send it to an endpoint to get its schema. */
|
|
3
|
+
export declare const GRAPHQL_INTROSPECTION_QUERY = "query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types { ...FullType }\n }\n}\nfragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args { ...InputValue }\n type { ...TypeRef }\n isDeprecated\n deprecationReason\n }\n inputFields { ...InputValue }\n interfaces { ...TypeRef }\n enumValues(includeDeprecated: true) { name description isDeprecated }\n possibleTypes { ...TypeRef }\n}\nfragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n}\nfragment TypeRef on __Type {\n kind\n name\n ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }\n}";
|
|
4
|
+
/** A reference to a type, wrapped in NON_NULL / LIST as the schema has it. */
|
|
5
|
+
export interface NiceGraphqlTypeRef {
|
|
6
|
+
kind: string;
|
|
7
|
+
name?: string | null;
|
|
8
|
+
ofType?: NiceGraphqlTypeRef | null;
|
|
9
|
+
}
|
|
10
|
+
export interface NiceGraphqlInputValue {
|
|
11
|
+
name: string;
|
|
12
|
+
description?: string | null;
|
|
13
|
+
type: NiceGraphqlTypeRef;
|
|
14
|
+
defaultValue?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface NiceGraphqlField {
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string | null;
|
|
19
|
+
args: NiceGraphqlInputValue[];
|
|
20
|
+
type: NiceGraphqlTypeRef;
|
|
21
|
+
isDeprecated?: boolean;
|
|
22
|
+
deprecationReason?: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface NiceGraphqlType {
|
|
25
|
+
kind: 'SCALAR' | 'OBJECT' | 'INTERFACE' | 'UNION' | 'ENUM' | 'INPUT_OBJECT' | string;
|
|
26
|
+
name: string;
|
|
27
|
+
description?: string | null;
|
|
28
|
+
fields?: NiceGraphqlField[] | null;
|
|
29
|
+
inputFields?: NiceGraphqlInputValue[] | null;
|
|
30
|
+
enumValues?: {
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string | null;
|
|
33
|
+
}[] | null;
|
|
34
|
+
possibleTypes?: NiceGraphqlTypeRef[] | null;
|
|
35
|
+
}
|
|
36
|
+
/** A schema read from introspection. */
|
|
37
|
+
export interface NiceGraphqlSchema {
|
|
38
|
+
queryType?: string;
|
|
39
|
+
mutationType?: string;
|
|
40
|
+
subscriptionType?: string;
|
|
41
|
+
types: Record<string, NiceGraphqlType>;
|
|
42
|
+
}
|
|
43
|
+
export type NiceGraphqlOperationKind = 'query' | 'mutation' | 'subscription';
|
|
44
|
+
/** One root field — what a request can call. */
|
|
45
|
+
export interface NiceGraphqlOperation {
|
|
46
|
+
kind: NiceGraphqlOperationKind;
|
|
47
|
+
field: NiceGraphqlField;
|
|
48
|
+
}
|
|
49
|
+
/** Reads an introspection result (`{data: {__schema}}`, `{__schema}` or the schema itself). */
|
|
50
|
+
export declare function parseGraphqlIntrospection(source: string | object): NiceGraphqlSchema;
|
|
51
|
+
/** `[User!]!` */
|
|
52
|
+
export declare function graphqlTypeName(ref: NiceGraphqlTypeRef | null | undefined): string;
|
|
53
|
+
/** The named type under the NON_NULL / LIST wrappers. */
|
|
54
|
+
export declare function namedType(ref: NiceGraphqlTypeRef | null | undefined): string | undefined;
|
|
55
|
+
/** Every root field of the query, mutation and subscription types. */
|
|
56
|
+
export declare function graphqlOperations(schema: NiceGraphqlSchema): NiceGraphqlOperation[];
|
|
57
|
+
/** An example value for an input type: `""`, `0`, `false`, the first enum value, nested inputs. */
|
|
58
|
+
export declare function graphqlExampleValue(schema: NiceGraphqlSchema, ref: NiceGraphqlTypeRef, depth?: number): unknown;
|
|
59
|
+
/** An operation's text — `query User($id: ID!) { user(id: $id) { … } }` — and example variables. */
|
|
60
|
+
export declare function buildGraphqlOperation(schema: NiceGraphqlSchema, operation: NiceGraphqlOperation, options?: {
|
|
61
|
+
depth?: number;
|
|
62
|
+
}): {
|
|
63
|
+
query: string;
|
|
64
|
+
variables: Record<string, unknown>;
|
|
65
|
+
operationName: string;
|
|
66
|
+
};
|
|
67
|
+
/** A collection: a request per operation, in folders Queries / Mutations / Subscriptions. */
|
|
68
|
+
export declare function importGraphqlIntrospection(source: string | object | NiceGraphqlSchema, options?: {
|
|
69
|
+
name?: string;
|
|
70
|
+
endpoint?: string;
|
|
71
|
+
depth?: number;
|
|
72
|
+
/** The folder names (a UI passes translations). Default Queries / Mutations / Subscriptions. */
|
|
73
|
+
folderNames?: Partial<Record<NiceGraphqlOperationKind, string>>;
|
|
74
|
+
}): NiceApiCollection;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NiceApiCollection, NiceApiRequest } from './model';
|
|
2
|
+
export interface NiceHarImportOptions {
|
|
3
|
+
/** Leave out images, fonts, style sheets and scripts. Default true. */
|
|
4
|
+
skipStatic?: boolean;
|
|
5
|
+
/** Keep only the entries this returns true for (the raw HAR entry). */
|
|
6
|
+
filter?: (entry: Record<string, unknown>) => boolean;
|
|
7
|
+
/** Collection name. Default "HAR import". */
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Whether a parsed JSON value is a HAR log. */
|
|
11
|
+
export declare function isHar(value: unknown): boolean;
|
|
12
|
+
/** Reads a HAR log into a collection (flat, in the log's order). */
|
|
13
|
+
export declare function importHar(source: string | object, options?: NiceHarImportOptions): NiceApiCollection;
|
|
14
|
+
/** Requests (and their first saved example as the response) as a HAR 1.2 log. */
|
|
15
|
+
export declare function exportHar(source: NiceApiCollection | readonly NiceApiRequest[], options?: {
|
|
16
|
+
creator?: string;
|
|
17
|
+
transform?: (text: string) => string;
|
|
18
|
+
now?: () => Date;
|
|
19
|
+
}): Record<string, unknown>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nice2dev/ui-api/core — the React-free core of the API tools (1.4.9): the request / collection
|
|
3
|
+
* model, converters (curl, OpenAPI 3.x / Swagger 2.0, Postman, HAR, GraphQL introspection, WSDL),
|
|
4
|
+
* code samples, YAML, mock data, Markdown docs and the transport (variables, auth signing,
|
|
5
|
+
* OAuth 2). Usable in Node: importers in CI, generators, a host's proxy.
|
|
6
|
+
*/
|
|
7
|
+
export * from './model';
|
|
8
|
+
export * from './variables';
|
|
9
|
+
export * from './url';
|
|
10
|
+
export * from './curl';
|
|
11
|
+
export * from './codegen';
|
|
12
|
+
export * from './yaml';
|
|
13
|
+
export * from './mock';
|
|
14
|
+
export * from './openapi';
|
|
15
|
+
export * from './postman';
|
|
16
|
+
export * from './har';
|
|
17
|
+
export * from './graphql';
|
|
18
|
+
export * from './wsdl';
|
|
19
|
+
export * from './md5';
|
|
20
|
+
export * from './transport';
|
|
21
|
+
export * from './markdown';
|
|
22
|
+
export * from './detect';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NiceApiCodeLanguage } from './codegen';
|
|
2
|
+
import { NiceApiCollection } from './model';
|
|
3
|
+
export interface NiceApiMarkdownLabels {
|
|
4
|
+
version: string;
|
|
5
|
+
servers: string;
|
|
6
|
+
authentication: string;
|
|
7
|
+
parameters: string;
|
|
8
|
+
name: string;
|
|
9
|
+
location: string;
|
|
10
|
+
required: string;
|
|
11
|
+
type: string;
|
|
12
|
+
description: string;
|
|
13
|
+
yes: string;
|
|
14
|
+
no: string;
|
|
15
|
+
requestBody: string;
|
|
16
|
+
responses: string;
|
|
17
|
+
status: string;
|
|
18
|
+
example: string;
|
|
19
|
+
deprecated: string;
|
|
20
|
+
noAuth: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const NICE_API_MARKDOWN_LABELS: NiceApiMarkdownLabels;
|
|
23
|
+
export interface NiceApiMarkdownOptions {
|
|
24
|
+
labels?: Partial<NiceApiMarkdownLabels>;
|
|
25
|
+
/** The language of each request's code sample; `false` leaves samples out. Default `curl`. */
|
|
26
|
+
codeLanguage?: NiceApiCodeLanguage | false;
|
|
27
|
+
}
|
|
28
|
+
/** The collection as Markdown. */
|
|
29
|
+
export declare function collectionToMarkdown(collection: NiceApiCollection, options?: NiceApiMarkdownOptions): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MD5 (RFC 1321) — Web Crypto has no MD5, and HTTP Digest auth still mostly uses it. Internal to
|
|
3
|
+
* the transport; not for anything security-sensitive beyond what the Digest scheme asks.
|
|
4
|
+
*/
|
|
5
|
+
/** The MD5 digest of `input` (text as UTF-8) as lower-case hex. */
|
|
6
|
+
export declare function md5Hex(input: string | Uint8Array): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NiceApiCollection, NiceApiRequest, NiceApiSchema } from './model';
|
|
2
|
+
export interface NiceApiMockOptions {
|
|
3
|
+
/** Looks a `$ref` up (`#/components/schemas/Pet` → its schema). */
|
|
4
|
+
resolveRef?: (ref: string) => NiceApiSchema | undefined;
|
|
5
|
+
/** How deep nested objects go before they stop (cycles stop at once). Default 6. */
|
|
6
|
+
maxDepth?: number;
|
|
7
|
+
/** Items per array. Default 1. */
|
|
8
|
+
arrayItems?: number;
|
|
9
|
+
/** Clock for date examples (tests). */
|
|
10
|
+
now?: () => Date;
|
|
11
|
+
/** `request` skips read-only properties, `response` write-only ones. */
|
|
12
|
+
usage?: 'request' | 'response';
|
|
13
|
+
}
|
|
14
|
+
/** `resolveRef` over a collection's (or an OpenAPI document's) named schemas. */
|
|
15
|
+
export declare function schemaResolver(schemas: Record<string, NiceApiSchema> | undefined): (ref: string) => NiceApiSchema | undefined;
|
|
16
|
+
/** An example value for `schema`: its example, default, const or first enum value, else made up. */
|
|
17
|
+
export declare function mockFromSchema(schema: NiceApiSchema | undefined, options?: NiceApiMockOptions): unknown;
|
|
18
|
+
/** A schema describing an example value (for exporting a request whose body has no schema). */
|
|
19
|
+
export declare function inferSchema(value: unknown): NiceApiSchema;
|
|
20
|
+
/** A mock answer for a request: its saved example, else its documented 2xx response's example or schema. */
|
|
21
|
+
export declare function mockResponse(request: NiceApiRequest, collection?: Pick<NiceApiCollection, 'schemas'>): {
|
|
22
|
+
status: number;
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
body: string;
|
|
25
|
+
};
|