@@ -27,6 +27,14 @@ export const generate = async (
27
27
// Define template data
28
28
let apiByGroupAndName : any [ ]
29
29
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
+
30
38
// Group apiDoc data by group and name
31
39
apiByGroupAndName = unique ( Object . values ( options . apiDocApiData ) . map ( x => x . group ) )
32
40
. reduce ( ( acc , cur ) => {
@@ -149,14 +157,38 @@ export const generateMarkdownFileSystem = async (options: ConfigurationObjectCLI
149
157
// Single file documentation generation
150
158
const singleDoc = documentation [ 0 ] . content
151
159
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
+
152
175
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
+ )
153
193
}
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
- )
162
194
}
0 commit comments