Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export default tsPlugin.config(
name: "source/ez",
files: ["express-zod-api/src/*.ts"],
rules: {
complexity: ["error", 18],
complexity: ["error", 16],
"allowed/dependencies": ["error", { packageDir: ezDir }],
"no-restricted-syntax": [
"warn",
Expand Down
17 changes: 10 additions & 7 deletions express-zod-api/src/documentation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,19 @@ export const depictRequestParams = ({
areHeadersEnabled &&
(isHeader?.(name, method, path) ?? defaultIsHeader(name, securityHeaders));

const getLocation = (name: string) =>
isPathParam(name)
? "path"
: isHeaderParam(name)
Comment thread
pullfrog[bot] marked this conversation as resolved.
Outdated
? "header"
: isQueryEnabled
? "query"
: undefined;

return Object.entries(flat.properties).reduce<ParameterObject[]>(
(acc, [name, jsonSchema]) => {
if (!isObject(jsonSchema)) return acc;
const location = isPathParam(name)
? "path"
: isHeaderParam(name)
? "header"
: isQueryEnabled
? "query"
: undefined;
const location = getLocation(name);
if (!location) return acc;
const depicted = asOAS(jsonSchema);
const result =
Expand Down
29 changes: 18 additions & 11 deletions express-zod-api/src/json-schema-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ export const processPropertyNames = (
if (!isOptional) requiredKeys.push(...keys);
};

const mergeExamples = (
Comment thread
pullfrog[bot] marked this conversation as resolved.
Outdated
flat: FlattenObjectSchema,
Comment thread
pullfrog[bot] marked this conversation as resolved.
Outdated
entry: z.core.JSONSchema.BaseSchema,
isOptional: boolean,
) => {
if (!entry.examples?.length) return;
if (isOptional) {
flat.examples = R.concat(flat.examples || [], entry.examples);
} else {
flat.examples = combinations(
flat.examples?.filter(isObject) || [],
entry.examples.filter(isObject),
([a, b]) => R.mergeDeepRight(a, b),
);
}
};

export const flattenIO = (
jsonSchema: z.core.JSONSchema.BaseSchema,
mode: MergeMode = "coerce",
Expand All @@ -91,17 +108,7 @@ export const flattenIO = (
if (entry.description) flat.description ??= entry.description;
stack.push(...processAllOf(entry, mode, isOptional));
stack.push(...processVariants(entry));
if (entry.examples?.length) {
if (isOptional) {
flat.examples = R.concat(flat.examples || [], entry.examples);
} else {
flat.examples = combinations(
flat.examples?.filter(isObject) || [],
entry.examples.filter(isObject),
([a, b]) => R.mergeDeepRight(a, b),
);
}
}
mergeExamples(flat, entry, isOptional);
if (!isJsonObjectSchema(entry)) continue;
stack.push([isOptional, { examples: pullRequestExamples(entry) }]);
if (entry.properties) {
Expand Down
Loading