@mettlecast/domain-cli 0.2.11 → 0.2.12

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.
@@ -93,6 +93,7 @@ export async function buildRegistry(domainRoot) {
93
93
  requestSchema: latestVersion?.requestSchema,
94
94
  responseSchema: latestVersion?.responseSchema,
95
95
  versions: versionSnapshots.length > 0 ? versionSnapshots : undefined,
96
+ examples: e['examples'],
96
97
  };
97
98
  }));
98
99
  const webhooks = paths.webhooks.flatMap((filePath, i) => (webhookExports[i] ?? [])
@@ -13,6 +13,10 @@ export interface CatalogApi {
13
13
  requestSchema?: Record<string, unknown>;
14
14
  responseSchema?: Record<string, unknown>;
15
15
  }>;
16
+ examples?: {
17
+ request?: Record<string, unknown>;
18
+ response?: Record<string, unknown>;
19
+ };
16
20
  }
17
21
  /** A single action entry in the catalog. */
18
22
  export interface CatalogAction {
@@ -67,6 +67,7 @@ export async function runBuildCatalog(tibDir) {
67
67
  requestSchema: api['requestSchema'],
68
68
  responseSchema: api['responseSchema'],
69
69
  versions: api['versions'],
70
+ examples: api['examples'],
70
71
  });
71
72
  }
72
73
  const actions = registry['actions'] ?? [];
@@ -139,19 +139,17 @@ export async function runValidate(domainRoot, exitOnFailure = true, config = { m
139
139
  message: `API '${api.id}' (${api.method} ${api.path}) has invalid method "${api.method}". Use one of: ${[...VALID_METHODS].join(', ')}.`,
140
140
  });
141
141
  }
142
- function hasExampleOrDefault(schema) {
143
- if (!schema)
144
- return false;
145
- if (schema['default'] !== undefined)
146
- return true;
147
- const examples = schema['examples'] ?? schema['example'];
148
- return Array.isArray(examples) && examples.length > 0;
149
- }
150
- if (api.requestSchema && !hasExampleOrDefault(api.requestSchema)) {
151
- warnings.push(`API '${api.id}' (${api.method} ${api.path}) request schema has no example data. Add .default({...}) to your Zod schema.`);
142
+ if (!api.examples?.request) {
143
+ errors.push({
144
+ code: 'MISSING_API_REQUEST_EXAMPLE',
145
+ message: `API '${api.id}' (${api.method} ${api.path}) has no request example. Add examples: { request: {...}, response: {...} } to the defineApi config.`,
146
+ });
152
147
  }
153
- if (api.responseSchema && !hasExampleOrDefault(api.responseSchema)) {
154
- warnings.push(`API '${api.id}' (${api.method} ${api.path}) response schema has no example data. Add .default({...}) to your Zod schema.`);
148
+ if (!api.examples?.response) {
149
+ errors.push({
150
+ code: 'MISSING_API_RESPONSE_EXAMPLE',
151
+ message: `API '${api.id}' (${api.method} ${api.path}) has no response example. Add examples: { request: {...}, response: {...} } to the defineApi config.`,
152
+ });
155
153
  }
156
154
  }
157
155
  const rawPathErrors = await checkRawPathViolations(registry.domainRoot, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mettlecast/domain-cli",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -130,6 +130,7 @@ export async function buildRegistry(domainRoot: string): Promise<BuildResult> {
130
130
  requestSchema: latestVersion?.requestSchema,
131
131
  responseSchema: latestVersion?.responseSchema,
132
132
  versions: versionSnapshots.length > 0 ? versionSnapshots : undefined,
133
+ examples: (e['examples'] as { request?: Record<string, unknown>; response?: Record<string, unknown> } | undefined),
133
134
  };
134
135
  })
135
136
  );
@@ -13,6 +13,7 @@ export interface CatalogApi {
13
13
  requestSchema?: Record<string, unknown>;
14
14
  responseSchema?: Record<string, unknown>;
15
15
  versions?: Array<{ version: string; requestSchema?: Record<string, unknown>; responseSchema?: Record<string, unknown> }>;
16
+ examples?: { request?: Record<string, unknown>; response?: Record<string, unknown> };
16
17
  }
17
18
 
18
19
  /** A single action entry in the catalog. */
@@ -163,6 +164,7 @@ export async function runBuildCatalog(tibDir?: string): Promise<DomainCatalog> {
163
164
  requestSchema: api['requestSchema'] as Record<string, unknown> | undefined,
164
165
  responseSchema: api['responseSchema'] as Record<string, unknown> | undefined,
165
166
  versions: api['versions'] as CatalogApi['versions'],
167
+ examples: api['examples'] as CatalogApi['examples'],
166
168
  });
167
169
  }
168
170
 
@@ -195,17 +195,17 @@ export async function runValidate(
195
195
  message: `API '${api.id}' (${api.method} ${api.path}) has invalid method "${api.method}". Use one of: ${[...VALID_METHODS].join(', ')}.`,
196
196
  });
197
197
  }
198
- function hasExampleOrDefault(schema: Record<string, unknown> | undefined): boolean {
199
- if (!schema) return false;
200
- if (schema['default'] !== undefined) return true;
201
- const examples = schema['examples'] ?? schema['example'];
202
- return Array.isArray(examples) && examples.length > 0;
203
- }
204
- if (api.requestSchema && !hasExampleOrDefault(api.requestSchema)) {
205
- warnings.push(`API '${api.id}' (${api.method} ${api.path}) request schema has no example data. Add .default({...}) to your Zod schema.`);
198
+ if (!api.examples?.request) {
199
+ errors.push({
200
+ code: 'MISSING_API_REQUEST_EXAMPLE',
201
+ message: `API '${api.id}' (${api.method} ${api.path}) has no request example. Add examples: { request: {...}, response: {...} } to the defineApi config.`,
202
+ });
206
203
  }
207
- if (api.responseSchema && !hasExampleOrDefault(api.responseSchema)) {
208
- warnings.push(`API '${api.id}' (${api.method} ${api.path}) response schema has no example data. Add .default({...}) to your Zod schema.`);
204
+ if (!api.examples?.response) {
205
+ errors.push({
206
+ code: 'MISSING_API_RESPONSE_EXAMPLE',
207
+ message: `API '${api.id}' (${api.method} ${api.path}) has no response example. Add examples: { request: {...}, response: {...} } to the defineApi config.`,
208
+ });
209
209
  }
210
210
  }
211
211