diff --git a/src/api/autogen/index.ts b/src/api/autogen/index.ts index 157b043..80c10be 100644 --- a/src/api/autogen/index.ts +++ b/src/api/autogen/index.ts @@ -1,5 +1,5 @@ import openapi from '@readme/openapi-parser'; -import { writeFile } from 'fs/promises'; +import { chmod, open, unlink, writeFile } from 'fs/promises'; import { spawnSync } from 'child_process'; import { toSnakeCase, @@ -632,15 +632,17 @@ function stringifyIter( function stringifyDoc(doc: string | undefined = '') { doc = doc.trim(); if (!doc) return ''; - return doc - // Change "`InterfaceV1 Only` ...actual description" to be "actual description\n\n_InterfaceV1 Only_" - .replace(/^`(.+?)\.?`\s*(.*)$/s, '$2\n\n_$1._') - // If there is no summary, split out first sentence as summary. - .replace(/^(.*?(? { case 'Response': { return ` ${stringifyDoc(type.doc)} - ${cfg}#[derive(Debug, Clone${type.name !== 'DeviceStateItem' ? ', Copy' : ''}, Serialize, Deserialize)] + ${cfg}#[derive(Debug, Clone${ + type.name !== 'DeviceStateItem' ? ', Copy' : '' + }, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct ${type.name} { ${stringifyIter( @@ -908,4 +908,8 @@ try { console.warn(err); } -await writeFile('../mod.rs', rendered); +await unlink('../mod.rs'); +await writeFile('../mod.rs', rendered, { + flag: 'wx', + mode: /* readonly */ 0o444 +});