mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 00:26:34 +03:00
feat: add x-explicitMappingOnly extension (#1215)
This commit is contained in:
parent
830371b5d1
commit
ea5b0aabf9
|
@ -306,3 +306,37 @@ Player:
|
|||
x-additionalPropertiesName: attribute-name
|
||||
type: string
|
||||
```
|
||||
|
||||
#### x-explicitMappingOnly
|
||||
**ATTENTION**: This is ReDoc-specific vendor extension. It won't be supported by other tools.
|
||||
|
||||
Extends the `discriminator` property of the schema object.
|
||||
|
||||
| Field Name | Type | Description |
|
||||
| :------------- | :------: | :---------- |
|
||||
| x-explicitMappingOnly | boolean | limit the discriminator selectpicker to the explicit mappings only |
|
||||
|
||||
###### Usage in ReDoc
|
||||
ReDoc uses this extension to filter the `discriminator` mappings shown in the selectpicker.
|
||||
When set to `true`, the selectpicker will only list the the explicitly defined mappings. When `false`,
|
||||
the default behavior is kept, i.e. explicit and implicit mappings will be shown.
|
||||
|
||||
###### x-explicitMappingOnly example
|
||||
|
||||
|
||||
```yaml
|
||||
Pet:
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- photoUrls
|
||||
discriminator:
|
||||
propertyName: petType
|
||||
x-explicitMappingOnly: true
|
||||
mapping:
|
||||
cat: "#/components/schemas/Cat"
|
||||
bee: "#/components/schemas/HoneyBee"
|
||||
```
|
||||
|
||||
Will show in the selectpicker only the items `cat` and `bee`, even though the `Dog` class inherits from
|
||||
the `Pet` class.
|
||||
|
|
|
@ -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-explicitMappingOnly'] || 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];
|
||||
|
@ -252,7 +261,7 @@ export class SchemaModel {
|
|||
}
|
||||
}
|
||||
|
||||
const inversedMapping = { ...implicitInversedMapping, ...explicitInversedMapping };
|
||||
const inversedMapping = isLimitedToMapping ? { ...explicitInversedMapping } : { ...implicitInversedMapping, ...explicitInversedMapping };
|
||||
|
||||
const refs: Array<{ $ref; name }> = [];
|
||||
|
||||
|
|
1
src/types/open-api.d.ts
vendored
1
src/types/open-api.d.ts
vendored
|
@ -144,6 +144,7 @@ export interface OpenAPISchema {
|
|||
export interface OpenAPIDiscriminator {
|
||||
propertyName: string;
|
||||
mapping?: { [name: string]: string };
|
||||
'x-explicitMappingOnly'?: boolean;
|
||||
}
|
||||
|
||||
export interface OpenAPIMediaType {
|
||||
|
|
|
@ -579,6 +579,7 @@ export function isRedocExtension(key: string): boolean {
|
|||
'x-tagGroups': true,
|
||||
'x-traitTag': true,
|
||||
'x-additionalPropertiesName': true,
|
||||
'x-explicitMappingOnly': true,
|
||||
};
|
||||
|
||||
return key in redocExtensions;
|
||||
|
|
Loading…
Reference in New Issue
Block a user