Skip to content

Commit

Permalink
[bug][html2] Fix visibility of body/response schemas (#5643)
Browse files Browse the repository at this point in the history
* 1441 fix visibility of body/response schemas

* Handle schemas with array items

* Point to template directory in bin script

* Regenerate sample

Co-authored-by: Jim Schubert <[email protected]>
  • Loading branch information
damian-zaleski and jimschubert authored Apr 19, 2020
1 parent 171f718 commit f6572fd
Show file tree
Hide file tree
Showing 6 changed files with 475 additions and 240 deletions.
2 changes: 1 addition & 1 deletion bin/html2-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html2 -o samples/documentation/html2 --additional-properties hideGenerationTimestamp=true $@"
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html2 -o samples/documentation/html2 -t modules/openapi-generator/src/main/resources/htmlDocs2/ --additional-properties hideGenerationTimestamp=true $@"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -5543,13 +5543,20 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
setParameterNullable(codegenParameter, codegenProperty);
}

addJsonSchemaForBodyRequestInCaseItsNotPresent(codegenParameter, body);

// set the parameter's example value
// should be overridden by lang codegen
setParameterExampleValue(codegenParameter, body);

return codegenParameter;
}

private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body){
if(codegenParameter.jsonSchema == null)
codegenParameter.jsonSchema = Json.pretty(body);
}

protected void addOption(String key, String description, String defaultValue) {
CliOption option = new CliOption(key, description);
if (defaultValue != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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 {
schemaWrapper.definitions = Object.assign({}, defs);
$RefParser.dereference(schemaWrapper).catch(function(err) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<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 {
Expand Down
2 changes: 1 addition & 1 deletion samples/documentation/html2/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1-SNAPSHOT
4.3.0-SNAPSHOT
Loading

0 comments on commit f6572fd

Please sign in to comment.