Skip to content

Commit

Permalink
Fix default/required & additional properties in parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya committed Jan 5, 2025
1 parent 46a9168 commit f3ac692
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { normalize } from 'pathe'
import type { HTTPMethod, LocalHook } from 'elysia'

Expand Down Expand Up @@ -36,19 +34,33 @@ export const mapProperties = (
// object like schemas.
return Object.entries(schema?.properties as Record<string, TSchema> ?? []).map(([key, value]) => {
const {
type: valueType = undefined,
description,
deprecated,
allowEmptyValue,
style,
explode,
allowReserved,
example,
examples,
...schemaKeywords
...schemaVal
} = value;
let required = schema!.required?.includes(key) ?? false;
if ("default" in schemaVal) required = false;

return {
name: key,
in: name,
description,
required,
deprecated,
allowEmptyValue,
style,
explode,
allowReserved,
example,
examples,
schema: { type: valueType, ...schemaKeywords },
in: name,
name: key,
required: schema!.required?.includes(key) ?? false
}
schema: schemaVal,
} satisfies OpenAPIV3.ParameterObject;
})
}

Expand Down

0 comments on commit f3ac692

Please sign in to comment.