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
9 changes: 5 additions & 4 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
_subModelName,
remove,
_upperFirst,
md2Html
md2Html,
_doc
} = require('./helper');

function collectionType(name) {
Expand Down Expand Up @@ -73,7 +74,7 @@
'artifactId', 'version'
];
needParamsKeys.forEach(key => {
if (params[key] === undefined) {

Check warning on line 77 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected use of undefined

Check warning on line 77 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Unexpected use of undefined

Check warning on line 77 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected use of undefined

Check warning on line 77 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected use of undefined

Check warning on line 77 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected use of undefined
params[key] = '';
}
});
Expand Down Expand Up @@ -851,7 +852,7 @@
if (description) {
const descriptions = md2Html(description).trimEnd().split('\n');
for (let j = 0; j < descriptions.length; j++) {
this.emit(` * ${descriptions[j]}\n`, level);
this.emit(` * ${_doc(descriptions[j])}\n`, level);
}
hasNextSection = true;
}
Expand All @@ -862,7 +863,7 @@
const examples = md2Html(example).trimEnd().split('\n');
this.emit(' * <strong>example:</strong>\n', level);
for (let j = 0; j < examples.length; j++) {
this.emit(` * ${examples[j]}\n`, level);
this.emit(` * ${_doc(examples[j])}\n`, level);
}
hasNextSection = true;
}
Expand Down Expand Up @@ -891,7 +892,7 @@
}
this.emit(' */\n', level);
}
this.emit(`@NameInMap("${realName}")\n`, level);
this.emit(`@NameInMap("${_doc(realName)}")\n`, level);
if (deprecated === 'true') {
this.emit(`@Deprecated\n`, level);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,18 @@ function _string(str) {
if (str.string === '""') {
return '\\"\\"';
}

// process \n in string expr
str.string = str.string.replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
return str.string.replace(/([^\\])"+|^"/g, function (str) {
return str.replace(/"/g, '\\"');
});
}
function _doc(str) {
return str.replace(/\\/g, '\\\\');
}

module.exports = {
_name, _type, _escape, _string,
_lowerFirst, _subModelName, remove, _upperFirst, md2Html
_lowerFirst, _subModelName, remove, _upperFirst, md2Html, _doc
};
4 changes: 4 additions & 0 deletions test/fixtures/model/NewMyModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public NewMyModelObject getObject() {
}

public static class NewMyModelObject extends TeaModel {
/**
* <strong>example:</strong>
* <p>example.com\\wuying\\users</p>
*/
@NameInMap("Name")
@Validation(required = true)
public String name;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/model/main.dara
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ model MyModel = {

model NewMyModel = {
object: {
name: string(name='Name'),
name: string(name='Name', example='example.com\\wuying\\users'),
num?: integer(name='Num'),
},
}