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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ gradle/wrapper/

\.DS_Store

plugin/
common-api/build/

/plugin/
2 changes: 1 addition & 1 deletion common/build.gradle → common-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.11'
ext.kotlin_version = '1.3.21'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.itangcent.common.constant

object HttpMethod {
val NO_METHOD = "ALL"
val GET = "GET"
val POST = "POST"
val DELETE = "DELETE"
val PUT = "PUT"
val PATCH = "PATCH"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.itangcent.common.exporter
import com.itangcent.common.constant.Attrs
import com.itangcent.common.model.*

class DefaultParseHandle : ParseHandle {
abstract class AbstractParseHandle : ParseHandle {
override fun setName(request: Request, name: String) {
request.name = name
}
Expand Down Expand Up @@ -51,7 +51,7 @@ class DefaultParseHandle : ParseHandle {
request.paths!!.add(pathParam)
}

override fun setJsonBody(request: Request, body: Any?) {
override fun setJsonBody(request: Request, body: Any?, bodyAttr: String?) {
request.body = body
}

Expand All @@ -67,6 +67,31 @@ class DefaultParseHandle : ParseHandle {
if (request.headers == null) {
request.headers = ArrayList()
}
request.headers!!.removeIf { it.name == header.name }
request.headers!!.add(header)
}

override fun addResponse(request: Request, response: Response) {
if (request.response == null) {
request.response = ArrayList()
}
request.response!!.add(response)
}

override fun addResponseHeader(response: Response, header: Header) {

if (response.headers == null) {
response.headers = ArrayList()
}
response.headers!!.add(header)
}

override fun setResponseBody(response: Response, bodyType: String, body: Any?) {
response.bodyType = bodyType
response.body = body
}

override fun setResponseCode(response: Response, code: Int) {
response.code = code
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ParseHandle {

fun setName(request: Request, name: String)

fun setMethod(request: Request, httpMethod: String)
fun setMethod(request: Request, method: String)

fun setPath(request: Request, path: String)

Expand All @@ -24,11 +24,27 @@ interface ParseHandle {

fun addPathParam(request: Request, pathParam: PathParam)

fun setJsonBody(request: Request, body: Any?)
fun setJsonBody(request: Request, body: Any?, bodyAttr: String?)

fun appendDesc(request: Request, desc: String?)

fun addHeader(request: Request, header: Header)

//region response
fun addResponse(request: Request, response: Response)

fun addResponseHeader(response: Response, header: Header)

fun setResponseBody(response: Response, bodyType: String, body: Any?)

fun setResponseCode(response: Response, code: Int)
//endregion

fun linkToClass(linkClass: Any): String?

fun linkToMethod(linkMethod: Any): String?

fun linkToProperty(linkField: Any): String?
}

//region utils------------------------------------------------------------------
Expand All @@ -55,6 +71,16 @@ fun ParseHandle.addFormParam(request: Request, paramName: String, defaultVal: St
param.value = defaultVal
param.required = required
param.desc = desc
param.type = "text"
this.addFormParam(request, param)
}

fun ParseHandle.addFormFileParam(request: Request, paramName: String, required: Boolean, desc: String?) {
val param = FormParam()
param.name = paramName
param.required = required
param.desc = desc
param.type = "file"
this.addFormParam(request, param)
}

Expand All @@ -72,4 +98,11 @@ fun ParseHandle.addPathParam(request: Request, name: String, desc: String) {
pathParam.desc = desc
this.addPathParam(request, pathParam)
}

fun ParseHandle.addResponseHeader(response: Response, name: String, value: String) {
val header = Header()
header.name = name
header.value = value
addResponseHeader(response, header)
}
//endregion utils------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.itangcent.common.model
class Param {
var name: String? = null

var value: String? = null
var value: Any? = null

var desc: String? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.itangcent.common.model

class Response {

var headers: Array<Header>? = null
var headers: ArrayList<Header>? = null

/**
* raw/json/xml
*/
var bodyType: String? = null

var body: Any? = null

var code: Int? = null
}
19 changes: 10 additions & 9 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ plugins {
group 'com.itangcent'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'idea'
Expand All @@ -25,7 +24,6 @@ intellij {
// version idea_version
// version '2018.2.1'
version '2017.3.5'
// plugins 'git4idea'
pluginName plugin_name
updateSinceUntilBuild false
downloadSources true
Expand All @@ -44,6 +42,11 @@ task sourcesJar(type: Jar) {
from sourceSets.main.allSource
}


jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

artifacts {
archives jar
archives javadocJar
Expand All @@ -54,11 +57,9 @@ repositories {
mavenCentral()
}

jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

dependencies {
compile project(path: ':common-api', configuration: 'default')

compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

compile fileTree(dir: 'libs', include: ['*.jar'])
Expand All @@ -67,14 +68,14 @@ dependencies {

compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

testCompile group: 'junit', name: 'junit', version: '4.12'

compile group: 'commons-io', name: 'commons-io', version: '2.6'

testImplementation group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
}
5 changes: 0 additions & 5 deletions idea-plugin/idea-sandbox/config/options/updates.xml

This file was deleted.

Binary file modified idea-plugin/libs/intellij-kotlin.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.itangcent.idea.constant

object SpringAttrs {

val SPRING_REQUEST_RESPONSE: Array<String> = arrayOf("HttpServletRequest", "HttpServletResponse")

var SPRING_CONTROLLER_ANNOTATION: Set<String> =
mutableSetOf("org.springframework.stereotype.Controller",
"org.springframework.web.bind.annotation.RestController")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,4 @@ abstract class ApiExportAction(text: String) : KotlinAnAction(text) {
builder.bind(PsiClassHelper::class) { it.singleton() }
builder.bind(TmTypeHelper::class) { it.singleton() }
}

protected fun saveOrCopy(project: Project?, info: String?,
onCopy: () -> Unit,
onSaveSuccess: () -> Unit,
onSaveFailed: () -> Unit) {

if (info == null) return
val actionContext = ActionContext.getContext()!!

actionContext.runInSwingUI {
val descriptor = FileChooserDescriptorFactory
.createSingleFileOrFolderDescriptor()
.withTitle("Export location")
.withDescription("Choose directory to export api to")
.withHideIgnored(false)
val chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, project, null)
var toSelect: VirtualFile? = null
val lastLocation = PropertiesComponent.getInstance().getValue(lastImportedLocation())
if (lastLocation != null) {
toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation)
}
val files = chooser.choose(project, toSelect)
if (files.isNotEmpty()) {
actionContext.runInWriteUI {
val file = files[0]
PropertiesComponent.getInstance().setValue(lastImportedLocation(), file.path)
if (file.isDirectory) {
try {
val defaultFile = defaultExportedFile()
FileUtils.forceSave("${file.path}/$defaultFile", info.toByteArray(Charset.defaultCharset()))
onSaveSuccess()
} catch (e: Exception) {
onSaveFailed()
actionContext.runAsync {
copyAndLog(info, onCopy)
}
}
} else {
try {
FileUtils.forceSave(file, info.toByteArray(Charset.defaultCharset()))
onSaveSuccess()
} catch (e: Exception) {
onSaveFailed()
actionContext.runAsync {
copyAndLog(info, onCopy)
}
}
}
}
} else {
copyAndLog(info, onCopy)
}
}
}

private fun copyAndLog(info: String, onCopy: () -> Unit) {
val logger: Logger = ActionContext.getContext()!!.instance(Logger::class)
ToolUtils.copy2Clipboard(info)
onCopy()
if (info.length > 10000) {
logger.info("Api data is too lager to show in console!")
} else {
logger.log(info)
}
}

open fun defaultExportedFile(): String {
return "api.json"
}

open fun lastImportedLocation(): String {
return "com.itangcent.api.export.path"
}
}
Loading