Skip to content

Commit

Permalink
WIP: Manage examples for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed Sep 4, 2024
1 parent d85c3a0 commit 3e8dc1d
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
export const fetchMetadataFields = (objectNamePlural: string) => {
const fromRelations = `
toObjectMetadata {
id
dataSourceId
nameSingular
namePlural
isSystem
isRemote
}
toFieldMetadataId
`;

const toRelations = `
fromObjectMetadata {
id
dataSourceId
nameSingular
namePlural
isSystem
isRemote
}
fromFieldMetadataId
`;

const fields = `
type
name
Expand All @@ -14,26 +38,12 @@ export const fetchMetadataFields = (objectNamePlural: string) => {
fromRelationMetadata {
id
relationType
toObjectMetadata {
id
dataSourceId
nameSingular
namePlural
isSystem
}
toFieldMetadataId
${fromRelations}
}
toRelationMetadata {
id
relationType
fromObjectMetadata {
id
dataSourceId
nameSingular
namePlural
isSystem
}
fromFieldMetadataId
${toRelations}
}
defaultValue
options
Expand Down Expand Up @@ -69,25 +79,10 @@ export const fetchMetadataFields = (objectNamePlural: string) => {
return fields;
case 'relations':
return `
id
relationType
fromObjectMetadata {
id
dataSourceId
nameSingular
namePlural
isSystem
}
fromObjectMetadataId
toObjectMetadata {
id
dataSourceId
nameSingular
namePlural
isSystem
}
toObjectMetadataId
fromFieldMetadataId
toFieldMetadataId
${fromRelations}
${toRelations}
`;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
computeManyResultPath,
computeSingleResultPath,
} from 'src/engine/core-modules/open-api/utils/path.utils';
import { getRequestBody } from 'src/engine/core-modules/open-api/utils/request-body.utils';
import {
getRequestBody,
getUpdateRequestBody,
} from 'src/engine/core-modules/open-api/utils/request-body.utils';
import {
getCreateOneResponse201,
getDeleteResponse200,
Expand Down Expand Up @@ -187,7 +190,7 @@ export class OpenApiService {
summary: `Update One ${item.nameSingular}`,
operationId: `updateOne${capitalize(item.nameSingular)}`,
parameters: [{ $ref: '#/components/parameters/idPath' }],
requestBody: getRequestBody(capitalize(item.nameSingular)),
requestBody: getUpdateRequestBody(capitalize(item.nameSingular)),
responses: {
'200': getUpdateOneResponse200(item, true),
'400': { $ref: '#/components/responses/400' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { capitalize } from 'src/utils/capitalize';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';

type Property = OpenAPIV3_1.SchemaObject;

Expand Down Expand Up @@ -312,19 +313,12 @@ export const computeMetadataSchemaComponents = (
type: 'object',
description: `An object`,
properties: {
dataSourceId: { type: 'string', format: 'uuid' },
nameSingular: { type: 'string' },
namePlural: { type: 'string' },
labelSingular: { type: 'string' },
labelPlural: { type: 'string' },
description: { type: 'string' },
icon: { type: 'string' },
isCustom: { type: 'boolean' },
isRemote: { type: 'boolean' },
isActive: { type: 'boolean' },
isSystem: { type: 'boolean' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
labelIdentifierFieldMetadataId: {
type: 'string',
format: 'uuid',
Expand All @@ -333,6 +327,33 @@ export const computeMetadataSchemaComponents = (
type: 'string',
format: 'uuid',
},
},
};
schemas[`${capitalize(item.namePlural)}`] = {
type: 'array',
description: `A list of ${item.namePlural}`,
items: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
},
};
schemas[`${capitalize(item.nameSingular)} for Update`] = {
type: 'object',
description: `An object`,
properties: {
isActive: { type: 'boolean' },
},
};
schemas[`${capitalize(item.nameSingular)} for Response`] = {
...schemas[`${capitalize(item.nameSingular)}`],
properties: {
...schemas[`${capitalize(item.nameSingular)}`].properties,
id: { type: 'string', format: 'uuid' },
dataSourceId: { type: 'string', format: 'uuid' },
isCustom: { type: 'boolean' },
isActive: { type: 'boolean' },
isSystem: { type: 'boolean' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
fields: {
type: 'object',
properties: {
Expand All @@ -342,7 +363,7 @@ export const computeMetadataSchemaComponents = (
node: {
type: 'array',
items: {
$ref: '#/components/schemas/Field',
$ref: '#/components/schemas/Field for Response',
},
},
},
Expand All @@ -351,37 +372,83 @@ export const computeMetadataSchemaComponents = (
},
},
};
schemas[`${capitalize(item.namePlural)}`] = {
schemas[`${capitalize(item.namePlural)} for Response`] = {
type: 'array',
description: `A list of ${item.namePlural}`,
items: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
$ref: `#/components/schemas/${capitalize(item.nameSingular)} for Response`,
},
};

return schemas;
}
case 'field': {

schemas[`${capitalize(item.nameSingular)}`] = {
type: 'object',
description: `A field`,
properties: {
type: { type: 'string' },
type: {
type: 'string',
enum: Object.keys(FieldMetadataType),
},
name: { type: 'string' },
label: { type: 'string' },
description: { type: 'string' },
icon: { type: 'string' },
isCustom: { type: 'boolean' },
isNullable: { type: 'boolean' },
objectMetadataId: { type: 'string', format: 'uuid' },
},
};
schemas[`${capitalize(item.namePlural)}`] = {
type: 'array',
description: `A list of ${item.namePlural}`,
items: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
},
};
schemas[`${capitalize(item.nameSingular)} for Update`] = {
type: 'object',
description: `An object`,
properties: {
description: { type: 'string' },
icon: { type: 'string' },
isActive: { type: 'boolean' },
isCustom: { type: 'boolean' },
isNullable: { type: 'boolean' },
isSystem: { type: 'boolean' },
label: { type: 'string' },
name: { type: 'string' },
},
};
schemas[`${capitalize(item.nameSingular)} for Response`] = {
...schemas[`${capitalize(item.nameSingular)}`],
properties: {
type: {
type: 'string',
enum: Object.keys(FieldMetadataType),
},
name: { type: 'string' },
label: { type: 'string' },
description: { type: 'string' },
icon: { type: 'string' },
isNullable: { type: 'boolean' },
id: { type: 'string', format: 'uuid' },
isCustom: { type: 'boolean' },
isActive: { type: 'boolean' },
isSystem: { type: 'boolean' },
defaultValue: { type: 'object' },
options: { type: 'object' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
fromRelationMetadata: {
type: 'object',
properties: {
id: { type: 'string', format: 'uuid' },
relationType: { type: 'string' },
relationType: {
type: 'string',
enum: Object.keys(RelationMetadataType),
},
toObjectMetadata: {
type: 'object',
properties: {
Expand All @@ -390,6 +457,7 @@ export const computeMetadataSchemaComponents = (
nameSingular: { type: 'string' },
namePlural: { type: 'string' },
isSystem: { type: 'boolean' },
isRemote: { type: 'boolean' },
},
},
toFieldMetadataId: { type: 'string', format: 'uuid' },
Expand All @@ -399,7 +467,10 @@ export const computeMetadataSchemaComponents = (
type: 'object',
properties: {
id: { type: 'string', format: 'uuid' },
relationType: { type: 'string' },
relationType: {
type: 'string',
enum: Object.keys(RelationMetadataType),
},
fromObjectMetadata: {
type: 'object',
properties: {
Expand All @@ -408,20 +479,19 @@ export const computeMetadataSchemaComponents = (
nameSingular: { type: 'string' },
namePlural: { type: 'string' },
isSystem: { type: 'boolean' },
isRemote: { type: 'boolean' },
},
},
fromFieldMetadataId: { type: 'string', format: 'uuid' },
},
},
defaultValue: { type: 'object' },
options: { type: 'object' },
},
};
schemas[`${capitalize(item.namePlural)}`] = {
schemas[`${capitalize(item.namePlural)} for Response`] = {
type: 'array',
description: `A list of ${item.namePlural}`,
items: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
$ref: `#/components/schemas/${capitalize(item.nameSingular)} for Response`,
},
};

Expand All @@ -432,7 +502,35 @@ export const computeMetadataSchemaComponents = (
type: 'object',
description: 'A relation',
properties: {
relationType: { type: 'string' },
relationType: {
type: 'string',
enum: Object.keys(RelationMetadataType),
},
fromObjectMetadataId: { type: 'string', format: 'uuid' },
toObjectMetadataId: { type: 'string', format: 'uuid' },
fromName: { type: 'string' },
fromLabel: { type: 'string' },
toName: { type: 'string' },
toLabel: { type: 'string' },
},
};
schemas[`${capitalize(item.namePlural)}`] = {
type: 'array',
description: `A list of ${item.namePlural}`,
items: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
},
};
schemas[`${capitalize(item.nameSingular)} for Response`] = {
...schemas[`${capitalize(item.nameSingular)}`],
properties: {
relationType: {
type: 'string',
enum: Object.keys(RelationMetadataType),
},
id: { type: 'string', format: 'uuid' },
fromFieldMetadataId: { type: 'string', format: 'uuid' },
toFieldMetadataId: { type: 'string', format: 'uuid' },
fromObjectMetadata: {
type: 'object',
properties: {
Expand All @@ -441,9 +539,9 @@ export const computeMetadataSchemaComponents = (
nameSingular: { type: 'string' },
namePlural: { type: 'string' },
isSystem: { type: 'boolean' },
isRemote: { type: 'boolean' },
},
},
fromObjectMetadataId: { type: 'string' },
toObjectMetadata: {
type: 'object',
properties: {
Expand All @@ -452,18 +550,16 @@ export const computeMetadataSchemaComponents = (
nameSingular: { type: 'string' },
namePlural: { type: 'string' },
isSystem: { type: 'boolean' },
isRemote: { type: 'boolean' },
},
},
toObjectMetadataId: { type: 'string', format: 'uuid' },
fromFieldMetadataId: { type: 'string', format: 'uuid' },
toFieldMetadataId: { type: 'string', format: 'uuid' },
},
};
schemas[`${capitalize(item.namePlural)}`] = {
schemas[`${capitalize(item.namePlural)} for Response`] = {
type: 'array',
description: `A list of ${item.namePlural}`,
items: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
$ref: `#/components/schemas/${capitalize(item.nameSingular)} for Response`,
},
};
}
Expand Down
Loading

0 comments on commit 3e8dc1d

Please sign in to comment.