Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use schema's title when available in {one,any,all}Of applicators #744

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 18 additions & 3 deletions library/src/components/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ export const Schema: React.FunctionComponent<Props> = ({
<Schema
key={idx}
schema={s}
schemaName={idx === 0 ? 'Adheres to:' : 'Or to:'}
schemaName={SchemaHelpers.applicatorSchemaName(
idx,
'Adheres to',
'Or to',
s.title(),
)}
/>
))}
{schema.anyOf() &&
Expand All @@ -290,7 +295,12 @@ export const Schema: React.FunctionComponent<Props> = ({
<Schema
key={idx}
schema={s}
schemaName={idx === 0 ? 'Can adhere to:' : 'Or to:'}
schemaName={SchemaHelpers.applicatorSchemaName(
idx,
'Can adhere to',
'Or to',
s.title(),
)}
/>
))}
{schema.allOf() &&
Expand All @@ -300,7 +310,12 @@ export const Schema: React.FunctionComponent<Props> = ({
<Schema
key={idx}
schema={s}
schemaName={idx === 0 ? 'Consists of:' : 'And with:'}
schemaName={SchemaHelpers.applicatorSchemaName(
derberg marked this conversation as resolved.
Show resolved Hide resolved
idx,
'Consists of',
'And of',
s.title(),
)}
/>
))}
{schema.not() && (
Expand Down
14 changes: 14 additions & 0 deletions library/src/helpers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ export class SchemaHelpers {
return type;
}

static applicatorSchemaName(
idx: number,
firstCase: string,
otherCases: string,
title?: string,
) {
const suffix = (title !== null && ` ${title}:`) || `:`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title can also be undefined it seems. This introduced Consists of undefined: for us. So this check needs to be improved.

if (idx === 0) {
return `${firstCase}${suffix}`;
} else {
return `${otherCases}${suffix}`;
}
}

static prettifyValue(value: any, strict = true): string {
const typeOf = typeof value;
if (typeOf === 'string') {
Expand Down
1 change: 1 addition & 0 deletions playground/src/specs/streetlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ components:
union:
type: [string, number]
objectWithKey:
title: objectWithKey
type: object
propertyNames:
format: email
Expand Down