diff --git a/src/lib/openapi/meta-schema-rules.test.ts b/src/lib/openapi/meta-schema-rules.test.ts index cdb006766f..a87d332dfc 100644 --- a/src/lib/openapi/meta-schema-rules.test.ts +++ b/src/lib/openapi/meta-schema-rules.test.ts @@ -56,10 +56,9 @@ const metaRules: Rule[] = [ }, { name: 'should have properties with descriptions', - match: (_, schema) => { + match: (_, schema) => // only match schemas that have a properties field - return 'properties' in schema; - }, + 'properties' in schema, metaSchema: { type: 'object', // properties of the meta schema @@ -91,6 +90,17 @@ const metaRules: Rule[] = [ }, knownExceptions: [], }, + { + name: 'should either have oneOf or properties, instead extract them in commonProps', + match: (_, schema) => + // only match schemas that have a properties field + 'properties' in schema && 'oneOf' in schema, + metaSchema: { + type: 'object', + additionalProperties: false, // this is a shortcut to say: it should fail + }, + knownExceptions: [], + }, { name: 'should have a description', metaSchema: { diff --git a/src/lib/openapi/spec/export-query-schema.ts b/src/lib/openapi/spec/export-query-schema.ts index a234762fb2..67b8f62cb0 100644 --- a/src/lib/openapi/spec/export-query-schema.ts +++ b/src/lib/openapi/spec/export-query-schema.ts @@ -1,27 +1,28 @@ import { FromSchema } from 'json-schema-to-ts'; +const commonProps = { + environment: { + type: 'string', + example: 'development', + description: 'The environment to export from', + }, + downloadFile: { + type: 'boolean', + example: true, + description: 'Whether to return a downloadable file', + }, +} as const; + export const exportQuerySchema = { $id: '#/components/schemas/exportQuerySchema', type: 'object', - required: ['environment'], description: 'Available query parameters for the [deprecated export/import](https://docs.getunleash.io/reference/deploy/import-export) functionality.', - properties: { - environment: { - type: 'string', - example: 'development', - description: 'The environment to export from', - }, - downloadFile: { - type: 'boolean', - example: true, - description: 'Whether to return a downloadable file', - }, - }, oneOf: [ { - required: ['features'], + required: ['environment', 'features'], properties: { + ...commonProps, features: { type: 'array', example: ['MyAwesomeFeature'], @@ -34,8 +35,9 @@ export const exportQuerySchema = { }, }, { - required: ['tag'], + required: ['environment', 'tag'], properties: { + ...commonProps, tag: { type: 'string', example: 'release',