Skip to content

Commit

Permalink
feat: add x-additionalPropertiesName (#622) (#944)
Browse files Browse the repository at this point in the history
* Add x-additionalPropertiesName (#622)

Supply custom name to be displayed for property name of
`additionalProperties`.

* Include prettier output for Schema.ts
  • Loading branch information
David Beacham authored and RomanHotsiy committed Jun 18, 2019
1 parent c488bbf commit 0eb1e66
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ ReDoc makes use of the following [vendor extensions](https://swagger.io/specific
* [`x-tagGroups`](docs/redoc-vendor-extensions.md#x-tagGroups) - group tags by categories in the side menu
* [`x-servers`](docs/redoc-vendor-extensions.md#x-servers) - ability to specify different servers for API (backported from OpenAPI 3.0)
* [`x-ignoredHeaderParameters`](docs/redoc-vendor-extensions.md#x-ignoredHeaderParameters) - ability to specify header parameter names to ignore
* [`x-additionalPropertiesName`](docs/redoc-vendor-extensions.md#x-additionalPropertiesName) - ability to supply a descriptive name for the additional property keys

### `<redoc>` options object
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`.
Expand Down
28 changes: 28 additions & 0 deletions docs/redoc-vendor-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,31 @@ PayPalPayment:

In the example above the names of definitions (`PayPalPayment`) are named differently than
names in the payload (`paypal`) which is not supported by default `discriminator`.

#### x-additionalPropertiesName
**ATTENTION**: This is ReDoc-specific vendor extension. It won't be supported by other tools.

Extends the `additionalProperties` property of the schema object.

| Field Name | Type | Description |
| :------------- | :------: | :---------- |
| x-additionalPropertiesName | string | descriptive name of additional properties keys |

###### Usage in ReDoc
ReDoc uses this extension to display a more descriptive property name in objects with `additionalProperties` when viewing the property list with an `object`.

###### x-additionalPropertiesName example

```yaml
Player:
required:
- name

properties:
name:
type: string

additionalProperties:
x-additionalPropertiesName: attribute-name
type: string
```
5 changes: 4 additions & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ function buildFields(
new FieldModel(
parser,
{
name: 'property name *',
name: (typeof additionalProps === 'object'
? additionalProps['x-additionalPropertiesName'] || 'property name'
: 'property name'
).concat('*'),
required: false,
schema: additionalProps === true ? {} : additionalProps,
kind: 'additionalProperties',
Expand Down
1 change: 1 addition & 0 deletions src/utils/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ export function isRedocExtension(key: string): boolean {
'x-servers': true,
'x-tagGroups': true,
'x-traitTag': true,
'x-additionalPropertiesName': true,
};

return key in redocExtensions;
Expand Down

0 comments on commit 0eb1e66

Please sign in to comment.