mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->
This deprecates the `username` properties on api-token schemas, and adds
a `tokenName` property.
DB field `username` has been renamed to `token_name`, migration added
for the rename.
Both `username` and `tokenName` can be used when consuming the service,
but only one of them.
## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
There's a couple of things I'd like to get opinions on and discuss:
- Frontend still uses the deprecated `username` property
- ApiTokenSchema is used both for input and output of `Create`
controller endpoints and should be split out into separate schemas. I'll
set up a task for this
---------
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { FromSchema } from 'json-schema-to-ts';
|
|
import { ApiTokenType } from '../../types/models/api-token';
|
|
|
|
// TODO: (openapi) this schema isn't entirely correct: `project` and `projects`
|
|
// are mutually exclusive.
|
|
//
|
|
// That is, when creating a token, you can provide either `project` _or_
|
|
// `projects`, but *not* both.
|
|
//
|
|
// We should be able to annotate this using `oneOf` and `allOf`, but making
|
|
// `oneOf` only valid for _either_ `project` _or_ `projects` is tricky.
|
|
//
|
|
// I've opened an issue to get some help (thought it was a bug initially).
|
|
// There's more info available at:
|
|
//
|
|
// https://github.com/ajv-validator/ajv/issues/2096
|
|
//
|
|
// This also applies to apiTokenSchema and potentially other related schemas.
|
|
|
|
export const createApiTokenSchema = {
|
|
$id: '#/components/schemas/createApiTokenSchema',
|
|
type: 'object',
|
|
required: ['type'],
|
|
properties: {
|
|
secret: {
|
|
type: 'string',
|
|
},
|
|
type: {
|
|
type: 'string',
|
|
description: `One of ${Object.values(ApiTokenType).join(', ')}`,
|
|
},
|
|
environment: {
|
|
type: 'string',
|
|
},
|
|
project: {
|
|
type: 'string',
|
|
},
|
|
projects: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
expiresAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
nullable: true,
|
|
},
|
|
},
|
|
anyOf: [
|
|
{
|
|
properties: {
|
|
username: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
required: ['username'],
|
|
},
|
|
{
|
|
properties: {
|
|
tokenName: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
required: ['tokenName'],
|
|
},
|
|
],
|
|
components: {},
|
|
} as const;
|
|
|
|
export type CreateApiTokenSchema = FromSchema<typeof createApiTokenSchema>;
|