-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: handle nullable option for primitive types (#37) feat: handle nullable option for primitive types (#36) Co-authored-by: svolkov <svolkov@everpoint.ru> * bump: up version to 1.6.2; chore: update swagger2openapi to latest (6.0.0); docs: update CHANGELOG Co-authored-by: svolkov <svolkov@everpoint.ru>
- Loading branch information
Showing
9 changed files
with
143 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,65 @@ | ||
const _ = require('lodash'); | ||
const _ = require("lodash"); | ||
const { checkAndRenameModelName } = require("./modelNames"); | ||
|
||
const formatters = { | ||
'enum': content => _.map(content, ({ key, value }) => ` ${key} = ${value}`).join(',\n'), | ||
'intEnum': content => _.map(content, ({ value }) => value).join(' | '), | ||
'object': content => _.map(content, part => { | ||
const extraSpace = ' ' | ||
const result = `${extraSpace}${part.field};\n`; | ||
|
||
const comments = [ | ||
part.title, | ||
part.description | ||
].filter(Boolean) | ||
|
||
const commonText = comments.length ? [ | ||
'', | ||
'/**', | ||
...comments.reduce((acc, comment) => [...acc, ...comment.split(/\n/g).map(part => ` * ${part}`)], []), | ||
' */' | ||
].map(part => `${extraSpace}${part}\n`).join('') : ''; | ||
|
||
return `${commonText}${result}`; | ||
}).join(''), | ||
'type': content => { | ||
if (content.includes(' & ')) { | ||
return content.split(' & ').map(checkAndRenameModelName).join(' & ') | ||
enum: (content) => _.map(content, ({ key, value }) => ` ${key} = ${value}`).join(",\n"), | ||
intEnum: (content) => _.map(content, ({ value }) => value).join(" | "), | ||
object: (content) => | ||
_.map(content, (part) => { | ||
const extraSpace = " "; | ||
const result = `${extraSpace}${part.field};\n`; | ||
|
||
const comments = [part.title, part.description].filter(Boolean); | ||
|
||
const commonText = comments.length | ||
? [ | ||
"", | ||
"/**", | ||
...comments.reduce( | ||
(acc, comment) => [...acc, ...comment.split(/\n/g).map((part) => ` * ${part}`)], | ||
[], | ||
), | ||
" */", | ||
] | ||
.map((part) => `${extraSpace}${part}\n`) | ||
.join("") | ||
: ""; | ||
|
||
return `${commonText}${result}`; | ||
}).join(""), | ||
type: (content) => { | ||
if (content.includes(" & ")) { | ||
return content.split(" & ").map(checkAndRenameModelName).join(" & "); | ||
} | ||
|
||
if (content.includes(' | ')) { | ||
return content.split(' | ').map(checkAndRenameModelName).join(' | ') | ||
if (content.includes(" | ")) { | ||
return content.split(" | ").map(checkAndRenameModelName).join(" | "); | ||
} | ||
|
||
return content | ||
return content; | ||
}, | ||
'primitive': content => checkAndRenameModelName(content), | ||
} | ||
primitive: (content) => checkAndRenameModelName(content), | ||
}; | ||
|
||
const inlineExtraFormatters = { | ||
'object': (parsedSchema) => { | ||
object: (parsedSchema) => { | ||
return { | ||
...parsedSchema, | ||
typeIdentifier: parsedSchema.content.length ? parsedSchema.typeIdentifier : 'type', | ||
content: parsedSchema.content.length ? `{ ${parsedSchema.content.map(part => part.field).join(', ')} }` : 'object' | ||
} | ||
typeIdentifier: parsedSchema.content.length ? parsedSchema.typeIdentifier : "type", | ||
content: parsedSchema.content.length | ||
? `{ ${parsedSchema.content.map((part) => part.field).join(", ")} }` | ||
: "object", | ||
}; | ||
}, | ||
'enum': (parsedSchema) => { | ||
enum: (parsedSchema) => { | ||
return { | ||
...parsedSchema, | ||
content: _.map(parsedSchema.content, ({ value }) => `${value}`).join(' | ') | ||
} | ||
} | ||
} | ||
|
||
content: _.map(parsedSchema.content, ({ value }) => `${value}`).join(" | "), | ||
}; | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
formatters, | ||
inlineExtraFormatters, | ||
} | ||
}; |
Oops, something went wrong.