Use case switch and iterate over define enums of model types

This commit is contained in:
Vincent (Wen Yu) Ge
2024-04-18 15:16:17 -04:00
parent 5a1c803ae1
commit 099ea23f04
3 changed files with 42 additions and 26 deletions

View File

@@ -60,8 +60,8 @@ export interface Property {
}
export enum ModelType {
REST = 'rest',
GRAPHQL = 'graphql'
REST = 'REST',
GRAPHQL = 'GraphQL'
}
function getExamples(version: string) {
@@ -362,7 +362,19 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
const example = properties.reduce((carry, currentValue) => {
const property = currentValue as AppwriteSchemaObject & Property;
const propertyName = modelType === ModelType.REST ? property.name : property.name.replace('$', '_');
let propertyName;
switch (modelType) {
case ModelType.REST:
propertyName = property.name;
break;
case ModelType.GRAPHQL:
propertyName = property.name.replace('$', '_');
break;
default:
propertyName = property.name;
break;
}
if (property.type === 'array') {
// If it's an array type containing primatives
if (property.items?.type){