Updating the Openapi specs
Updating our OpenAPI specs to auto-generate end-to-end types and React Query options:
- Creates a single source of truth between backend and frontend
- Provides automatic type safety across the entire application
- Enables better IDE autocompletion for API requests and responses
- Catches type errors during build instead of runtime
- Reduces manual maintenance when API changes occur
- Simplifies onboarding for new developers
- Generates ready-to-use React Query hooks with proper typing
The following discussions from !2 should be addressed:
-
@ss5278 started a discussion: Add REST method as prefix
-
@ss5278 started a discussion: Use createInsertSchema because these are hard coded models, if we change the database schemas we will have to change it again, creates a dependecy that needs to be mended to
import { createInsertSchema} from './common.models.ts'; import { resultjob, sharedWorkOrders } from '@db/index.ts'; const ResultJobSchema = createInsertSchema(resultjob); const ShareWorkOrderSchema = createInsertSchema(sharedWorkOrders); //notice how I add the param req in the name export const GetParamIDWorkOrderResponseSchema = z.object({ data: ResultJobSchema .pick({ id: true, language: true, course_name: true, academic_term: true, assignment_name: true, job_complete: true, result_json: true, // if we need to rename the model }).extend({ owner: ResultJobSchema.pick({ user: true }).shape.user, }).optional(), message: z.string().optional(), });
-
@ss5278 started a discussion: Use my helper model from common.models.ts
import { DescribeRouteBase, } from '@/models/index.ts'; export const DescribeWorkOrderRoute = ({ description, tags = ['Work Order'], responses = {}, }: { description: string; tags?: string[]; responses?: Record<string, { description?: string; schema?: z.ZodTypeAny; }>; }) => DescribeRouteBase({ description, tags, responses: { '200': { description: 'Successfully created work order', schema: SuccessMessageSchema, }, '400': { description: 'Bad request for work order', schema: ErrorResponseSchema, }, '404': { description: 'Route under construction', schema: ErrorResponseSchema, }, '409': { description: 'Error creating work order', schema: ErrorResponseSchema, }, '500': { description: 'Server error while processing work order', schema: ErrorResponseSchema, }, // see how I spread it in the end // this will allow me override the responses if a routes works differently ...responses, }, });
-
@ss5278 started a discussion:
Edited by Satwik Shresth