2021-04-22 10:07:10 +02:00
import { Request , Response } from 'express' ;
import Controller from '../controller' ;
2022-06-22 12:49:18 +02:00
import { IUnleashConfig , IUnleashServices } from '../../types' ;
2021-04-22 10:07:10 +02:00
import { Logger } from '../../logger' ;
import AddonService from '../../services/addon-service' ;
2021-01-19 10:42:45 +01:00
2021-09-14 19:58:48 +02:00
import { extractUsername } from '../../util/extract-user' ;
2021-08-12 15:04:37 +02:00
import {
CREATE_ADDON ,
DELETE_ADDON ,
2022-06-22 12:49:18 +02:00
NONE ,
UPDATE_ADDON ,
2021-08-12 15:04:37 +02:00
} from '../../types/permissions' ;
2021-09-14 19:58:48 +02:00
import { IAuthRequest } from '../unleash-types' ;
2022-07-01 08:06:33 +02:00
import { createRequestSchema } from '../../openapi/util/create-request-schema' ;
import { createResponseSchema } from '../../openapi/util/create-response-schema' ;
2022-06-22 12:49:18 +02:00
import { OpenApiService } from '../../services/openapi-service' ;
import { AddonSchema , addonSchema } from '../../openapi/spec/addon-schema' ;
import { serializeDates } from '../../types/serialize-dates' ;
import { AddonsSchema , addonsSchema } from '../../openapi/spec/addons-schema' ;
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
import {
emptyResponse ,
getStandardResponses ,
} from '../../openapi/util/standard-responses' ;
import { AddonCreateUpdateSchema } from 'lib/openapi/spec/addon-create-update-schema' ;
2022-06-22 12:49:18 +02:00
type AddonServices = Pick < IUnleashServices , ' addonService ' | ' openApiService ' > ;
const PATH = '/' ;
2021-01-19 10:42:45 +01:00
class AddonController extends Controller {
2021-04-22 10:07:10 +02:00
private logger : Logger ;
private addonService : AddonService ;
2022-06-22 12:49:18 +02:00
private openApiService : OpenApiService ;
2021-04-22 10:07:10 +02:00
constructor (
config : IUnleashConfig ,
2022-06-22 12:49:18 +02:00
{ addonService , openApiService } : AddonServices ,
2021-04-22 10:07:10 +02:00
) {
2021-01-19 10:42:45 +01:00
super ( config ) ;
2021-08-12 15:04:37 +02:00
this . logger = config . getLogger ( '/admin-api/addon.ts' ) ;
2021-01-19 10:42:45 +01:00
this . addonService = addonService ;
2022-06-22 12:49:18 +02:00
this . openApiService = openApiService ;
this . route ( {
method : 'get' ,
path : '' ,
permission : NONE ,
handler : this.getAddons ,
middleware : [
openApiService . validPath ( {
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
summary : 'Get all addons and providers' ,
description :
'Retrieve all addons and providers that are defined on this Unleash instance.' ,
2022-08-12 11:37:57 +02:00
tags : [ 'Addons' ] ,
2022-06-22 12:49:18 +02:00
operationId : 'getAddons' ,
responses : {
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
. . . getStandardResponses ( 401 ) ,
2022-06-22 12:49:18 +02:00
200 : createResponseSchema ( 'addonsSchema' ) ,
} ,
} ) ,
] ,
} ) ;
this . route ( {
method : 'post' ,
path : '' ,
handler : this.createAddon ,
permission : CREATE_ADDON ,
middleware : [
openApiService . validPath ( {
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
summary : 'Create a new addon' ,
description :
'Create an addon instance. The addon must use one of the providers available on this Unleash instance.' ,
2022-08-12 11:37:57 +02:00
tags : [ 'Addons' ] ,
2022-06-22 12:49:18 +02:00
operationId : 'createAddon' ,
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
requestBody : createRequestSchema ( 'addonCreateUpdateSchema' ) ,
responses : {
200 : createResponseSchema ( 'addonSchema' ) ,
. . . getStandardResponses ( 400 , 401 , 403 , 413 , 415 ) ,
} ,
2022-06-22 12:49:18 +02:00
} ) ,
] ,
} ) ;
2021-01-19 10:42:45 +01:00
2022-06-22 12:49:18 +02:00
this . route ( {
method : 'get' ,
path : ` ${ PATH } :id ` ,
handler : this.getAddon ,
permission : NONE ,
middleware : [
openApiService . validPath ( {
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
summary : 'Get a specific addon' ,
description :
'Retrieve information about the addon whose ID matches the ID in the request URL.' ,
2022-08-12 11:37:57 +02:00
tags : [ 'Addons' ] ,
2022-06-22 12:49:18 +02:00
operationId : 'getAddon' ,
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
responses : {
200 : createResponseSchema ( 'addonSchema' ) ,
. . . getStandardResponses ( 401 ) ,
} ,
2022-06-22 12:49:18 +02:00
} ) ,
] ,
} ) ;
this . route ( {
method : 'put' ,
path : ` ${ PATH } :id ` ,
handler : this.updateAddon ,
permission : UPDATE_ADDON ,
middleware : [
openApiService . validPath ( {
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
summary : 'Update an addon' ,
description : ` Update the addon with a specific ID. Any fields in the update object will be updated. Properties that are not included in the update object will not be affected. To empty a property, pass \` null \` as that property's value.
Note : passing \ ` null \` as a value for the description property will set it to an empty string. ` ,
2022-08-12 11:37:57 +02:00
tags : [ 'Addons' ] ,
2022-06-22 12:49:18 +02:00
operationId : 'updateAddon' ,
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
requestBody : createRequestSchema ( 'addonCreateUpdateSchema' ) ,
responses : {
200 : createResponseSchema ( 'addonSchema' ) ,
. . . getStandardResponses ( 400 , 401 , 403 , 413 , 415 ) ,
} ,
2022-06-22 12:49:18 +02:00
} ) ,
] ,
} ) ;
this . route ( {
method : 'delete' ,
path : ` ${ PATH } :id ` ,
handler : this.deleteAddon ,
acceptAnyContentType : true ,
permission : DELETE_ADDON ,
middleware : [
openApiService . validPath ( {
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
summary : 'Delete an addon' ,
description :
'Delete the addon specified by the ID in the request path.' ,
2022-08-12 11:37:57 +02:00
tags : [ 'Addons' ] ,
2022-06-22 12:49:18 +02:00
operationId : 'deleteAddon' ,
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
responses : {
200 : emptyResponse ,
. . . getStandardResponses ( 401 , 403 ) ,
} ,
2022-06-22 12:49:18 +02:00
} ) ,
] ,
} ) ;
2021-01-19 10:42:45 +01:00
}
2022-06-22 12:49:18 +02:00
async getAddons ( req : Request , res : Response < AddonsSchema > ) : Promise < void > {
2021-08-13 10:36:19 +02:00
const addons = await this . addonService . getAddons ( ) ;
const providers = this . addonService . getProviderDefinitions ( ) ;
2022-06-22 12:49:18 +02:00
this . openApiService . respondWithValidation ( 200 , res , addonsSchema . $id , {
addons : serializeDates ( addons ) ,
providers : serializeDates ( providers ) ,
} ) ;
2021-01-19 10:42:45 +01:00
}
2021-08-12 15:04:37 +02:00
async getAddon (
req : Request < { id : number } , any , any , any > ,
2022-06-22 12:49:18 +02:00
res : Response < AddonSchema > ,
2021-08-12 15:04:37 +02:00
) : Promise < void > {
2021-01-19 10:42:45 +01:00
const { id } = req . params ;
2021-08-13 10:36:19 +02:00
const addon = await this . addonService . getAddon ( id ) ;
2022-06-22 12:49:18 +02:00
this . openApiService . respondWithValidation (
200 ,
res ,
addonSchema . $id ,
serializeDates ( addon ) ,
) ;
2021-01-19 10:42:45 +01:00
}
2021-08-12 15:04:37 +02:00
async updateAddon (
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
req : IAuthRequest < { id : number } , any , AddonCreateUpdateSchema , any > ,
2022-06-22 12:49:18 +02:00
res : Response < AddonSchema > ,
2021-08-12 15:04:37 +02:00
) : Promise < void > {
2021-01-19 10:42:45 +01:00
const { id } = req . params ;
2021-09-14 19:58:48 +02:00
const createdBy = extractUsername ( req ) ;
2021-01-19 10:42:45 +01:00
const data = req . body ;
2021-08-13 10:36:19 +02:00
const addon = await this . addonService . updateAddon ( id , data , createdBy ) ;
2022-06-22 12:49:18 +02:00
this . openApiService . respondWithValidation (
200 ,
res ,
addonSchema . $id ,
serializeDates ( addon ) ,
) ;
2021-01-19 10:42:45 +01:00
}
2022-06-22 12:49:18 +02:00
async createAddon (
OpenAPI: addon operations (#3421)
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>
2023-04-18 12:50:34 +02:00
req : IAuthRequest < AddonCreateUpdateSchema , any , any , any > ,
2022-06-22 12:49:18 +02:00
res : Response < AddonSchema > ,
) : Promise < void > {
2021-09-14 19:58:48 +02:00
const createdBy = extractUsername ( req ) ;
2021-01-19 10:42:45 +01:00
const data = req . body ;
2021-08-13 10:36:19 +02:00
const addon = await this . addonService . createAddon ( data , createdBy ) ;
2022-06-22 12:49:18 +02:00
this . openApiService . respondWithValidation (
201 ,
res ,
addonSchema . $id ,
serializeDates ( addon ) ,
) ;
2021-01-19 10:42:45 +01:00
}
2021-08-12 15:04:37 +02:00
async deleteAddon (
2021-09-14 19:58:48 +02:00
req : IAuthRequest < { id : number } , any , any , any > ,
2022-06-22 12:49:18 +02:00
res : Response < void > ,
2021-08-12 15:04:37 +02:00
) : Promise < void > {
2021-01-19 10:42:45 +01:00
const { id } = req . params ;
2021-09-14 19:58:48 +02:00
const username = extractUsername ( req ) ;
2021-08-13 10:36:19 +02:00
await this . addonService . removeAddon ( id , username ) ;
2022-06-22 12:49:18 +02:00
2021-08-13 10:36:19 +02:00
res . status ( 200 ) . end ( ) ;
2021-01-19 10:42:45 +01:00
}
}
2021-04-22 10:07:10 +02:00
export default AddonController ;
2021-01-19 10:42:45 +01:00
module .exports = AddonController ;