首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >#ref in RAML with Mule (apikit)

#ref in RAML with Mule (apikit)
EN

Stack Overflow用户
提问于 2016-03-01 17:12:56
回答 1查看 651关注 0票数 1

我们使用的是Mule 3.7 CE。在我们的Maven POM中,我们使用apikit 1.7.3。我们还使用raml-for-jax-rs来生成基于RAML的java代码。

我们尝试做的是在代码方面使用一个公共对象,而raml/ What在模式方面引用各种其他模式都可以使用的公共模式。

mule-flow使用apikit并链接到以下RAML (只是一个示例):

代码语言:javascript
复制
#%RAML 0.8
version: v1.0
title: Test service
mediaType: application/json
schemas:
  - addressbook: |
      {
        "$schema": "draft4 (normally the url needs to be here but can't post more then 2 links)",
        "title": "addressbook",
        "description": "addressbook object",
        "type": "object",
        "properties": {
          "address": {
            "description": "address",
            "type": "string",
            "default":""
          }
        }
      }
  - testinput1: |
      {
        "$schema": "draft4 (normally the url needs to be here but can't post more then 2 links)",
        "title": "Testinput1",
        "description": "Testinput1 object",
        "type": "object",
        "properties": {
          "name": {
            "description": "name",
            "type": "string",
            "default":""
          },
          "addressbook": {
            "$ref" : "addressbook"
          }
        }
      }
  - testinput2: |
      {
        "$schema": "draft4 (normally the url needs to be here but can't post more then 2 links)",
        "title": "Testinput2",
        "description": "Testinput2 object",
        "type": "object",
        "properties":
        {
          "name": {
            "description": "id",
            "type": "string"
          },
          "addressbook": {
            "$ref" : "addressbook"
          }
        }
      }
  - output: |
      {
        "$schema": "draft4 (normally the url needs to be here but can't post more then 2 links)",
        "title": "Output",
        "description": "Output object",
        "type": "object",
        "properties": {
          "code": {
            "description": "code",
            "type": "string",
            "default":""
          }
        }
      }
/test1:
  displayName: test1
  post:
    description: test1
    body:
      application/json:
        schema: testinput1
    responses:
      200:
        body:
          application/json:
            schema: output
/test2:
  displayName: test2
  post:
    description: test2
    body:
      application/json:
        schema: testinput2
    responses:
      200:
        body:
          application/json:
            schema: output

现在的问题是,我们在运行时执行POST时会出现以下错误:

代码语言:javascript
复制
 ERROR 2016-02-29 15:45:52,755 [[testraml].test-httpListenerConfig.worker.01] org.mule.module.apikit.MappingExceptionListener: 
********************************************************************************
Message               : fatal: URI "addressbook#" is not absolute
    level: "fatal"
    uri: "addressbook#"
 (com.github.fge.jsonschema.core.exceptions.ProcessingException)
Type                  : org.mule.module.apikit.exception.BadRequestException
Code                  : MULE_ERROR--2
JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/apikit/exception/BadRequestException.html
********************************************************************************
Exception stack is:
1. fatal: URI "addressbook#" is not absolute
    level: "fatal"
    uri: "addressbook#"
 (com.github.fge.jsonschema.core.exceptions.ProcessingException)
  com.github.fge.jsonschema.core.load.SchemaLoader:163 (null)
2. fatal: URI "addressbook#" is not absolute
    level: "fatal"
    uri: "addressbook#"
 (com.github.fge.jsonschema.core.exceptions.ProcessingException) (org.mule.module.apikit.exception.BadRequestException)
  org.mule.module.apikit.validation.RestJsonSchemaValidator:95 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/apikit/exception/BadRequestException.html)
********************************************************************************
Root Exception stack trace:
com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: URI "addressbook#" is not absolute
    level: "fatal"
    uri: "addressbook#"

    at com.github.fge.jsonschema.core.load.SchemaLoader.get(SchemaLoader.java:163)
    at com.github.fge.jsonschema.core.load.RefResolver.rawProcess(RefResolver.java:114)
    at com.github.fge.jsonschema.core.load.RefResolver.rawProcess(RefResolver.java:51)
    at com.github.fge.jsonschema.core.processing.RawProcessor.process(RawProcessor.java:77)
    at com.github.fge.jsonschema.core.processing.RawProcessor.process(RawProcessor.java:41)
    at com.github.fge.jsonschema.core.processing.ProcessorChain$ProcessorMerger.process(ProcessorChain.java:189)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:79)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:128)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:120)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
    at com.github.fge.jsonschema.core.processing.CachingProcessor.process(CachingProcessor.java:109)
    at com.github.fge.jsonschema.processors.validation.ValidationChain.process(ValidationChain.java:107)
    at com.github.fge.jsonschema.processors.validation.ValidationChain.process(ValidationChain.java:57)
    at com.github.fge.jsonschema.core.processing.ProcessorMap$Mapper.process(ProcessorMap.java:166)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:79)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:128)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:120)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
    at com.github.fge.jsonschema.core.processing.CachingProcessor.process(CachingProcessor.java:109)
    at com.github.fge.jsonschema.processors.validation.InstanceValidator.process(InstanceValidator.java:136)
    at com.github.fge.jsonschema.processors.validation.InstanceValidator.processObject(InstanceValidator.java:241)
    at com.github.fge.jsonschema.processors.validation.InstanceValidator.process(InstanceValidator.java:176)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:56)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:34)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:79)
    at com.github.fge.jsonschema.main.JsonSchema.doValidate(JsonSchema.java:76)
    at com.github.fge.jsonschema.main.JsonSchema.validate(JsonSchema.java:109)
    at com.github.fge.jsonschema.main.JsonSchema.validate(JsonSchema.java:125)
    at org.mule.module.apikit.validation.RestJsonSchemaValidator.validate(RestJsonSchemaValidator.java:73)
    at org.mule.module.apikit.HttpRestRequest.validateSchema(HttpRestRequest.java:413)
    at org.mule.module.apikit.HttpRestRequest.valideateBody(HttpRestRequest.java:312)
    at org.mule.module.apikit.HttpRestRequest.negotiateInputRepresentation(HttpRestRequest.java:289)
    at org.mule.module.apikit.HttpRestRequest.validate(HttpRestRequest.java:114)
    at org.mule.module.apikit.AbstractRouter.processRouterRequest(AbstractRouter.java:193)
    at org.mule.module.apikit.AbstractRouter.processBlockingRequest(AbstractRouter.java:89)
    at org.mule.module.apikit.AbstractRouter.processBlocking(AbstractRouter.java:83)
    at org.mule.processor.AbstractRequestResponseMessageProcessor.process(AbstractRequestResponseMessageProcessor.java:47)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
    at org.mule.processor.BlockingProcessorExecutor.executeNext(Blocking...
********************************************************************************

来自raml-for-jax-rs的生成代码看起来不错。我们有一个TestInput1和TestInput2使用的Addressbook对象。

我们确实找到了一个jira标签,上面写着它在1.7.3中被修复了(我们在POM中使用了它)。据我们所知,这个问题似乎仍然没有得到解决,因为在RAML方面,这看起来很好,在代码方面,它看起来很好,但将RAML与API-kit一起使用会产生错误。

那么我们是不是做错了什么?这还是一个bug吗?我们需要等待Mule 3.8吗?有什么变通办法吗?我们在概念层面上做错了吗?

另外要注意的是,查看APIkit控制台显示的是完整的引用,而不是描述引用。这样,外部开发人员就不知道该方案的上下文。有什么解决方法吗?

EN

回答 1

Stack Overflow用户

发布于 2016-03-01 19:10:07

我记得我使用了一个自定义的JSON验证器来调用json模式,但是这里的情况是引用来自不同模式的对象并产生多个模式。

您可以创建多个模式文件,然后使用raml !include吗?说吧!包括sampleschema.json。

然后检查链接:http://spacetelescope.github.io/understanding-json-schema/structuring.html

这里有一个部分:

“井号(#)表示当前文档,然后斜杠(/)分隔的键将遍历文档中对象中的键。因此,在我们的示例中,”#/定义/地址“表示:

转到文档的根,找到该对象中关键字" definitions“的值,找到关键字"address”的值$ref也可以是相对URI或绝对URI,所以如果您希望将定义包含在单独的文件中,也可以这样做。例如:

{ "$ref":“定义.json#/地址”}“

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35718716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档