fix: discriminator field doesn't change in examples

fixes #524
This commit is contained in:
Roman Hotsiy 2018-06-20 16:33:44 +03:00
parent 133f9f0d12
commit 5dae267a54
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -42,12 +42,18 @@ export class MediaTypeModel {
if (this.schema && this.schema.oneOf) { if (this.schema && this.schema.oneOf) {
this.examples = {}; this.examples = {};
for (const subSchema of this.schema.oneOf) { for (const subSchema of this.schema.oneOf) {
const sample = Sampler.sample(
subSchema.rawSchema,
{ skipReadOnly: this.isRequestType, skipWriteOnly: !this.isRequestType },
parser.spec,
);
if (this.schema.discriminatorProp && typeof sample === 'object' && sample) {
sample[this.schema.discriminatorProp] = subSchema.title;
}
this.examples[subSchema.title] = { this.examples[subSchema.title] = {
value: Sampler.sample( value: sample,
subSchema.rawSchema,
{ skipReadOnly: this.isRequestType, skipWriteOnly: !this.isRequestType },
parser.spec,
),
}; };
} }
} else { } else {