File tree 1 file changed +66
-0
lines changed
packages/openapi-fetch/test
1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { test , expectTypeOf } from "vitest" ;
2
+
3
+ import createClient from "../src/index.js" ;
4
+
5
+ interface paths {
6
+ "/" : {
7
+ get : operations [ "GetObjects" ] ;
8
+ } ;
9
+ }
10
+
11
+ interface operations {
12
+ GetObjects : {
13
+ parameters : { } ;
14
+ responses : {
15
+ 200 : components [ "responses" ] [ "MultipleObjectsResponse" ] ;
16
+ 401 : components [ "responses" ] [ "Unauthorized" ] ;
17
+ 422 : components [ "responses" ] [ "GenericError" ] ;
18
+ } ;
19
+ } ;
20
+ }
21
+
22
+ interface components {
23
+ schemas : {
24
+ Object : {
25
+ id : string ;
26
+ name : string ;
27
+ } ;
28
+ GenericErrorModel : {
29
+ errors : {
30
+ body : string [ ] ;
31
+ } ;
32
+ } ;
33
+ } ;
34
+ responses : {
35
+ MultipleObjectsResponse : {
36
+ content : {
37
+ "application/json" : {
38
+ objects : components [ "schemas" ] [ "Object" ] [ ] ;
39
+ } ;
40
+ } ;
41
+ } ;
42
+ /** @description Unauthorized */
43
+ Unauthorized : {
44
+ content : { } ;
45
+ } ;
46
+ /** @description Unexpected error */
47
+ GenericError : {
48
+ content : {
49
+ "application/json" : components [ "schemas" ] [ "GenericErrorModel" ] ;
50
+ } ;
51
+ } ;
52
+ } ;
53
+ }
54
+
55
+ const { GET } = createClient < paths > ( ) ;
56
+
57
+ test ( "the error type works properly" , async ( ) => {
58
+ const value = await GET ( "/" ) ;
59
+
60
+ if ( value . data ) {
61
+ expectTypeOf ( value . data ) . toEqualTypeOf ( { objects : [ { id : "" , name : "" } ] } ) ;
62
+ } else {
63
+ expectTypeOf ( value . data ) . toBeUndefined ( ) ;
64
+ expectTypeOf ( value . error ) . toEqualTypeOf ( { errors : [ "" ] } ) ;
65
+ }
66
+ } ) ;
You can’t perform that action at this time.
0 commit comments