mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-10 21:07:46 +00:00
Add tab for graphQL response models
This commit is contained in:
@@ -59,6 +59,11 @@ export interface Property {
|
||||
} & OpenAPIV3.ReferenceObject;
|
||||
}
|
||||
|
||||
export enum ModelType {
|
||||
REST = 'rest',
|
||||
GRAPHQL = 'graphql'
|
||||
}
|
||||
|
||||
function getExamples(version: string) {
|
||||
switch (version) {
|
||||
case '0.15.x':
|
||||
@@ -344,7 +349,7 @@ export function resolveReference(
|
||||
throw new Error("Schema doesn't exist");
|
||||
}
|
||||
|
||||
export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.Document<{}>): Object => {
|
||||
export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.Document<{}>, modelType: ModelType = ModelType.REST): Object => {
|
||||
|
||||
const properties = Object.keys(schema.properties ?? {}).map((key) =>{
|
||||
const name = key;
|
||||
@@ -357,12 +362,13 @@ 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('$', '_');
|
||||
if (property.type === 'array') {
|
||||
// If it's an array type containing primatives
|
||||
if (property.items?.type){
|
||||
return {
|
||||
...carry,
|
||||
[property.name]: property['x-example']
|
||||
[propertyName]: property['x-example']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,7 +379,7 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
|
||||
|
||||
return {
|
||||
...carry,
|
||||
[property.name]: [generateExample(schema, api)]
|
||||
[propertyName]: [generateExample(schema, api, modelType)]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -381,7 +387,7 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
|
||||
const schema = getSchema(getIdFromReference(property.items as OpenAPIV3.ReferenceObject), api);
|
||||
return {
|
||||
...carry,
|
||||
[property.name]: [generateExample(schema, api)]
|
||||
[propertyName]: [generateExample(schema, api, modelType)]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +398,7 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
|
||||
const schema = getSchema(getIdFromReference(property.items.oneOf[0] as OpenAPIV3.ReferenceObject), api);
|
||||
return {
|
||||
...carry,
|
||||
[property.name]: generateExample(schema, api)
|
||||
[propertyName]: generateExample(schema, api, modelType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,14 +406,14 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
|
||||
const schema = getSchema(getIdFromReference(property.items), api);
|
||||
return {
|
||||
...carry,
|
||||
[property.name]: generateExample(schema, api)
|
||||
[propertyName]: generateExample(schema, api, modelType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...carry,
|
||||
[property.name]: property['x-example']
|
||||
[propertyName]: property['x-example']
|
||||
}
|
||||
}, {});
|
||||
return example;
|
||||
|
||||
Reference in New Issue
Block a user