Add JSON schema endpoint
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile ratpack.dependency('jdbc-tx')
|
compile ratpack.dependency('jdbc-tx')
|
||||||
|
compile 'com.fasterxml.jackson.module:jackson-module-jsonSchema:2.9.0'
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ import com.devsoap.dbt.config.DBTConfig
|
|||||||
import com.devsoap.dbt.data.LedgerData
|
import com.devsoap.dbt.data.LedgerData
|
||||||
import com.devsoap.dbt.handlers.ExecutorHandler
|
import com.devsoap.dbt.handlers.ExecutorHandler
|
||||||
import com.devsoap.dbt.handlers.ConfigInfoHandler
|
import com.devsoap.dbt.handlers.ConfigInfoHandler
|
||||||
|
import com.devsoap.dbt.handlers.JsonSchemaHandler
|
||||||
import com.devsoap.dbt.handlers.LedgerGetTransactionHandler
|
import com.devsoap.dbt.handlers.LedgerGetTransactionHandler
|
||||||
import com.devsoap.dbt.handlers.LedgerListTransactionsHandler
|
import com.devsoap.dbt.handlers.LedgerListTransactionsHandler
|
||||||
import com.devsoap.dbt.handlers.LedgerUpdateTransactionHandler
|
import com.devsoap.dbt.handlers.LedgerUpdateTransactionHandler
|
||||||
@@ -47,12 +48,14 @@ class DBTModule extends ConfigurableModule<DBTConfig> {
|
|||||||
|
|
||||||
bind(ExecutorChainAction)
|
bind(ExecutorChainAction)
|
||||||
bind(ExecutorHandler)
|
bind(ExecutorHandler)
|
||||||
bind(ConfigInfoHandler)
|
|
||||||
|
|
||||||
bind(LedgerData)
|
bind(LedgerData)
|
||||||
bind(LedgerService)
|
bind(LedgerService)
|
||||||
bind(TransactionManagerService)
|
bind(TransactionManagerService)
|
||||||
|
|
||||||
|
bind(ConfigInfoHandler)
|
||||||
|
bind(JsonSchemaHandler)
|
||||||
|
|
||||||
Multibinder.newSetBinder(binder(), HandlerDecorator).addBinding()
|
Multibinder.newSetBinder(binder(), HandlerDecorator).addBinding()
|
||||||
.toInstance(HandlerDecorator.prependHandlers(LedgerChainAction))
|
.toInstance(HandlerDecorator.prependHandlers(LedgerChainAction))
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.devsoap.dbt.actions
|
|||||||
import com.devsoap.dbt.config.DBTConfig
|
import com.devsoap.dbt.config.DBTConfig
|
||||||
import com.devsoap.dbt.handlers.ExecutorHandler
|
import com.devsoap.dbt.handlers.ExecutorHandler
|
||||||
import com.devsoap.dbt.handlers.ConfigInfoHandler
|
import com.devsoap.dbt.handlers.ConfigInfoHandler
|
||||||
|
import com.devsoap.dbt.handlers.JsonSchemaHandler
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import groovy.util.logging.Slf4j
|
import groovy.util.logging.Slf4j
|
||||||
import ratpack.groovy.handling.GroovyChainAction
|
import ratpack.groovy.handling.GroovyChainAction
|
||||||
@@ -42,5 +43,6 @@ class ExecutorChainAction extends GroovyChainAction {
|
|||||||
log.info("Registering executor at /$executorPath")
|
log.info("Registering executor at /$executorPath")
|
||||||
path(executorPath, ExecutorHandler)
|
path(executorPath, ExecutorHandler)
|
||||||
path("$executorPath/config", ConfigInfoHandler)
|
path("$executorPath/config", ConfigInfoHandler)
|
||||||
|
path("$executorPath/schema", JsonSchemaHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ package com.devsoap.dbt.actions
|
|||||||
|
|
||||||
import com.devsoap.dbt.config.DBTConfig
|
import com.devsoap.dbt.config.DBTConfig
|
||||||
import com.devsoap.dbt.handlers.ConfigInfoHandler
|
import com.devsoap.dbt.handlers.ConfigInfoHandler
|
||||||
|
import com.devsoap.dbt.handlers.JsonSchemaHandler
|
||||||
import com.devsoap.dbt.handlers.LedgerGetTransactionHandler
|
import com.devsoap.dbt.handlers.LedgerGetTransactionHandler
|
||||||
import com.devsoap.dbt.handlers.LedgerListTransactionsHandler
|
import com.devsoap.dbt.handlers.LedgerListTransactionsHandler
|
||||||
import com.devsoap.dbt.handlers.LedgerUpdateTransactionHandler
|
import com.devsoap.dbt.handlers.LedgerUpdateTransactionHandler
|
||||||
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import groovy.util.logging.Slf4j
|
import groovy.util.logging.Slf4j
|
||||||
import ratpack.groovy.handling.GroovyChainAction
|
import ratpack.groovy.handling.GroovyChainAction
|
||||||
@@ -48,5 +50,6 @@ class LedgerChainAction extends GroovyChainAction {
|
|||||||
registry.get(LedgerListTransactionsHandler)
|
registry.get(LedgerListTransactionsHandler)
|
||||||
))
|
))
|
||||||
path("$ledgerPath/config", ConfigInfoHandler)
|
path("$ledgerPath/config", ConfigInfoHandler)
|
||||||
|
path("$ledgerPath/schema", JsonSchemaHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.devsoap.dbt.data
|
package com.devsoap.dbt.data
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import groovy.transform.ToString
|
import groovy.transform.ToString
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
@@ -25,6 +26,7 @@ class BlockTransaction implements Serializable {
|
|||||||
|
|
||||||
String id = UUID.randomUUID().toString().replace('-','')
|
String id = UUID.randomUUID().toString().replace('-','')
|
||||||
|
|
||||||
|
@JsonProperty(required = true)
|
||||||
List<Query> queries = []
|
List<Query> queries = []
|
||||||
|
|
||||||
boolean completed = false
|
boolean completed = false
|
||||||
@@ -61,6 +63,8 @@ class BlockTransaction implements Serializable {
|
|||||||
// A block in the chain
|
// A block in the chain
|
||||||
@ToString
|
@ToString
|
||||||
static final class Query implements Serializable {
|
static final class Query implements Serializable {
|
||||||
|
|
||||||
|
@JsonProperty(required = true)
|
||||||
String query
|
String query
|
||||||
String id
|
String id
|
||||||
String parent
|
String parent
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Devsoap Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package com.devsoap.dbt.handlers
|
package com.devsoap.dbt.handlers
|
||||||
|
|
||||||
import com.devsoap.dbt.config.DBTConfig
|
import com.devsoap.dbt.config.DBTConfig
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Devsoap Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.devsoap.dbt.handlers
|
||||||
|
|
||||||
|
import com.devsoap.dbt.data.BlockTransaction
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator
|
||||||
|
import ratpack.handling.Context
|
||||||
|
import ratpack.handling.Handler
|
||||||
|
import ratpack.http.HttpMethod
|
||||||
|
import ratpack.jackson.Jackson
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class JsonSchemaHandler implements Handler {
|
||||||
|
|
||||||
|
private final JsonSchemaGenerator generator
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
JsonSchemaHandler(ObjectMapper mapper) {
|
||||||
|
this.generator = new JsonSchemaGenerator(mapper)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void handle(Context ctx) throws Exception {
|
||||||
|
if(ctx.request.method == HttpMethod.GET) {
|
||||||
|
def schema = generator.generateSchema(BlockTransaction)
|
||||||
|
ctx.render Jackson.json(schema)
|
||||||
|
} else {
|
||||||
|
ctx.next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user