-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug][html2] Fix visibility of body/response schemas #5643
Changes from all commits
d8790d9
949dfd6
452029f
d7f66c2
f7681ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,31 @@ | |
//Convert elements with "marked" class to markdown | ||
processMarked(); | ||
}); | ||
function findNode(id, currentNode) { | ||
return (Object.keys(currentNode)[0] === id) ? currentNode : findNodeInChildren(id, currentNode); | ||
} | ||
function findNodeInChildren(id, currentNode) { | ||
for (let prop in currentNode) { | ||
if (currentNode.hasOwnProperty(prop)) { | ||
let currentChild = currentNode[prop]; | ||
if (id === prop) { | ||
return currentChild; | ||
} else { | ||
// Search in the current child | ||
if (typeof (currentChild) === 'object') { | ||
let result = findNode(id, currentChild); | ||
if (result !== false) { | ||
return result; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
</script> | ||
<style type="text/css"> | ||
{{>fonts}} | ||
|
@@ -416,9 +441,14 @@ | |
<script> | ||
$(document).ready(function() { | ||
var schemaWrapper = {{{jsonSchema}}}; | ||
var schema = schemaWrapper.schema; | ||
var schema = findNode('schema',schemaWrapper).schema; | ||
if (!schema) { | ||
schema = schemaWrapper.schema; | ||
} | ||
if (schema.$ref != null) { | ||
schema = defsParser.$refs.get(schema.$ref); | ||
} else if (schema.items != null && schema.items.$ref != null) { | ||
schema.items = defsParser.$refs.get(schema.items.$ref); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not cover array type, e.g.: schema:
type: array
items:
ref: '#/components/schemas/Pet' So I had to add one more ...
} else if (schema.type === 'array' && schema.items != null && schema.items.$ref != null) {
schema.items = defsParser.$refs.get(schema.items.$ref);
} else {
// line 450
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're totally right. I tested it on two different versions of the OpenApi generator and on the older one there was no issue with arrays, so I didn't cover it up, but that's a great change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've applied the suggested fix to this branch. |
||
schemaWrapper.definitions = Object.assign({}, defs); | ||
$RefParser.dereference(schemaWrapper).catch(function(err) { | ||
|
@@ -505,8 +535,7 @@ | |
{{>js_json_stringify_safe}} | ||
{{>js_webfontloader}} | ||
<script> | ||
var schemaWrapper = {}; | ||
schemaWrapper.definitions = Object.assign({}, defs); | ||
var schemaWrapper = { "components": { "schemas" : defs}}; | ||
defsParser = new $RefParser(); | ||
defsParser.dereference(schemaWrapper).catch(function(err) { | ||
console.log(err); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.1-SNAPSHOT | ||
4.3.0-SNAPSHOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you can share a minimal spec to reproduce the issue fixed by this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented on my phone, and this was attached at the PR level rather than response here. I'm duplicating my response here in case you didn't see it.
This affects every spec. You can see the current samples, none of which display body parameter information.