You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2018/10/01 21:06:35 UTC

[camel] branch master updated: CAMEL-12846: Allow customization of REST API do...

This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ac341d  CAMEL-12846: Allow customization of REST API do...
2ac341d is described below

commit 2ac341d32163788783add4faf3b12816e6b5118a
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Mon Oct 1 23:05:49 2018 +0200

    CAMEL-12846: Allow customization of REST API do...
    
    ...cumentation Content-Type
    
    Adds two new API properties:
     - api.specification.contentType.json
     - api.specification.contentType.yaml
    
    Both specifying the `Content-Type` when serving the OpenAPI
    specification in JSON or YAML respectively. The defaults remain the same
    as before this change, `application/json` and `text/yaml`.
---
 camel-core/src/main/docs/rest-dsl.adoc             | 23 +++++++++++++++++++++-
 .../apache/camel/swagger/RestSwaggerSupport.java   |  5 +++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/camel-core/src/main/docs/rest-dsl.adoc b/camel-core/src/main/docs/rest-dsl.adoc
index c55c254..570cdc0 100644
--- a/camel-core/src/main/docs/rest-dsl.adoc
+++ b/camel-core/src/main/docs/rest-dsl.adoc
@@ -912,4 +912,25 @@ And in XML DSL:
       <apiProperty key="api.title" value="User API"/>
 
 </restConfiguration>
-----
\ No newline at end of file
+----
+
+==== Supported API properties
+
+The following table lists supported API properties and explains their effect. To set them use `apiProperty(String, String)` in the Java DSL
+or `<apiProperty>` when defining the REST API via XML configuration. Properties in **bold** are required by the OpenAPI 2.0 specification. 
+Most of the properties affect the OpenAPI https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#infoObject[Info object], https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#licenseObject[License object] or https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#contact-object[Contact object].
+
+|===
+|Property | Description
+| **api.version** | Version of the API 
+| **api.title** | Title of the API
+| api.description | Description of the API
+| api.termsOfService | API Terms of Service of the API
+| api.license.name | License information of the API
+| api.license.url | URL for the License of the API
+| api.contact.name | The identifying name of the contact person/organization
+| api.contact.url | The URL pointing to the contact information
+| api.contact.email | The email address of the contact person/organization
+| api.specification.contentType.json | The Content-Type of the served OpenAPI JSON specification, `application/json` by default
+| api.specification.contentType.yaml | The Content-Type of the served OpenAPI YAML specification, `text/yaml` by default
+|===
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
index 44db37f..c2e7890 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
@@ -203,8 +203,9 @@ public class RestSwaggerSupport {
 
         List<RestDefinition> rests = getRestDefinitions(contextId);
         if (rests != null) {
+            final Map<String, Object> apiProperties = configuration.getApiProperties();
             if (json) {
-                response.setHeader(Exchange.CONTENT_TYPE, "application/json");
+                response.setHeader(Exchange.CONTENT_TYPE, (String) apiProperties.getOrDefault("api.specification.contentType.json", "application/json"));
 
                 // read the rest-dsl into swagger model
                 Swagger swagger = reader.read(rests, route, swaggerConfig, contextId, classResolver);
@@ -223,7 +224,7 @@ public class RestSwaggerSupport {
 
                 response.writeBytes(bytes);
             } else {
-                response.setHeader(Exchange.CONTENT_TYPE, "text/yaml");
+                response.setHeader(Exchange.CONTENT_TYPE, (String) apiProperties.getOrDefault("api.specification.contentType.yaml", "text/yaml"));
 
                 // read the rest-dsl into swagger model
                 Swagger swagger = reader.read(rests, route, swaggerConfig, contextId, classResolver);