forked from AlroviOfficial/RoZod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.hbs
108 lines (103 loc) · 2.02 KB
/
template.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { z } from "zod";
import { endpoint } from "..";
{{#if imports}}
{{#each imports}}
import { {{{@key}}} } from "./{{{this}}}"
{{/each}}
{{/if}}
{{#if types}}
{{#each types}}
{{{this}}};
{{/each}}
{{/if}}
{{#each schemas}}
const {{@key}}{{#if (lookup ../circularTypeByName @key)}}: z.ZodType<{{@key}}>{{/if}} = {{{this}}};
{{/each}}
{{#ifNotEmptyObj schemas}}
const schemas = {
{{#each schemas}}
{{@key}},
{{/each}}
};
{{/ifNotEmptyObj}}
{{#each endpoints}}
/**
* @api {{toUpperCase method}} {{#if @root.options.baseUrl}}{{@root.options.baseUrl}}{{/if}}{{path}}
{{#if summary}}
* @summary {{{summary}}}
{{/if}}
{{#if parameters}}
{{#each parameters}}
* @param {{{name}}} {{{description}}}
{{/each}}
{{/if}}
{{#if tags}}
* @tags {{{tags}}}
{{/if}}
{{#if description}}
* @description {{{description}}}
{{/if}}
*/
export const {{alias}} = endpoint({
method: "{{method}}" as const,
path: "{{path}}",
{{#if @root.options.baseUrl}}
baseUrl: "{{@root.options.baseUrl}}",
{{/if}}
{{#if style}}
style: `{{style}}`,
{{/if}}
{{#if requestFormat}}
requestFormat: "{{requestFormat}}" as const,
{{/if}}
{{#if parameters}}
serializationMethod: {
{{#each parameters}}
"{{name}}": {
{{#if style}}
"style": "{{style}}",
{{/if}}
{{#if explode}}
"explode": true
{{/if}}
}{{#unless @last}},{{/unless}}
{{/each}}
},
parameters: {
{{#each parameters}}
{{!-- If not equal to body --}}
{{#ifeq name "body"}}
{{else}}
"{{name}}": {{{schema}}},
{{/ifeq}}
{{/each}}
},
{{!-- If name is "body" inside a parameter, add that here --}}
{{#each parameters}}
{{#ifeq name "body"}}
body: {{{schema}}},
{{/ifeq}}
{{/each}}
{{/if}}
response: {{{response}}},
{{#if errors.length}}
errors: [
{{#each errors}}
{
{{#ifeq status "default" }}
status: "default",
{{else}}
status: {{status}},
{{/ifeq}}
{{#if description}}
description: `{{description}}`,
{{/if}}
},
{{/each}}
]
{{/if}}
{{#unless errors.length}}
errors: [],
{{/unless}}
});
{{/each}}