Skip to content

Commit

Permalink
add limit to mapping extension
Browse files Browse the repository at this point in the history
  • Loading branch information
zeapo committed Mar 26, 2020
1 parent 830371b commit 9ff0f3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ export class SchemaModel {
}

const mapping = discriminator.mapping || {};

// Defines if the mapping is exhaustive. This avoids having references
// that overlap with the mapping entries
let isLimitedToMapping = discriminator['x-limitToMapping'] || false;
// if there are no mappings, assume non-exhaustive
if (Object.keys(mapping).length === 0) {
isLimitedToMapping = false;
}

const explicitInversedMapping = {};
for (const name in mapping) {
const $ref = mapping[name];
Expand All @@ -252,7 +261,7 @@ export class SchemaModel {
}
}

const inversedMapping = { ...implicitInversedMapping, ...explicitInversedMapping };
const inversedMapping = isLimitedToMapping ? { ...explicitInversedMapping } : { ...implicitInversedMapping, ...explicitInversedMapping };

const refs: Array<{ $ref; name }> = [];

Expand Down
1 change: 1 addition & 0 deletions src/types/open-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface OpenAPISchema {
export interface OpenAPIDiscriminator {
propertyName: string;
mapping?: { [name: string]: string };
'x-limitToMapping'?: boolean;
}

export interface OpenAPIMediaType {
Expand Down

0 comments on commit 9ff0f3a

Please sign in to comment.