mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 05:10:20 +03:00
fix: Overrides user-provided discriminator values with object names (#1794)
This commit is contained in:
parent
8b1eea8c0c
commit
969e4b961e
|
@ -33,7 +33,7 @@ export class DiscriminatorDropdown extends React.Component<{
|
|||
|
||||
const options = parent.oneOf.map((subSchema, idx) => {
|
||||
return {
|
||||
value: subSchema.title,
|
||||
value: subSchema.discriminant(parent.discriminatorProp),
|
||||
idx,
|
||||
};
|
||||
});
|
||||
|
|
|
@ -63,10 +63,11 @@ export class MediaTypeModel {
|
|||
const sample = Sampler.sample(subSchema.rawSchema as any, samplerOptions, parser.spec);
|
||||
|
||||
if (this.schema.discriminatorProp && typeof sample === 'object' && sample) {
|
||||
sample[this.schema.discriminatorProp] = subSchema.title;
|
||||
sample[this.schema.discriminatorProp] = subSchema.discriminant(
|
||||
this.schema.discriminatorProp,
|
||||
);
|
||||
}
|
||||
|
||||
this.examples[subSchema.title] = new ExampleModel(
|
||||
this.examples[subSchema.discriminant()] = new ExampleModel(
|
||||
parser,
|
||||
{
|
||||
value: sample,
|
||||
|
|
|
@ -102,6 +102,26 @@ export class SchemaModel {
|
|||
this.activeOneOf = idx;
|
||||
}
|
||||
|
||||
discriminant(propName?): string {
|
||||
if (!propName) {
|
||||
propName = this.schema.discriminator?.propertyName;
|
||||
}
|
||||
|
||||
if (!propName) {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
const properties = this.schema.properties;
|
||||
|
||||
if (!properties) {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
const prop = properties[propName] || null;
|
||||
|
||||
return (prop && prop.enum && prop.enum.length && prop.enum[0]) || this.title;
|
||||
}
|
||||
|
||||
hasType(type: string) {
|
||||
return this.type === type || (Array.isArray(this.type) && this.type.includes(type));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user