Skip to content

Commit

Permalink
Only use BoolParam for GET method params
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Sep 19, 2024
1 parent 5b7b000 commit c42f5cb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
42 changes: 35 additions & 7 deletions src/api/autogen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ function handleIntFormat(format: string | undefined): RustType {
}

function handleObjectProps(
method: 'GET' | 'PUT',
baseKind: 'Request' | 'Response',
devicePath: string,
objName: string,
Expand All @@ -251,6 +252,7 @@ function handleObjectProps(
name: toPropName(propName),
originalName: propName,
type: handleOptType(
method,
baseKind,
devicePath,
`${objName}${propName}`,
Expand All @@ -264,6 +266,7 @@ function handleObjectProps(
}

function handleType(
method: 'GET' | 'PUT',
baseKind: 'Request' | 'Response',
devicePath: string,
name: string,
Expand Down Expand Up @@ -300,6 +303,7 @@ function handleType(
case 'array':
return rusty(
`Vec<${handleType(
method,
baseKind,
devicePath,
`${name}Item`,
Expand All @@ -321,13 +325,22 @@ function handleType(
return rusty('String');
}
case 'boolean':
return rusty('bool', baseKind === 'Request' ? 'BoolParam' : undefined);
return rusty(
'bool',
method === 'GET' && baseKind === 'Request' ? 'BoolParam' : undefined
);
case 'object': {
return registerType(devicePath, schema, schema => ({
kind: 'Object',
name,
doc: getDoc(schema),
properties: handleObjectProps(baseKind, devicePath, name, schema)
properties: handleObjectProps(
method,
baseKind,
devicePath,
name,
schema
)
}));
}
}
Expand All @@ -340,17 +353,19 @@ function handleType(
}

function handleOptType(
method: 'GET' | 'PUT',
baseKind: 'Request' | 'Response',
devicePath: string,
name: string,
schema: SchemaObject | ReferenceObject | undefined,
required: boolean
): RustType {
let type = handleType(baseKind, devicePath, name, schema);
let type = handleType(method, baseKind, devicePath, name, schema);
return required ? type : rusty(`Option<${type}>`);
}

function handleContent(
method: 'GET' | 'PUT',
devicePath: string,
prefixName: string,
baseKind: 'Request' | 'Response',
Expand Down Expand Up @@ -406,6 +421,7 @@ function handleContent(
isDeepStrictEqual(Object.keys(properties), ['Value'])
) {
let valueType = handleType(
method,
baseKind,
devicePath,
name,
Expand All @@ -417,10 +433,16 @@ function handleContent(
);
}

let convertedProps = handleObjectProps(baseKind, devicePath, name, {
properties,
required
});
let convertedProps = handleObjectProps(
method,
baseKind,
devicePath,
name,
{
properties,
required
}
);

return {
kind: baseKind,
Expand All @@ -433,6 +455,7 @@ function handleContent(
}

function handleResponse(
method: 'GET' | 'PUT',
devicePath: string,
prefixName: string,
{
Expand All @@ -446,6 +469,7 @@ function handleResponse(
) {
assertEmpty(otherResponses, 'Unexpected response status codes');
return handleContent(
method,
devicePath,
prefixName,
'Response',
Expand Down Expand Up @@ -528,6 +552,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
originalName: param.name,
doc: getDoc(param),
type: handleOptType(
'GET',
'Request',
devicePath,
`${device.name}${canonicalMethodName}Request${param.name}`,
Expand All @@ -544,6 +569,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
doc: getDoc(get),
resolvedArgs,
returnType: handleResponse(
'GET',
devicePath,
`${device.name}${canonicalMethodName}`,
get
Expand Down Expand Up @@ -579,6 +605,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
(get ? 'Set' : '') + canonicalDevice.getMethod(methodPath);

let argsType = handleContent(
'PUT',
devicePath,
`${device.name}${canonicalMethodName}`,
'Request',
Expand Down Expand Up @@ -608,6 +635,7 @@ for (let [path, methods = err('Missing methods')] of Object.entries(
doc: getDoc(put),
resolvedArgs,
returnType: handleResponse(
'PUT',
devicePath,
`${device.name}${canonicalMethodName}`,
put
Expand Down
54 changes: 11 additions & 43 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,7 @@ pub trait Device: std::fmt::Debug + Send + Sync {

/// Sets the connected state of the device.
#[http("connected", method = Put)]
async fn set_connected(
&self,

#[http("Connected", via = BoolParam)] connected: bool,
) -> ASCOMResult {
async fn set_connected(&self, #[http("Connected")] connected: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -719,11 +715,7 @@ pub trait Camera: Device + Send + Sync {
///
/// True = cooler on, False = cooler off.
#[http("cooleron", method = Put)]
async fn set_cooler_on(
&self,

#[http("CoolerOn", via = BoolParam)] cooler_on: bool,
) -> ASCOMResult {
async fn set_cooler_on(&self, #[http("CoolerOn")] cooler_on: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -765,11 +757,7 @@ pub trait Camera: Device + Send + Sync {

/// Sets whether Fast Readout Mode is enabled.
#[http("fastreadout", method = Put)]
async fn set_fast_readout(
&self,

#[http("FastReadout", via = BoolParam)] fast_readout: bool,
) -> ASCOMResult {
async fn set_fast_readout(&self, #[http("FastReadout")] fast_readout: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -1132,7 +1120,7 @@ pub trait Camera: Device + Send + Sync {

#[http("Duration")] duration: f64,

#[http("Light", via = BoolParam)] light: bool,
#[http("Light")] light: bool,
) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}
Expand Down Expand Up @@ -1319,7 +1307,7 @@ pub trait Dome: Device + Send + Sync {

/// Sets the current subframe height.
#[http("slaved", method = Put)]
async fn set_slaved(&self, #[http("Slaved", via = BoolParam)] slaved: bool) -> ASCOMResult {
async fn set_slaved(&self, #[http("Slaved")] slaved: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -1463,11 +1451,7 @@ pub trait Focuser: Device + Send + Sync {

/// Sets the state of temperature compensation mode.
#[http("tempcomp", method = Put)]
async fn set_temp_comp(
&self,

#[http("TempComp", via = BoolParam)] temp_comp: bool,
) -> ASCOMResult {
async fn set_temp_comp(&self, #[http("TempComp")] temp_comp: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -1661,7 +1645,7 @@ pub trait Rotator: Device + Send + Sync {

/// Sets the rotator’s Reverse state.
#[http("reverse", method = Put)]
async fn set_reverse(&self, #[http("Reverse", via = BoolParam)] reverse: bool) -> ASCOMResult {
async fn set_reverse(&self, #[http("Reverse")] reverse: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -1799,13 +1783,7 @@ pub trait Switch: Device + Send + Sync {
///
/// _ISwitchV3 and later._.
#[http("setasync", method = Put)]
async fn set_async(
&self,

#[http("Id")] id: i32,

#[http("State", via = BoolParam)] state: bool,
) -> ASCOMResult {
async fn set_async(&self, #[http("Id")] id: i32, #[http("State")] state: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand All @@ -1825,13 +1803,7 @@ pub trait Switch: Device + Send + Sync {

/// Sets a switch controller device to the specified state, true or false.
#[http("setswitch", method = Put)]
async fn set_switch(
&self,

#[http("Id")] id: i32,

#[http("State", via = BoolParam)] state: bool,
) -> ASCOMResult {
async fn set_switch(&self, #[http("Id")] id: i32, #[http("State")] state: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down Expand Up @@ -2061,7 +2033,7 @@ pub trait Telescope: Device + Send + Sync {
async fn set_does_refraction(
&self,

#[http("DoesRefraction", via = BoolParam)] does_refraction: bool,
#[http("DoesRefraction")] does_refraction: bool,
) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}
Expand Down Expand Up @@ -2266,11 +2238,7 @@ pub trait Telescope: Device + Send + Sync {

/// Sets the state of the telescope's sidereal tracking drive.
#[http("tracking", method = Put)]
async fn set_tracking(
&self,

#[http("Tracking", via = BoolParam)] tracking: bool,
) -> ASCOMResult {
async fn set_tracking(&self, #[http("Tracking")] tracking: bool) -> ASCOMResult {
Err(ASCOMError::NOT_IMPLEMENTED)
}

Expand Down

0 comments on commit c42f5cb

Please sign in to comment.