Skip to content
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

chore: polish YapiFormatter #1043

Merged
merged 1 commit into from
Oct 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ open class YapiFormatter {
@Inject
protected lateinit var urlSelector: UrlSelector

protected val json5Formatter: Json5Formatter by lazy {
actionContext.instance(Json5Formatter::class)
}

fun doc2Items(doc: Doc): List<HashMap<String, Any?>> {
if (doc is Request) {
return request2Items(doc)
Expand Down Expand Up @@ -161,18 +165,15 @@ open class YapiFormatter {
private fun parseQueryValueAsJson5(value: Any?): String? {
when (value) {
is Array<*> -> {
return actionContext.instance(Json5Formatter::class)
.format(value)
return json5Formatter.format(value)
}

is Collection<*> -> {
return actionContext.instance(Json5Formatter::class)
.format(value)
return json5Formatter.format(value)
}

is Map<*, *> -> {
return actionContext.instance(Json5Formatter::class)
.format(value)
return json5Formatter.format(value)
}

else -> {
Expand Down Expand Up @@ -647,7 +648,7 @@ open class YapiFormatter {
//region parse-json5
private fun parseByJson5(typedObject: Any?, rootDesc: String?): String {
addMockAsProperty("", typedObject)
val json5Formatter = actionContext.instance(Json5Formatter::class)
val json5Formatter = json5Formatter
return json5Formatter.format(typedObject, rootDesc)
}

Expand Down
Loading