mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-10 21:07:46 +00:00
prettier updates
This commit is contained in:
@@ -52,11 +52,11 @@ export type AppwriteSchemaObject = OpenAPIV3.SchemaObject & {
|
||||
};
|
||||
|
||||
export interface Property {
|
||||
name: string;
|
||||
items?: {
|
||||
type?: string;
|
||||
oneOf?: OpenAPIV3.ReferenceObject[];
|
||||
} & OpenAPIV3.ReferenceObject;
|
||||
name: string;
|
||||
items?: {
|
||||
type?: string;
|
||||
oneOf?: OpenAPIV3.ReferenceObject[];
|
||||
} & OpenAPIV3.ReferenceObject;
|
||||
}
|
||||
|
||||
export enum ModelType {
|
||||
@@ -182,7 +182,8 @@ export function getSchema(id: string, api: OpenAPIV3.Document): OpenAPIV3.Schema
|
||||
if (schema) {
|
||||
return schema;
|
||||
}
|
||||
throw new Error(`Schema doesn't exist for id: ${id}`);}
|
||||
throw new Error(`Schema doesn't exist for id: ${id}`);
|
||||
}
|
||||
|
||||
const specs = import.meta.glob(
|
||||
'$appwrite/app/config/specs/open-api3*-(client|server|console).json',
|
||||
@@ -354,15 +355,18 @@ export function resolveReference(
|
||||
throw new Error("Schema doesn't exist");
|
||||
}
|
||||
|
||||
export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.Document<{}>, modelType: ModelType = ModelType.REST): Object => {
|
||||
|
||||
const properties = Object.keys(schema.properties ?? {}).map((key) =>{
|
||||
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;
|
||||
const fields = schema.properties?.[key];
|
||||
return {
|
||||
name,
|
||||
...fields
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const example = properties.reduce((carry, currentValue) => {
|
||||
@@ -370,29 +374,32 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
|
||||
let propertyName;
|
||||
switch (modelType) {
|
||||
case ModelType.REST:
|
||||
propertyName = property.name;
|
||||
break;
|
||||
propertyName = property.name;
|
||||
break;
|
||||
case ModelType.GRAPHQL:
|
||||
propertyName = property.name.replace('$', '_');
|
||||
break;
|
||||
propertyName = property.name.replace('$', '_');
|
||||
break;
|
||||
default:
|
||||
propertyName = property.name;
|
||||
break;
|
||||
propertyName = property.name;
|
||||
break;
|
||||
}
|
||||
|
||||
if (property.type === 'array') {
|
||||
// If it's an array type containing primatives
|
||||
if (property.items?.type){
|
||||
if (property.items?.type) {
|
||||
return {
|
||||
...carry,
|
||||
[propertyName]: property['x-example']
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (property.items && 'anyOf' in property.items) {
|
||||
// default to first child type if multiple available
|
||||
const firstSchema = (property.items as unknown as AppwriteSchemaObject)?.anyOf?.[0];
|
||||
const schema = getSchema(getIdFromReference(firstSchema as OpenAPIV3.ReferenceObject), api)
|
||||
const schema = getSchema(
|
||||
getIdFromReference(firstSchema as OpenAPIV3.ReferenceObject),
|
||||
api
|
||||
);
|
||||
|
||||
return {
|
||||
...carry,
|
||||
@@ -401,37 +408,43 @@ export const generateExample = (schema: OpenAPIV3.SchemaObject, api: OpenAPIV3.D
|
||||
}
|
||||
|
||||
// if an array of objects without child types
|
||||
const schema = getSchema(getIdFromReference(property.items as OpenAPIV3.ReferenceObject), api);
|
||||
const schema = getSchema(
|
||||
getIdFromReference(property.items as OpenAPIV3.ReferenceObject),
|
||||
api
|
||||
);
|
||||
return {
|
||||
...carry,
|
||||
[propertyName]: [generateExample(schema, api, modelType)]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// If it's an object type, but not in an array.
|
||||
if (property.type === 'object') {
|
||||
if (property.items?.oneOf){
|
||||
if (property.items?.oneOf) {
|
||||
// default to first child type if multiple available
|
||||
const schema = getSchema(getIdFromReference(property.items.oneOf[0] as OpenAPIV3.ReferenceObject), api);
|
||||
const schema = getSchema(
|
||||
getIdFromReference(property.items.oneOf[0] as OpenAPIV3.ReferenceObject),
|
||||
api
|
||||
);
|
||||
return {
|
||||
...carry,
|
||||
[propertyName]: generateExample(schema, api, modelType)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (property.items){
|
||||
if (property.items) {
|
||||
const schema = getSchema(getIdFromReference(property.items), api);
|
||||
return {
|
||||
...carry,
|
||||
[propertyName]: generateExample(schema, api, modelType)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...carry,
|
||||
[propertyName]: property['x-example']
|
||||
}
|
||||
};
|
||||
}, {});
|
||||
return example;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user