mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 13:44:54 +03:00
disableDefaultSample option
This commit is contained in:
parent
755a9095f5
commit
e5c6221afe
|
@ -505,7 +505,6 @@ paths:
|
|||
type: string
|
||||
format: uri
|
||||
description: This URL will be called by the server when the desired event will occur
|
||||
example: https://myserver.com/send/callback/here
|
||||
eventName:
|
||||
type: string
|
||||
description: Event name for the subscription
|
||||
|
|
|
@ -26,7 +26,7 @@ const specUrl =
|
|||
(userUrl && userUrl[1]) || (swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml');
|
||||
|
||||
let store;
|
||||
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 3 };
|
||||
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 3, disableDefaultSample: true };
|
||||
|
||||
async function init() {
|
||||
const spec = await loadAndBundleSpec(specUrl);
|
||||
|
|
|
@ -42,6 +42,7 @@ export interface RedocRawOptions {
|
|||
maxDisplayedEnumValues?: number;
|
||||
ignoreNamedSchemas?: string[] | string;
|
||||
hideSchemaPattern?: boolean;
|
||||
disableDefaultSample?: boolean;
|
||||
}
|
||||
|
||||
function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
||||
|
@ -196,6 +197,7 @@ export class RedocNormalizedOptions {
|
|||
|
||||
ignoreNamedSchemas: Set<string>;
|
||||
hideSchemaPattern: boolean;
|
||||
disableDefaultSample: boolean;
|
||||
|
||||
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
|
||||
raw = { ...defaults, ...raw };
|
||||
|
@ -257,5 +259,6 @@ export class RedocNormalizedOptions {
|
|||
: raw.ignoreNamedSchemas?.split(',').map((s) => s.trim());
|
||||
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
||||
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
||||
this.disableDefaultSample = argValueToBoolean(raw.disableDefaultSample);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ export class MediaTypeModel {
|
|||
),
|
||||
};
|
||||
} else if (isJsonLike(name)) {
|
||||
this.generateExample(parser, info);
|
||||
this.generateExample(parser, info, options.disableDefaultSample);
|
||||
}
|
||||
}
|
||||
|
||||
generateExample(parser: OpenAPIParser, info: OpenAPIMediaType) {
|
||||
generateExample(parser: OpenAPIParser, info: OpenAPIMediaType, disableDefaultSample: boolean) {
|
||||
const samplerOptions = {
|
||||
skipReadOnly: this.isRequestType,
|
||||
skipNonRequired: this.isRequestType && this.onlyRequiredInSamples,
|
||||
|
@ -74,12 +74,22 @@ export class MediaTypeModel {
|
|||
);
|
||||
}
|
||||
} else if (this.schema) {
|
||||
const sampledData = Sampler.sample(info.schema, samplerOptions, parser.spec);
|
||||
|
||||
if (disableDefaultSample && info.schema) {
|
||||
const properties = parser.deref(info.schema)?.properties || {};
|
||||
Object.keys(properties).map((propName) => {
|
||||
const property = properties[propName];
|
||||
if (!property.example && sampledData[propName] !== undefined) {
|
||||
delete sampledData[propName];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.examples = {
|
||||
default: new ExampleModel(
|
||||
parser,
|
||||
{
|
||||
value: Sampler.sample(info.schema, samplerOptions, parser.spec),
|
||||
},
|
||||
{ value: sampledData },
|
||||
this.name,
|
||||
info.encoding,
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue
Block a user