typed-openapi 0.1.1 → 0.1.3

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.
package/src/generator.ts CHANGED
@@ -14,6 +14,7 @@ type GeneratorOptions = ReturnType<typeof mapOpenApiEndpoints> & {
14
14
  type GeneratorContext = Required<GeneratorOptions>;
15
15
 
16
16
  export const allowedRuntimes = type("'none' | 'arktype' | 'io-ts' | 'typebox' | 'valibot' | 'yup' | 'zod'");
17
+ export type OutputRuntime = typeof allowedRuntimes.infer;
17
18
 
18
19
  // TODO validate response schemas in sample fetch ApiClient
19
20
  // also, check that we can easily retrieve the response schema from the Fetcher
@@ -95,9 +96,9 @@ export const generateFile = (options: GeneratorOptions) => {
95
96
  return prettify(file);
96
97
  };
97
98
 
98
- const generateSchemaList = ({ refs }: GeneratorContext) => {
99
+ const generateSchemaList = ({ refs, runtime }: GeneratorContext) => {
99
100
  let file = `
100
- export namespace Schemas {
101
+ ${runtime === "none" ? "export namespace Schemas {" : ""}
101
102
  // <Schemas>
102
103
  `;
103
104
  refs.getOrderedSchemas().forEach(([schema, infos]) => {
@@ -111,7 +112,7 @@ const generateSchemaList = ({ refs }: GeneratorContext) => {
111
112
  file +
112
113
  `
113
114
  // </Schemas>
114
- }
115
+ ${runtime === "none" ? "}" : ""}
115
116
  `
116
117
  );
117
118
  };
@@ -127,7 +128,7 @@ const parameterObjectToString = (parameters: Box<BoxRef> | Record<string, AnyBox
127
128
  };
128
129
  const generateEndpointSchemaList = (ctx: GeneratorContext) => {
129
130
  let file = `
130
- export namespace Endpoints {
131
+ ${ctx.runtime === "none" ? "export namespace Endpoints {" : ""}
131
132
  // <Endpoints>
132
133
  ${ctx.runtime === "none" ? "" : "type __ENDPOINTS_START__ = {}"}
133
134
  `;
@@ -146,13 +147,15 @@ const generateEndpointSchemaList = (ctx: GeneratorContext) => {
146
147
  : "parameters: never,"
147
148
  }
148
149
  response: ${
149
- endpoint.response.recompute((box) => {
150
- if (Box.isReference(box) && !box.params.generics) {
151
- box.value = `Schemas.${box.value}`;
152
- }
153
-
154
- return box;
155
- }).value
150
+ ctx.runtime === "none"
151
+ ? endpoint.response.recompute((box) => {
152
+ if (Box.isReference(box) && !box.params.generics) {
153
+ box.value = `Schemas.${box.value}`;
154
+ }
155
+
156
+ return box;
157
+ }).value
158
+ : endpoint.response.value
156
159
  },
157
160
  }\n`;
158
161
  });
@@ -161,7 +164,7 @@ const generateEndpointSchemaList = (ctx: GeneratorContext) => {
161
164
  file +
162
165
  `
163
166
  // </Endpoints>
164
- }
167
+ ${ctx.runtime === "none" ? "}" : ""}
165
168
  ${ctx.runtime === "none" ? "" : "type __ENDPOINTS_END__ = {}"}
166
169
  `
167
170
  );
@@ -177,7 +180,9 @@ const generateEndpointByMethod = (ctx: GeneratorContext) => {
177
180
  ${Object.entries(byMethods)
178
181
  .map(([method, list]) => {
179
182
  return `${method}: {
180
- ${list.map((endpoint) => `"${endpoint.path}": Endpoints.${endpoint.meta.alias}`)}
183
+ ${list.map(
184
+ (endpoint) => `"${endpoint.path}": ${ctx.runtime === "none" ? "Endpoints." : ""}${endpoint.meta.alias}`,
185
+ )}
181
186
  }`;
182
187
  })
183
188
  .join(",\n")}
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./box-factory";
2
+ export { generateFile, type OutputRuntime } from "./generator";
3
+ export * from "./map-openapi-endpoints";
4
+ export * from "./openapi-schema-to-ts";
5
+ export * from "./ref-resolver";
6
+ export * from "./ts-factory";
7
+ export * from "./types";