Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/helpers/lib/each-openapi-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ function child_entries(node) {
format_additionalProperties(node.additionalProperties) ]]
: []

const via_allOf = node.allOf?.flatMap(
a => Object.entries(a.properties || {})) || []
// allOf can be nested, so call child_entries recursively
const via_allOf = (node.allOf || []).flatMap(subNode =>
child_entries(subNode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, it actually was that easy...
I was very much "can't program my way out of a paper bag" last time I looked at this...
Thanks for taking this on!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used AI to ask how I would do this in js based on how I would do this in another language.

)

return [...via_properties, ...via_additionalProperties, ...via_allOf]
}
Expand Down
14 changes: 13 additions & 1 deletion test/fixtures/toc-bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@
}
},
console: {

<a href="#logging-console-collation_buffer_size">collation_buffer_size</a>: 10,
<a href="#logging-console-color_enabled">color_enabled</a>: false,
<a href="#logging-console-enabled">enabled</a>: false,
<a href="#logging-console-file_output">file_output</a>: "string",
<a href="#logging-console-log_keys">log_keys</a>: ["CRUD,HTTP,Query"...],
<a href="#logging-console-log_level">log_level</a>: "info",
<a href="#logging-console-rotation">rotation</a>: {
<a href="#logging-console-rotation-localtime">localtime</a>: false,
<a href="#logging-console-rotation-max_age">max_age</a>: 0,
<a href="#logging-console-rotation-max_size">max_size</a>: 100,
<a href="#logging-console-rotation-rotated_logs_size_limit">rotated_logs_size_limit</a>: 1024,
<a href="#logging-console-rotation-rotation_interval">rotation_interval</a>: "0"
}
},
<a href="#logging-debug">debug</a>: {
<a href="#logging-debug-collation_buffer_size">collation_buffer_size</a>: 1000,
Expand Down
17 changes: 16 additions & 1 deletion test/test-each-openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ describe('child_entries', function () {
['bar', {type: 'number'}]
])
})

ok('via allOf recursive', function () {
assert.deepEqual(
child_entries({
allOf: [
{properties: {'outer': {type: 'string'}}},
{allOf: [{properties: {'inner': {type: 'number'}}}]}
]
}),
[
['outer', {type: 'string'}],
['inner', {type: 'number'}]
])
})

})

// Helper function to clean up whitespace in strings for comparison
Expand All @@ -318,4 +333,4 @@ function assert_equal_no_whitespace (actual, expected) {
assert.equal(
cleanup_whitespace(actual),
cleanup_whitespace(expected))
}
}