从Camel生成的swagger定义中抑制Camel特定属性

时间:2017-10-27 12:41:30

标签: apache-camel swagger aws-api-gateway

我使用camel-swagger生成我的服务的API定义。请在下面找到生成的swagger定义 -

{
  "swagger" : "2.0",
  "info" : {
    "description" : "api.description",
    "version" : "1.0",
    "title" : "api.title",
    "termsOfService" : "api.termsOfService",
    "contact" : {
      "name" : "api.contact.name",
      "url" : "http://api.contact.url",
      "email" : "api@demo.com"
    },
    "license" : {
      "name" : "api.license.name",
      "url" : "http://api.license.url"
    }
  },
  "host" : "0.0.0.0:13000",
  "basePath" : "/airportinfo-service/1.0",
  "tags" : [ {
    "name" : "airports"
  } ],
  "schemes" : [ "http" ],
  "paths" : {
    "/airports" : {
      "get" : {
        "tags" : [ "airports" ],
        "parameters" : [ ],
        "responses" : {
          "200" : {
            "description" : "Output type",
            "schema" : {
              "$ref" : "#/definitions/Airports"
            }
          }
        },
        "x-camelContextId" : "airportinfo-service",
        "x-routeId" : "getAirports"
      }
    },
    "/airports/{id}" : {
      "get" : {
        "tags" : [ "airports" ],
        "parameters" : [ {
          "name" : "id",
          "in" : "path",
          "description" : "",
          "required" : true,
          "type" : "string"
        } ],
        "responses" : {
          "200" : {
            "description" : "Output type",
            "schema" : {
              "$ref" : "#/definitions/Airport"
            }
          }
        },
        "x-camelContextId" : "airportinfo-service",
        "x-routeId" : "getAirport"
      }
    },
    "/airports/health" : {
      "get" : {
        "tags" : [ "airports" ],
        "parameters" : [ ],
        "responses" : {
          "200" : {
            "description" : "Output type",
            "schema" : {
              "type" : "string",
              "format" : "java.lang.String"
            }
          }
        },
        "x-camelContextId" : "airportinfo-service",
        "x-routeId" : "health"
      }
    }
  },
  "definitions" : {
    "Airport" : {
      "type" : "object",
      "properties" : {
        "id" : {
          "type" : "integer",
          "format" : "int64"
        },
        "airportIataCode" : {
          "type" : "string"
        },
        "airportName" : {
          "type" : "string"
        },
        "airportStatus" : {
          "type" : "string"
        },
        "airportLatitude" : {
          "type" : "number",
          "format" : "double"
        },
        "airportLongitude" : {
          "type" : "number",
          "format" : "double"
        },
        "airportUrl" : {
          "type" : "string"
        },
        "cityId" : {
          "type" : "integer",
          "format" : "int64"
        },
        "cityIataCode" : {
          "type" : "string"
        },
        "cityName" : {
          "type" : "string"
        },
        "cityLatitude" : {
          "type" : "number",
          "format" : "double"
        },
        "cityLongitude" : {
          "type" : "number",
          "format" : "double"
        },
        "cityStatus" : {
          "type" : "string"
        },
        "cityCategory" : {
          "type" : "string"
        },
        "countryId" : {
          "type" : "integer",
          "format" : "int64"
        },
        "countryIataCode" : {
          "type" : "string"
        },
        "countryName" : {
          "type" : "string"
        },
        "region" : {
          "type" : "string"
        }
      },
      "x-className" : {
        "type" : "string",
        "format" : "demo.service.composite.airportinfo.datatypes.Airport"
      }
    },
    "Airports" : {
      "type" : "object",
      "properties" : {
        "size" : {
          "type" : "integer",
          "format" : "int32"
        },
        "airports" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/Airport"
          }
        }
      },
      "x-className" : {
        "type" : "string",
        "format" : "demo.service.composite.airportinfo.datatypes.Airports"
      }
    }
  }
}

生成上述API定义的代码是 -

    restConfiguration()
        .component("{{server.component}}")
            .host("{{server.host}}")
            .port("{{server.port}}")
            .bindingMode(RestBindingMode.json)
            .dataFormatProperty("prettyPrint", "true")
            .contextPath("/{{service.name}}/{{service.version}}")
                .apiContextPath( "/" )
                    .apiProperty("api.title", "{{api.title}}")
                    .apiProperty("api.version", "{{service.version}}")
                    .apiProperty("api.description", "{{api.description}}")
                    .apiProperty("api.termsOfService", "{{api.termsOfService}}")
                    .apiProperty("api.contact.name", "{{api.contact.name}}")
                    .apiProperty("api.contact.email", "{{api.contact.email}}")
                    .apiProperty("api.contact.url", "{{api.contact.url}}")
                    .apiProperty("api.license.name", "{{api.license.name}}")
                    .apiProperty("api.license.url", "{{api.license.url}}")
                    .apiProperty("apiContextIdListing", "{{apiContextIdListing}}")
                    .apiProperty("apiContextIdPattern", "{{apiContextIdPattern}}");

    rest("/airports")
        .get()
        .id("getAirports")
            .outType(Airports.class)
            .to("direct:getAirports")
        .get("/{id}")
        .id("getAirport")
            .outType(Airport.class)
            .to("direct:getAirport")
        .get("/health")
        .id("health")
            .outType(String.class)
            .to("direct:health");

现在,我想在AWS API Gateway中导入此定义。但是,由于上面给出的API定义中的以下部分 -

,因此不会被接受
  1. 需要删除

    "x-className" : {
        "type" : "string",
        "format" : "demo.service.composite.airportinfo.datatypes.Airport"
    }
    
  2. 需要删除

    "x-className" : {
        "type" : "string",
        "format" : "demo.service.composite.airportinfo.datatypes.Airports"
    }
    
  3. 需要更换

    "schema" : {
        "type" : "string",
        "format" : "java.lang.String"
    }
    

    "schema" : {
        "format" : "String"
    }
    
  4. 进行这些更改后,我可以轻松地在AWS API Gateway中导入定义。

    有没有办法在使用camel-swagger生成的swagger定义中抑制Camel特定属性?

    感谢。

1 个答案:

答案 0 :(得分:0)

不,这是不可能的,它们总是包括在内。

这些类型是扩展名,例如,它们以x-开头,如规范中所述:https://swagger.io/specification/#specificationExtensions

我在下一个版本中记录了一张票,以便为此添加支持:https://issues.apache.org/jira/browse/CAMEL-11957

我们还修复了回复中的原始类型,不使用格式:https://issues.apache.org/jira/browse/CAMEL-11960