From 0eb1e66a10ad3add8db147e2bd6ce6ee333edd68 Mon Sep 17 00:00:00 2001 From: David Beacham Date: Tue, 18 Jun 2019 09:41:48 +0100 Subject: [PATCH] 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 --- README.md | 1 + docs/redoc-vendor-extensions.md | 28 ++++++++++++++++++++++++++++ src/services/models/Schema.ts | 5 ++++- src/utils/openapi.ts | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 16554c6b..97c760aa 100644 --- a/README.md +++ b/README.md @@ -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 ### `` options object You can use all of the following options with standalone version on tag by kebab-casing them, e.g. `scrollYOffset` becomes `scroll-y-offset` and `expandResponses` becomes `expand-responses`. diff --git a/docs/redoc-vendor-extensions.md b/docs/redoc-vendor-extensions.md index 065ea3a2..f02bc9b2 100644 --- a/docs/redoc-vendor-extensions.md +++ b/docs/redoc-vendor-extensions.md @@ -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 +``` diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index fe904a23..6b228711 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -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', diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index d12ab9e2..2637fb1e 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -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;