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

fix: correct content-type for Postman API export #546

Merged
merged 1 commit into from
Jun 30, 2024
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
14 changes: 14 additions & 0 deletions common-api/src/main/kotlin/com/itangcent/http/RawContentType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.itangcent.http

import org.apache.http.entity.ContentType

/**
* define raw content types without charset
*
* @author tangcent
* @date 2024/06/29
*/
object RawContentType {

val APPLICATION_JSON = ContentType.create("application/json")!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import com.google.inject.Inject
import com.itangcent.common.logger.Log
import com.itangcent.common.logger.traceError
import com.itangcent.common.utils.*
import com.itangcent.http.HttpClient
import com.itangcent.http.HttpRequest
import com.itangcent.http.HttpResponse
import com.itangcent.http.contentType
import com.itangcent.http.*
import com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper
import com.itangcent.idea.utils.GsonExUtils
import com.itangcent.intellij.context.ActionContext
Expand All @@ -21,7 +18,6 @@ import com.itangcent.intellij.extend.rx.ThrottleHelper
import com.itangcent.intellij.extend.sub
import com.itangcent.intellij.logger.Logger
import com.itangcent.suv.http.HttpClientProvider
import org.apache.http.entity.ContentType
import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -119,7 +115,7 @@ open class DefaultPostmanApiHelper : PostmanApiHelper {
LOG.info("create collection in workspace $workspaceId to postman")
val request = getHttpClient()
.post(COLLECTION)
.contentType(ContentType.APPLICATION_JSON)
.contentType(RawContentType.APPLICATION_JSON)
.header("x-api-key", postmanSettingsHelper.getPrivateToken())
.body(linkedMapOf("collection" to collection))

Expand Down Expand Up @@ -206,7 +202,7 @@ open class DefaultPostmanApiHelper : PostmanApiHelper {
private fun doUpdateCollection(collectionId: String, apiInfo: Map<String, Any?>): Boolean {

val request = getHttpClient().put("$COLLECTION/$collectionId")
.contentType(ContentType.APPLICATION_JSON)
.contentType(RawContentType.APPLICATION_JSON)
.header("x-api-key", postmanSettingsHelper.getPrivateToken())
.body(GsonUtils.toJson(linkedMapOf("collection" to apiInfo)).apply { GsonExUtils.resolveGsonLazily(this) })

Expand Down Expand Up @@ -434,7 +430,7 @@ open class DefaultPostmanApiHelper : PostmanApiHelper {
}

companion object : Log() {
const val POSTMAN_HOST = "https://api.getpostman.com"
private const val POSTMAN_HOST = "https://api.getpostman.com"

//const val IMPOREDAPI = "$POSTMANHOST/import/exported"
const val COLLECTION = "$POSTMAN_HOST/collections"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ import com.itangcent.common.logger.traceError
import com.itangcent.common.model.Request
import com.itangcent.common.utils.*
import com.itangcent.idea.plugin.api.ClassApiExporterHelper
import com.itangcent.idea.plugin.rule.SuvRuleContext
import com.itangcent.idea.plugin.rule.setDoc
import com.itangcent.idea.plugin.settings.PostmanExportMode
import com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper
import com.itangcent.idea.psi.resource
import com.itangcent.idea.utils.FileSaveHelper
import com.itangcent.idea.utils.ModuleHelper
import com.itangcent.intellij.config.rule.RuleComputer
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.logger.Logger


@Singleton
class PostmanApiExporter {

@Inject
private lateinit var actionContext: ActionContext

@Inject
private lateinit var logger: Logger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ package com.itangcent.idea.plugin.api.export.postman
import com.google.inject.Inject
import com.itangcent.common.kit.toJson
import com.itangcent.common.utils.KV
import com.itangcent.http.RawContentType
import com.itangcent.idea.plugin.settings.helper.SettingsHelperTest
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.asJsonElement
import com.itangcent.intellij.extend.asMap
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
import com.itangcent.intellij.extend.sub
import com.itangcent.mock.AdvancedContextTest
import com.itangcent.suv.http.HttpClientProvider
import com.itangcent.test.HttpClientProviderMockBuilder
import com.itangcent.test.response404
import org.apache.http.entity.ContentType
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledOnOs
import org.junit.jupiter.api.condition.OS
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
Expand Down Expand Up @@ -52,19 +49,19 @@ abstract class DefaultPostmanApiHelperTest : SettingsHelperTest() {
.method("POST")
.response(
content = CREATE_OR_UPDATE_COLLECTION_SUCCESS_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.COLLECTION}/8283378b-5df6-488b-237c-f6b9ed0d7883")
.method("PUT")
.response(
content = CREATE_OR_UPDATE_COLLECTION_SUCCESS_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.COLLECTION}/31415926-67ce-2d4a-13c1-535897932384")
.method("PUT")
.response(
content = CREATE_OR_UPDATE_COLLECTION_FAILED_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.COLLECTION}/31415926-67ce-12cf-13c1-535897932384")
.method("PUT")
Expand All @@ -75,43 +72,43 @@ abstract class DefaultPostmanApiHelperTest : SettingsHelperTest() {
.method("GET")
.response(
content = ALL_COLLECTIONS_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.WORKSPACE}/e508269b-72ef-4c67-92c4-55777ba33434")
.method("GET")
.response(
content = COLLECTIONS_IN_WORKSPACE,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.COLLECTION}/42dc9386-34ab-2d4a-83c1-535897932384")
.method("GET")
.response(
content = COLLECTION_INFO_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url(DefaultPostmanApiHelper.WORKSPACE)
.method("GET")
.response(
content = ALL_WORKSPACES_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.WORKSPACE}/0db55d8f-8e03-4568-2871-250a378ab87c")
.method("GET")
.response(
content = WORKSPACE_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.COLLECTION}/42dc9386-34ab-2d4a-83c1-535897932384")
.method("DELETE")
.response(
content = DELETE_COLLECTION_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.url("${DefaultPostmanApiHelper.COLLECTION}/378bacc3-77cf-5331-82c1-ed273450ae35")
.method("DELETE")
.response(
content = DELETE_COLLECTION_FAILED_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.notFound().response404()
.build()
Expand Down Expand Up @@ -257,7 +254,7 @@ abstract class DefaultPostmanApiHelperTest : SettingsHelperTest() {
.call()
.response(
content = AUTHENTICATION_FAILED_RESULT,
contentType = ContentType.APPLICATION_JSON
contentType = RawContentType.APPLICATION_JSON
)
.notFound().response404()
.build()
Expand All @@ -277,7 +274,7 @@ abstract class DefaultPostmanApiHelperTest : SettingsHelperTest() {
.call()
.response(
content = SERVICE_LIMIT_EXHAUSTED_FAILED_RESULT,
contentType = ContentType.APPLICATION_JSON,
contentType = RawContentType.APPLICATION_JSON,
responseCode = 429
)
.notFound().response404()
Expand Down
Loading