@hey-api/openapi-ts 0.76.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,10 @@ export const createClient = (config: Config = {}): Client => {
46
46
  });
47
47
  }
48
48
 
49
+ if (opts.requestValidator) {
50
+ await opts.requestValidator(opts);
51
+ }
52
+
49
53
  if (opts.body && opts.bodySerializer) {
50
54
  opts.body = opts.bodySerializer(opts.body);
51
55
  }
@@ -84,6 +84,12 @@ export interface Config {
84
84
  * {@link https://swagger.io/docs/specification/serialization/#query View examples}
85
85
  */
86
86
  querySerializer?: QuerySerializer | QuerySerializerOptions;
87
+ /**
88
+ * A function validating request data. This is useful if you want to ensure
89
+ * the request conforms to the desired shape, so it can be safely sent to
90
+ * the server.
91
+ */
92
+ requestValidator?: (data: unknown) => Promise<unknown>;
87
93
  /**
88
94
  * A function transforming response data before it's returned. This is useful
89
95
  * for post-processing data, e.g. converting ISO strings into Date objects.
@@ -46,6 +46,10 @@ export const createClient = (config: Config = {}): Client => {
46
46
  });
47
47
  }
48
48
 
49
+ if (opts.requestValidator) {
50
+ await opts.requestValidator(opts);
51
+ }
52
+
49
53
  if (opts.body && opts.bodySerializer) {
50
54
  opts.body = opts.bodySerializer(opts.body);
51
55
  }
@@ -42,6 +42,10 @@ export const createClient = (config: Config = {}): Client => {
42
42
  });
43
43
  }
44
44
 
45
+ if (opts.requestValidator) {
46
+ await opts.requestValidator(opts);
47
+ }
48
+
45
49
  if (opts.body && opts.bodySerializer) {
46
50
  opts.body = opts.bodySerializer(opts.body);
47
51
  }
@@ -43,19 +43,30 @@ export const createClient = (config: Config = {}): Client => {
43
43
  onResponse: mergeInterceptors(_config.onResponse, options.onResponse),
44
44
  };
45
45
 
46
- const { responseTransformer, responseValidator, security } = opts;
47
- if (security) {
46
+ const {
47
+ requestValidator,
48
+ responseTransformer,
49
+ responseValidator,
50
+ security,
51
+ } = opts;
52
+ if (requestValidator || security) {
48
53
  // auth must happen in interceptors otherwise we'd need to require
49
54
  // asyncContext enabled
50
55
  // https://nuxt.com/docs/guide/going-further/experimental-features#asynccontext
51
56
  opts.onRequest = [
52
57
  async ({ options }) => {
53
- await setAuthParams({
54
- auth: opts.auth,
55
- headers: options.headers,
56
- query: options.query,
57
- security,
58
- });
58
+ if (security) {
59
+ await setAuthParams({
60
+ auth: opts.auth,
61
+ headers: options.headers,
62
+ query: options.query,
63
+ security,
64
+ });
65
+ }
66
+
67
+ if (requestValidator) {
68
+ await requestValidator(options);
69
+ }
59
70
  },
60
71
  ...opts.onRequest,
61
72
  ];