Skip to content

Commit fe40564

Browse files
committed
Throw an error if title key is missing fix #26
1 parent 600ff99 commit fe40564

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/generator.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ export const generate = async (
2727
// Define template data
2828
let apiByGroupAndName: any[]
2929

30+
// Throw error if one element is missing the `title` required key
31+
const elementsWithoutTitle = options.apiDocApiData.filter(x => !x.title)
32+
if (elementsWithoutTitle.length > 0)
33+
throw new Error(
34+
'Missing `title` key in one or more elements. Run with `--debug` to generate `api_data.json` file to try to find what is happening (see https://github.com/rigwild/apidoc-markdown/issues/26).\n' +
35+
`Elements without \`title\` key: ${JSON.stringify(elementsWithoutTitle, null, 2)}`
36+
)
37+
3038
// Group apiDoc data by group and name
3139
apiByGroupAndName = unique(Object.values(options.apiDocApiData).map(x => x.group))
3240
.reduce((acc, cur) => {
@@ -149,14 +157,38 @@ export const generateMarkdownFileSystem = async (options: ConfigurationObjectCLI
149157
// Single file documentation generation
150158
const singleDoc = documentation[0].content
151159
await fs.writeFile(options.output, singleDoc)
160+
161+
if (options.debug) {
162+
await fs.writeFile(
163+
path.join(path.basename(path.dirname(options.output)), 'api_project.json'),
164+
JSON.stringify(apiDocProjectData, null, 2)
165+
)
166+
await fs.writeFile(
167+
path.join(path.basename(path.dirname(options.output)), 'api_data.json'),
168+
JSON.stringify(apiDocApiData, null, 2)
169+
)
170+
console.log(
171+
'Debug files `apidoc-project.json` and `apidoc-api.json` created. Put them in the bug report if you are creating one.'
172+
)
173+
}
174+
152175
return [{ outputFile: options.output, content: singleDoc }]
176+
} else {
177+
if (options.debug) {
178+
await fs.writeFile(path.join(options.output, 'api_project.json'), JSON.stringify(apiDocProjectData, null, 2))
179+
await fs.writeFile(path.join(options.output, 'api_data.json'), JSON.stringify(apiDocApiData, null, 2))
180+
console.log(
181+
'Debug files `apidoc-project.json` and `apidoc-api.json` created. Put them in the bug report if you are creating one.'
182+
)
183+
}
184+
185+
// Multi file documentation generation
186+
return Promise.all(
187+
documentation.map(async aDoc => {
188+
const filePath = path.resolve(outputPath, `${aDoc.name}.md`)
189+
await fs.writeFile(filePath, aDoc.content)
190+
return { outputFile: filePath, content: aDoc.content }
191+
})
192+
)
153193
}
154-
// Multi file documentation generation
155-
return Promise.all(
156-
documentation.map(async aDoc => {
157-
const filePath = path.resolve(outputPath, `${aDoc.name}.md`)
158-
await fs.writeFile(filePath, aDoc.content)
159-
return { outputFile: filePath, content: aDoc.content }
160-
})
161-
)
162194
}

0 commit comments

Comments
 (0)