Skip to content

Commit

Permalink
open-api addon controller (#1721)
Browse files Browse the repository at this point in the history
* open-api addon controller

* bug fixes

* bug fixes

* resolve merge conflict

* bug fix

* bug fix

* bug fix

* PR comments

* PR comments

* Resolve merge conflics

* Resolve merge conflics

* bug and tests
  • Loading branch information
andreas-unleash committed Jun 22, 2022
1 parent b3320bf commit 66452e2
Show file tree
Hide file tree
Showing 14 changed files with 641 additions and 48 deletions.
28 changes: 14 additions & 14 deletions .do/deploy.template.yaml
@@ -1,18 +1,18 @@
spec:
name: unleash
services:
- name: unleash-server
git:
branch: main
repo_clone_url: https://github.com/Unleash/unleash.git
build_command: 'yarn build'
run_command: 'yarn start'
envs:
- key: DATABASE_URL
scope: RUN_TIME
value: ${unleash-db.DATABASE_URL}
- key: UNLEASH_URL
scope: RUN_TIME
value: ${APP_URL}
- name: unleash-server
git:
branch: main
repo_clone_url: https://github.com/Unleash/unleash.git
build_command: 'yarn build'
run_command: 'yarn start'
envs:
- key: DATABASE_URL
scope: RUN_TIME
value: ${unleash-db.DATABASE_URL}
- key: UNLEASH_URL
scope: RUN_TIME
value: ${APP_URL}
databases:
- name: unleash-db
- name: unleash-db
8 changes: 8 additions & 0 deletions src/lib/openapi/index.ts
Expand Up @@ -49,6 +49,10 @@ import { validateTagTypeSchema } from './spec/validate-tag-type-schema';
import { variantSchema } from './spec/variant-schema';
import { variantsSchema } from './spec/variants-schema';
import { versionSchema } from './spec/version-schema';
import { addonSchema } from './spec/addon-schema';
import { addonsSchema } from './spec/addons-schema';
import { addonParameterSchema } from './spec/addon-parameter-schema';
import { addonTypeSchema } from './spec/addon-type-schema';
import { applicationSchema } from './spec/application-schema';
import { applicationsSchema } from './spec/applications-schema';
import { tagWithVersionSchema } from './spec/tag-with-version-schema';
Expand All @@ -60,6 +64,10 @@ import { exportParametersSchema } from './spec/export-parameters-schema';

// All schemas in `openapi/spec` should be listed here.
export const schemas = {
addonSchema,
addonsSchema,
addonTypeSchema,
addonParameterSchema,
apiTokenSchema,
apiTokensSchema,
applicationSchema,
Expand Down
33 changes: 33 additions & 0 deletions src/lib/openapi/spec/addon-parameter-schema.ts
@@ -0,0 +1,33 @@
import { FromSchema } from 'json-schema-to-ts';

export const addonParameterSchema = {
$id: '#/components/schemas/addonParameterSchema',
type: 'object',
required: ['name', 'displayName', 'type', 'required', 'sensitive'],
properties: {
name: {
type: 'string',
},
displayName: {
type: 'string',
},
type: {
type: 'string',
},
description: {
type: 'string',
},
placeholder: {
type: 'string',
},
required: {
type: 'boolean',
},
sensitive: {
type: 'boolean',
},
},
components: {},
} as const;

export type AddonParameterSchema = FromSchema<typeof addonParameterSchema>;
17 changes: 17 additions & 0 deletions src/lib/openapi/spec/addon-schema.test.ts
@@ -0,0 +1,17 @@
import { validateSchema } from '../validate';
import { AddonSchema } from './addon-schema';

test('addonSchema', () => {
const data: AddonSchema = {
provider: 'some-provider',
enabled: true,
parameters: {
someKey: 'some-value',
},
events: ['some-event'],
};

expect(
validateSchema('#/components/schemas/addonSchema', data),
).toBeUndefined();
});
39 changes: 39 additions & 0 deletions src/lib/openapi/spec/addon-schema.ts
@@ -0,0 +1,39 @@
import { FromSchema } from 'json-schema-to-ts';

export const addonSchema = {
$id: '#/components/schemas/addonSchema',
type: 'object',
required: ['provider', 'enabled', 'parameters', 'events'],
properties: {
id: {
type: 'number',
},
createdAt: {
type: 'string',
format: 'date-time',
nullable: true,
},
provider: {
type: 'string',
},
description: {
type: 'string',
},
enabled: {
type: 'boolean',
},
parameters: {
type: 'object',
additionalProperties: true,
},
events: {
type: 'array',
items: {
type: 'string',
},
},
},
components: {},
} as const;

export type AddonSchema = FromSchema<typeof addonSchema>;
49 changes: 49 additions & 0 deletions src/lib/openapi/spec/addon-type-schema.ts
@@ -0,0 +1,49 @@
import { FromSchema } from 'json-schema-to-ts';
import { addonParameterSchema } from './addon-parameter-schema';
import { tagTypeSchema } from './tag-type-schema';

export const addonTypeSchema = {
$id: '#/components/schemas/addonTypeSchema',
type: 'object',
required: ['name', 'displayName', 'documentationUrl', 'description'],
properties: {
name: {
type: 'string',
},
displayName: {
type: 'string',
},
documentationUrl: {
type: 'string',
},
description: {
type: 'string',
},
tagTypes: {
type: 'array',
items: {
$ref: '#/components/schemas/tagTypeSchema',
},
},
parameters: {
type: 'array',
items: {
$ref: '#/components/schemas/addonParameterSchema',
},
},
events: {
type: 'array',
items: {
type: 'string',
},
},
},
components: {
schemas: {
tagTypeSchema,
addonParameterSchema,
},
},
} as const;

export type AddonTypeSchema = FromSchema<typeof addonTypeSchema>;
36 changes: 36 additions & 0 deletions src/lib/openapi/spec/addons-schema.test.ts
@@ -0,0 +1,36 @@
import { validateSchema } from '../validate';
import { AddonsSchema } from './addons-schema';

test('addonsSchema', () => {
const data: AddonsSchema = {
addons: [
{
parameters: { someKey: 'some-value' },
events: ['some-event'],
enabled: true,
provider: 'some-name',
},
],
providers: [
{
name: 'some-name',
displayName: 'some-display-name',
documentationUrl: 'some-url',
description: 'some-description',
parameters: [
{
name: 'some-name',
displayName: 'some-display-name',
type: 'some-type',
required: true,
sensitive: true,
},
],
},
],
};

expect(
validateSchema('#/components/schemas/addonsSchema', data),
).toBeUndefined();
});
35 changes: 35 additions & 0 deletions src/lib/openapi/spec/addons-schema.ts
@@ -0,0 +1,35 @@
import { FromSchema } from 'json-schema-to-ts';
import { addonSchema } from './addon-schema';
import { addonTypeSchema } from './addon-type-schema';
import { addonParameterSchema } from './addon-parameter-schema';
import { tagTypeSchema } from './tag-type-schema';

export const addonsSchema = {
$id: '#/components/schemas/addonsSchema',
type: 'object',
required: ['addons', 'providers'],
properties: {
addons: {
type: 'array',
items: {
$ref: '#/components/schemas/addonSchema',
},
},
providers: {
type: 'array',
items: {
$ref: '#/components/schemas/addonTypeSchema',
},
},
},
components: {
schemas: {
addonSchema,
addonTypeSchema,
tagTypeSchema,
addonParameterSchema,
},
},
} as const;

export type AddonsSchema = FromSchema<typeof addonsSchema>;

0 comments on commit 66452e2

Please sign in to comment.