mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 13:44:54 +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) => {
|
const options = parent.oneOf.map((subSchema, idx) => {
|
||||||
return {
|
return {
|
||||||
value: subSchema.title,
|
value: subSchema.discriminant(parent.discriminatorProp),
|
||||||
idx,
|
idx,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,10 +63,11 @@ export class MediaTypeModel {
|
||||||
const sample = Sampler.sample(subSchema.rawSchema as any, samplerOptions, parser.spec);
|
const sample = Sampler.sample(subSchema.rawSchema as any, samplerOptions, parser.spec);
|
||||||
|
|
||||||
if (this.schema.discriminatorProp && typeof sample === 'object' && sample) {
|
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.discriminant()] = new ExampleModel(
|
||||||
this.examples[subSchema.title] = new ExampleModel(
|
|
||||||
parser,
|
parser,
|
||||||
{
|
{
|
||||||
value: sample,
|
value: sample,
|
||||||
|
|
|
@ -102,6 +102,26 @@ export class SchemaModel {
|
||||||
this.activeOneOf = idx;
|
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) {
|
hasType(type: string) {
|
||||||
return this.type === type || (Array.isArray(this.type) && this.type.includes(type));
|
return this.type === type || (Array.isArray(this.type) && this.type.includes(type));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user