Skip to content

Commit 0ad49ec

Browse files
authored
remove examples from schema (#890)
1 parent 40716fb commit 0ad49ec

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

Diff for: src/framework/types.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface Options extends ajv.Options {
4343
ajvFormats?: FormatsPluginOptions;
4444
}
4545

46-
export interface RequestValidatorOptions extends Options, ValidateRequestOpts {}
46+
export interface RequestValidatorOptions extends Options, ValidateRequestOpts { }
4747

4848
export type ValidateRequestOpts = {
4949
allowUnknownQueryParameters?: boolean;
@@ -240,7 +240,7 @@ export namespace OpenAPIV3 {
240240
in: string;
241241
}
242242

243-
export interface HeaderObject extends ParameterBaseObject {}
243+
export interface HeaderObject extends ParameterBaseObject { }
244244

245245
interface ParameterBaseObject {
246246
description?: string;
@@ -317,6 +317,7 @@ export namespace OpenAPIV3 {
317317
xml?: XMLObject;
318318
externalDocs?: ExternalDocumentationObject;
319319
example?: any;
320+
examples?: any;
320321
deprecated?: boolean;
321322

322323
// Express-openapi-validator specific properties

Diff for: src/middlewares/parsers/schema.preprocessor.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type Schema = ReferenceObject | SchemaObject;
7474
if (!Array.prototype['flatMap']) {
7575
// polyfill flatMap
7676
// TODO remove me when dropping node 10 support
77-
Array.prototype['flatMap'] = function(lambda) {
77+
Array.prototype['flatMap'] = function (lambda) {
7878
return Array.prototype.concat.apply([], this.map(lambda));
7979
};
8080
Object.defineProperty(Array.prototype, 'flatMap', { enumerable: false });
@@ -288,6 +288,7 @@ export class SchemaPreprocessor {
288288
this.handleSerDes(pschema, nschema, options);
289289
this.handleReadonly(pschema, nschema, options);
290290
this.processDiscriminator(pschema, nschema, options);
291+
this.removeExamples(pschema, nschema, options)
291292
}
292293
}
293294
}
@@ -443,6 +444,20 @@ export class SchemaPreprocessor {
443444
}
444445
}
445446

447+
private removeExamples(
448+
parent: OpenAPIV3.SchemaObject,
449+
schema: OpenAPIV3.SchemaObject,
450+
opts,
451+
) {
452+
if (schema.type !== 'object') return;
453+
if (schema?.example) {
454+
delete schema.example
455+
}
456+
if (schema?.examples) {
457+
delete schema.examples
458+
}
459+
}
460+
446461
private handleReadonly(
447462
parent: OpenAPIV3.SchemaObject,
448463
schema: OpenAPIV3.SchemaObject,
@@ -591,7 +606,7 @@ export class SchemaPreprocessor {
591606
) =>
592607
// if name or ref exists and are equal
593608
(opParam['name'] && opParam['name'] === pathParam['name']) ||
594-
(opParam['$ref'] && opParam['$ref'] === pathParam['$ref']);
609+
(opParam['$ref'] && opParam['$ref'] === pathParam['$ref']);
595610

596611
// Add Path level query param to list ONLY if there is not already an operation-level query param by the same name.
597612
for (const param of parameters) {

Diff for: test/356.campaign.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ components:
6868
format: date-time
6969
endDate:
7070
type: string
71-
format: date-time
71+
format: date-time
72+
example:
73+
type: string
74+
example:
75+
name: 'hi'
76+
description: 'yo'

0 commit comments

Comments
 (0)