Last active
December 2, 2021 03:16
-
-
Save harada-shota/caad6315467e67415a3052a5e2d36b85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .msw/openAPISpec.ts | |
export const endpoints = [ | |
"/sample-endpoint", | |
] as const; | |
export type Endpoints = typeof endpoints[number]; | |
export type Methods = "get" | "post" | "put" | "delete"; | |
type ExampleKindAndResponseType = { | |
"/sample-endpoint": { | |
get: { | |
responseType: SampleEndpointResponse; | |
exampleKind: | |
| "example1" | |
| "example2" | |
}; | |
put: never; | |
post: never; | |
delete: never; | |
}; | |
}; | |
export type ExampleKind< | |
Path extends Endpoints, | |
Method extends Methods | |
> = ExampleKindAndResponseType[Path][Method]["exampleKind"]; | |
export type ResponseType< | |
Path extends Endpoints, | |
Method extends Methods | |
> = ExampleKindAndResponseType[Path][Method]["responseType"]; | |
export type OpenAPISpec = { | |
paths: { | |
[Path in Endpoints]: { | |
[Method in Methods]: { | |
description: string; | |
operationId: string; | |
parameters: Record<string, unknown>[]; | |
tags: string[]; | |
responses: { | |
[status: string]: { | |
description: string; | |
content: { | |
"application/json": { | |
schema: Record<string, unknown>; | |
example?: ResponseType<Path, Method>; | |
examples?: { | |
[Example in ExampleKind<Path, Method>]: { | |
value: ResponseType<Path, Method>; | |
}; | |
}; | |
}; | |
}; | |
}; | |
}; | |
}; | |
}; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment