@mettlecast/domain-cli 0.2.10 → 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.
- package/dist/builder/build-registry.js +1 -0
- package/dist/commands/build-catalog.d.ts +4 -0
- package/dist/commands/build-catalog.js +1 -0
- package/dist/commands/validate.js +10 -12
- package/package.json +1 -1
- package/src/builder/build-registry.ts +1 -0
- package/src/commands/build-catalog.ts +2 -0
- package/src/commands/validate.ts +10 -10
|
@@ -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 {
|
|
@@ -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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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 (
|
|
154
|
-
|
|
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
|
@@ -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
|
|
package/src/commands/validate.ts
CHANGED
|
@@ -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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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 (
|
|
208
|
-
|
|
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
|
|