Skip to content

Commit c9af997

Browse files
committed
refactor: move schemaToType to plugin utils from @hey-api/types
1 parent 13e0065 commit c9af997

File tree

4 files changed

+763
-737
lines changed

4 files changed

+763
-737
lines changed

packages/openapi-ts/src/ir/schema.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IRSchemaObject } from './ir';
1+
import type { IRParameterObject, IRSchemaObject } from './ir';
22

33
/**
44
* Ensure we don't produce redundant types, e.g. string | string.
@@ -64,3 +64,38 @@ export const deduplicateSchema = <T extends IRSchemaObject>({
6464

6565
return schema;
6666
};
67+
68+
export const irParametersToIrSchema = ({
69+
parameters,
70+
}: {
71+
parameters: Record<string, IRParameterObject>;
72+
}): IRSchemaObject => {
73+
const irSchema: IRSchemaObject = {
74+
type: 'object',
75+
};
76+
77+
if (parameters) {
78+
const properties: Record<string, IRSchemaObject> = {};
79+
const required: Array<string> = [];
80+
81+
for (const name in parameters) {
82+
const parameter = parameters[name];
83+
84+
properties[name] = deduplicateSchema({
85+
schema: parameter.schema,
86+
});
87+
88+
if (parameter.required) {
89+
required.push(name);
90+
}
91+
}
92+
93+
irSchema.properties = properties;
94+
95+
if (required.length) {
96+
irSchema.required = required;
97+
}
98+
}
99+
100+
return irSchema;
101+
};

0 commit comments

Comments
 (0)