mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
e11fae56e9
This PR updates the OpenAPI schemas for all the operations tagged with "addons". In doing so, I also uncovered a few bugs and inconsistencies. These have also been fixed. ## Changes I've added inline comments to the changed files to call out anything that I think is worth clarifying specifically. As an overall description, this PR does the following: Splits `addon-schema` into `addon-schema` and `addon-create-update-schema`. The former is used when describing addons that exist within Unleash and contain IDs and `created_at` timestamps. The latter is used when creating or updating addons. Adds examples and descriptions to all relevant schemas (and their dependencies). Updates addons operations descriptions and response codes (including the recently introduced 413 and 415). Fixes a bug where the server would crash if it didn't recognize the addon provider (test added). Fixes a bug where updating an addon wouldn't return anything, even if the API said that it would. (test added) Resolves some inconsistencies in handling of addon description. (tests added) ### Addon descriptions when creating addons, descriptions are optional. The original `addonSchema` said they could be `null | string | undefined`. This caused some inconsistencies in return values. Sometimes they were returned, other times not. I've made it so that `descriptions` are now always returned from the API. If it's not defined or if it's set to `null`, the API will return `description: null`. ### `IAddonDto` `IAddonDto`, the type we used internally to model the incoming addons (for create and update) says that `description` is required. This hasn't been true at least since we introduced OpenAPI schemas. As such, the update and insert methods that the service uses were incompatible with the **actual** data that we require. I've changed the type to reflect reality for now. Assuming the tests pass, this **should** all be good, but I'd like the reviewer(s) to give this a think too. --------- Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
57 lines
2.5 KiB
TypeScript
57 lines
2.5 KiB
TypeScript
import { FromSchema } from 'json-schema-to-ts';
|
|
|
|
export const addonParameterSchema = {
|
|
$id: '#/components/schemas/addonParameterSchema',
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['name', 'displayName', 'type', 'required', 'sensitive'],
|
|
description: 'An addon parameter definition.',
|
|
properties: {
|
|
name: {
|
|
type: 'string',
|
|
example: 'emojiIcon',
|
|
description:
|
|
'The name of the parameter as it is used in code. References to this parameter should use this value.',
|
|
},
|
|
displayName: {
|
|
type: 'string',
|
|
example: 'Emoji Icon',
|
|
description:
|
|
'The name of the parameter as it is shown to the end user in the Admin UI.',
|
|
},
|
|
type: {
|
|
type: 'string',
|
|
description:
|
|
'The type of the parameter. Corresponds roughly to [HTML `input` field types](https://developer.mozilla.org/docs/Web/HTML/Element/Input#input_types). Multi-line inut fields are indicated as `textfield` (equivalent to the HTML `textarea` tag).',
|
|
example: 'text',
|
|
},
|
|
description: {
|
|
type: 'string',
|
|
example:
|
|
'The emoji_icon to use when posting messages to slack. Defaults to ":unleash:".',
|
|
description:
|
|
'A description of the parameter. This should explain to the end user what the parameter is used for.',
|
|
},
|
|
placeholder: {
|
|
type: 'string',
|
|
example: ':unleash:',
|
|
description:
|
|
'The default value for this parameter. This value is used if no other value is provided.',
|
|
},
|
|
required: {
|
|
type: 'boolean',
|
|
example: false,
|
|
description:
|
|
'Whether this parameter is required or not. If a parameter is required, you must give it a value when you create the addon. If it is not required it can be left out. It may receive a default value in those cases.',
|
|
},
|
|
sensitive: {
|
|
type: 'boolean',
|
|
example: false,
|
|
description: `Indicates whether this parameter is **sensitive** or not. Unleash will not return sensitive parameters to API requests. It will instead use a number of asterisks to indicate that a value is set, e.g. "******". The number of asterisks does not correlate to the parameter\'s value.`,
|
|
},
|
|
},
|
|
components: {},
|
|
} as const;
|
|
|
|
export type AddonParameterSchema = FromSchema<typeof addonParameterSchema>;
|