Skip to content

Commit

Permalink
Export tag types (#3026)
Browse files Browse the repository at this point in the history
Adds a simple functionality to export also tag types.
  • Loading branch information
sjaanus committed Feb 1, 2023
1 parent a91089d commit daa4041
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib/openapi/spec/export-result-schema.test.ts
Expand Up @@ -98,6 +98,7 @@ test('exportResultSchema', () => {
},
],
segments: [],
tagTypes: [{ name: 'simple', description: 'test' }],
};

expect(
Expand Down
10 changes: 9 additions & 1 deletion src/lib/openapi/spec/export-result-schema.ts
Expand Up @@ -11,12 +11,13 @@ import { variantSchema } from './variant-schema';
import { overrideSchema } from './override-schema';
import { variantsSchema } from './variants-schema';
import { constraintSchema } from './constraint-schema';
import { tagTypeSchema } from './tag-type-schema';

export const exportResultSchema = {
$id: '#/components/schemas/exportResultSchema',
type: 'object',
additionalProperties: false,
required: ['features', 'featureStrategies'],
required: ['features', 'featureStrategies', 'tagTypes'],
properties: {
features: {
type: 'array',
Expand Down Expand Up @@ -54,6 +55,12 @@ export const exportResultSchema = {
$ref: '#/components/schemas/segmentSchema',
},
},
tagTypes: {
type: 'array',
items: {
$ref: '#/components/schemas/tagTypeSchema',
},
},
},
components: {
schemas: {
Expand All @@ -69,6 +76,7 @@ export const exportResultSchema = {
constraintSchema,
parametersSchema,
legalValueSchema,
tagTypeSchema,
},
},
} as const;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/services/export-import-service.ts
Expand Up @@ -88,6 +88,7 @@ export default class ExportImportService {
contextFields,
featureTags,
segments,
tagTypes,
] = await Promise.all([
this.toggleStore.getAllByNames(query.features),
await this.featureEnvironmentStore.getAllByFeatures(
Expand All @@ -102,6 +103,7 @@ export default class ExportImportService {
this.contextFieldStore.getAll(),
this.featureTagStore.getAllByFeatures(query.features),
this.segmentStore.getAll(),
this.tagTypeStore.getAll(),
]);
this.addSegmentsToStrategies(featureStrategies, strategySegments);
const filteredContextFields = contextFields.filter((field) =>
Expand All @@ -116,6 +118,9 @@ export default class ExportImportService {
strategy.segments.includes(segment.id),
),
);
const filteredTagTypes = tagTypes.filter((tagType) =>
featureTags.map((tag) => tag.tagType).includes(tagType.name),
);
const result = {
features: features.map((item) => {
const { createdAt, archivedAt, lastSeenAt, ...rest } = item;
Expand Down Expand Up @@ -148,6 +153,7 @@ export default class ExportImportService {
const { createdAt, createdBy, ...rest } = item;
return rest;
}),
tagTypes: filteredTagTypes,
};
await this.eventStore.store({
type: FEATURES_EXPORTED,
Expand Down
Expand Up @@ -1096,10 +1096,17 @@ exports[`should serve the OpenAPI spec 1`] = `
},
"type": "array",
},
"tagTypes": {
"items": {
"$ref": "#/components/schemas/tagTypeSchema",
},
"type": "array",
},
},
"required": [
"features",
"featureStrategies",
"tagTypes",
],
"type": "object",
},
Expand Down

0 comments on commit daa4041

Please sign in to comment.