Skip to content

Commit 0eb1e66

Browse files
David BeachamRomanHotsiy
authored andcommitted
feat: add x-additionalPropertiesName (#622) (#944)
* Add x-additionalPropertiesName (#622) Supply custom name to be displayed for property name of `additionalProperties`. * Include prettier output for Schema.ts
1 parent c488bbf commit 0eb1e66

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ ReDoc makes use of the following [vendor extensions](https://swagger.io/specific
218218
* [`x-tagGroups`](docs/redoc-vendor-extensions.md#x-tagGroups) - group tags by categories in the side menu
219219
* [`x-servers`](docs/redoc-vendor-extensions.md#x-servers) - ability to specify different servers for API (backported from OpenAPI 3.0)
220220
* [`x-ignoredHeaderParameters`](docs/redoc-vendor-extensions.md#x-ignoredHeaderParameters) - ability to specify header parameter names to ignore
221+
* [`x-additionalPropertiesName`](docs/redoc-vendor-extensions.md#x-additionalPropertiesName) - ability to supply a descriptive name for the additional property keys
221222

222223
### `<redoc>` options object
223224
You can use all of the following options with standalone version on <redoc> tag by kebab-casing them, e.g. `scrollYOffset` becomes `scroll-y-offset` and `expandResponses` becomes `expand-responses`.

docs/redoc-vendor-extensions.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,31 @@ PayPalPayment:
278278

279279
In the example above the names of definitions (`PayPalPayment`) are named differently than
280280
names in the payload (`paypal`) which is not supported by default `discriminator`.
281+
282+
#### x-additionalPropertiesName
283+
**ATTENTION**: This is ReDoc-specific vendor extension. It won't be supported by other tools.
284+
285+
Extends the `additionalProperties` property of the schema object.
286+
287+
| Field Name | Type | Description |
288+
| :------------- | :------: | :---------- |
289+
| x-additionalPropertiesName | string | descriptive name of additional properties keys |
290+
291+
###### Usage in ReDoc
292+
ReDoc uses this extension to display a more descriptive property name in objects with `additionalProperties` when viewing the property list with an `object`.
293+
294+
###### x-additionalPropertiesName example
295+
296+
```yaml
297+
Player:
298+
required:
299+
- name
300+
301+
properties:
302+
name:
303+
type: string
304+
305+
additionalProperties:
306+
x-additionalPropertiesName: attribute-name
307+
type: string
308+
```

src/services/models/Schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ function buildFields(
292292
new FieldModel(
293293
parser,
294294
{
295-
name: 'property name *',
295+
name: (typeof additionalProps === 'object'
296+
? additionalProps['x-additionalPropertiesName'] || 'property name'
297+
: 'property name'
298+
).concat('*'),
296299
required: false,
297300
schema: additionalProps === true ? {} : additionalProps,
298301
kind: 'additionalProperties',

src/utils/openapi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export function isRedocExtension(key: string): boolean {
423423
'x-servers': true,
424424
'x-tagGroups': true,
425425
'x-traitTag': true,
426+
'x-additionalPropertiesName': true,
426427
};
427428

428429
return key in redocExtensions;

0 commit comments

Comments
 (0)