Skip to content

Commit

Permalink
clients/web/docs: deduplicate widget when schema accepts scalar and a…
Browse files Browse the repository at this point in the history
…rray of the same type

For schemas that are like `uuid | uuid[]`, we don't want the widget twice. So we remove the array schema if there is a non-array schema with the same type.
  • Loading branch information
frankie567 committed Jul 9, 2024
1 parent 913fb30 commit a57d064
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions clients/apps/web/src/components/Documentation/ParameterWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getParameterName,
getUnionSchemas,
hasSelectorWidget,
isArraySchema,
isDereferenced,
resolveSchemaMinMax,
} from './openapi'
Expand Down Expand Up @@ -301,9 +302,19 @@ const UnionParameterWidget = ({
const nullSchema = schemas.find((schema) => schema.type === 'null')
const nonNullSchemas = schemas.filter((schema) => schema.type !== 'null')

// For schemas that are like `uuid | uuid[]`, we don't want the widget twice
// So we remove the array schema if there is a non-array schema with the same type
const deduplicatedArraySchemas = nonNullSchemas.filter(
(schema) =>
!isArraySchema(schema) ||
!nonNullSchemas.some(
(s) => isDereferenced(schema.items) && s.type === schema.items.type,
),
)

return (
<div className="flex flex-row items-center gap-2">
{nonNullSchemas.map((schema, index) => (
{deduplicatedArraySchemas.map((schema, index) => (
<ParameterWidget
key={index}
schema={schema}
Expand Down Expand Up @@ -335,8 +346,6 @@ const ParameterWidget = ({
return null
}

console.log('ParameterWidget', schema)

const unionSchemas = getUnionSchemas(schema)
if (unionSchemas) {
return (
Expand Down

0 comments on commit a57d064

Please sign in to comment.