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
|
type: string
|
||||||
format: uri
|
format: uri
|
||||||
description: This URL will be called by the server when the desired event will occur
|
description: This URL will be called by the server when the desired event will occur
|
||||||
example: https://myserver.com/send/callback/here
|
|
||||||
eventName:
|
eventName:
|
||||||
type: string
|
type: string
|
||||||
description: Event name for the subscription
|
description: Event name for the subscription
|
||||||
|
@ -1193,7 +1192,7 @@ x-webhooks:
|
||||||
summary: New pet
|
summary: New pet
|
||||||
description: Information about a new pet in the systems
|
description: Information about a new pet in the systems
|
||||||
operationId: newPet
|
operationId: newPet
|
||||||
tags:
|
tags:
|
||||||
- pet
|
- pet
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
|
@ -1202,4 +1201,4 @@ x-webhooks:
|
||||||
$ref: "#/components/schemas/Pet"
|
$ref: "#/components/schemas/Pet"
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: Return a 200 status to indicate that the data was received successfully
|
description: Return a 200 status to indicate that the data was received successfully
|
||||||
|
|
|
@ -26,7 +26,7 @@ const specUrl =
|
||||||
(userUrl && userUrl[1]) || (swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml');
|
(userUrl && userUrl[1]) || (swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml');
|
||||||
|
|
||||||
let store;
|
let store;
|
||||||
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 3 };
|
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 3, disableDefaultSample: true };
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
const spec = await loadAndBundleSpec(specUrl);
|
const spec = await loadAndBundleSpec(specUrl);
|
||||||
|
|
|
@ -42,6 +42,7 @@ export interface RedocRawOptions {
|
||||||
maxDisplayedEnumValues?: number;
|
maxDisplayedEnumValues?: number;
|
||||||
ignoreNamedSchemas?: string[] | string;
|
ignoreNamedSchemas?: string[] | string;
|
||||||
hideSchemaPattern?: boolean;
|
hideSchemaPattern?: boolean;
|
||||||
|
disableDefaultSample?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
||||||
|
@ -196,6 +197,7 @@ export class RedocNormalizedOptions {
|
||||||
|
|
||||||
ignoreNamedSchemas: Set<string>;
|
ignoreNamedSchemas: Set<string>;
|
||||||
hideSchemaPattern: boolean;
|
hideSchemaPattern: boolean;
|
||||||
|
disableDefaultSample: boolean;
|
||||||
|
|
||||||
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
|
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
|
||||||
raw = { ...defaults, ...raw };
|
raw = { ...defaults, ...raw };
|
||||||
|
@ -257,5 +259,6 @@ export class RedocNormalizedOptions {
|
||||||
: raw.ignoreNamedSchemas?.split(',').map((s) => s.trim());
|
: raw.ignoreNamedSchemas?.split(',').map((s) => s.trim());
|
||||||
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
||||||
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
||||||
|
this.disableDefaultSample = argValueToBoolean(raw.disableDefaultSample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,11 +44,11 @@ export class MediaTypeModel {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (isJsonLike(name)) {
|
} 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 = {
|
const samplerOptions = {
|
||||||
skipReadOnly: this.isRequestType,
|
skipReadOnly: this.isRequestType,
|
||||||
skipNonRequired: this.isRequestType && this.onlyRequiredInSamples,
|
skipNonRequired: this.isRequestType && this.onlyRequiredInSamples,
|
||||||
|
@ -74,12 +74,22 @@ export class MediaTypeModel {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (this.schema) {
|
} 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 = {
|
this.examples = {
|
||||||
default: new ExampleModel(
|
default: new ExampleModel(
|
||||||
parser,
|
parser,
|
||||||
{
|
{ value: sampledData },
|
||||||
value: Sampler.sample(info.schema, samplerOptions, parser.spec),
|
|
||||||
},
|
|
||||||
this.name,
|
this.name,
|
||||||
info.encoding,
|
info.encoding,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user