Skip to content

Commit

Permalink
Accept Device instead of devicePath
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Sep 19, 2024
1 parent eb80fb7 commit b50ab16
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/api/autogen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let types = new Map<
let typeBySchema = new WeakMap<SchemaObject, RustType>();

function registerType<T extends RegisteredType>(
devicePath: string,
device: Device,
schema: SchemaObject,
createType: (schema: SchemaObject) => T | RustType
): RustType {
Expand All @@ -120,9 +120,9 @@ function registerType<T extends RegisteredType>(
return rusty(type.name);
}
});
if (devicePath !== '{device_type}') {
if (device.path !== '{device_type}') {
// This needs to be done even on cached types.
addFeature(rustyType, devicePath);
addFeature(rustyType, device.path);
}
return rustyType;
}
Expand Down Expand Up @@ -240,7 +240,7 @@ class TypeContext {
constructor(
private readonly method: 'GET' | 'PUT',
private readonly baseKind: 'Request' | 'Response',
private readonly devicePath: string
private readonly device: Device
) {}

handleObjectProps(
Expand Down Expand Up @@ -275,7 +275,7 @@ class TypeContext {
switch (schema.type) {
case 'integer':
if (schema.oneOf) {
return registerType(this.devicePath, schema, schema => {
return registerType(this.device, schema, schema => {
let enumType: EnumType = {
kind: 'Enum',
name,
Expand Down Expand Up @@ -323,7 +323,7 @@ class TypeContext {
: undefined
);
case 'object': {
return registerType(this.devicePath, schema, schema => ({
return registerType(this.device, schema, schema => ({
kind: 'Object',
name,
doc: getDoc(schema),
Expand Down Expand Up @@ -376,7 +376,7 @@ class TypeContext {
if (name.endsWith(baseKind)) {
name = name.slice(0, -baseKind.length);
}
return registerType(this.devicePath, schema, schema => {
return registerType(this.device, schema, schema => {
if (name === 'ImageArray') {
return rusty('ImageArray');
}
Expand Down Expand Up @@ -506,7 +506,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(

let resolvedArgs = new Map<string, Property>();

let paramCtx = new TypeContext('GET', 'Request', devicePath);
let paramCtx = new TypeContext('GET', 'Request', device);

for (let param of params.map(resolveMaybeRef)) {
assert.equal(param?.in, 'query', 'Parameter is not a query parameter');
Expand All @@ -529,11 +529,9 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
path: methodPath,
doc: getDoc(get),
resolvedArgs,
returnType: new TypeContext(
'GET',
'Response',
devicePath
).handleResponse(get)
returnType: new TypeContext('GET', 'Response', device).handleResponse(
get
)
});
});

Expand All @@ -543,7 +541,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
let params = (put.parameters ?? err('Missing parameters')).slice();

let expectedParams = ['device_number'];
if (devicePath === '{device_type}') {
if (device.path === '{device_type}') {
expectedParams.push('device_type');
}
for (let expectedParam of expectedParams) {
Expand All @@ -564,11 +562,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
let canonicalMethodName =
(get ? 'Set' : '') + canonicalDevice.getMethod(methodPath);

let argsType = new TypeContext(
'PUT',
'Request',
devicePath
).handleContent(
let argsType = new TypeContext('PUT', 'Request', device).handleContent(
`${device.name}${canonicalMethodName}`,
'application/x-www-form-urlencoded',
put.requestBody
Expand All @@ -595,11 +589,9 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
path: methodPath,
doc: getDoc(put),
resolvedArgs,
returnType: new TypeContext(
'PUT',
'Response',
devicePath
).handleResponse(put)
returnType: new TypeContext('PUT', 'Response', device).handleResponse(
put
)
});
});
});
Expand Down

0 comments on commit b50ab16

Please sign in to comment.