|
1 | 1 | /* ***************************************************************************
|
2 |
| - * Copyright 2013-2018 Ellucian Company L.P. and its affiliates. |
| 2 | + * Copyright 2013-2019 Ellucian Company L.P. and its affiliates. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -131,12 +131,16 @@ class RestfulApiController {
|
131 | 131 | // Setting overrideGenericMediaType=true in Config.groovy will replace generic media
|
132 | 132 | // types with latest actual versioned media types for a representation (where available).
|
133 | 133 | // The generic media types also need to be configured in genericMediaTypeList property.
|
134 |
| - // Setting overrideVersionRangeMediaType=true in Config.groovy will override the whole digit |
135 |
| - // version number with the highest semantic version where the major version matches. |
| 134 | + // Setting useHighestSemanticVersion=true in Config.groovy will dynamically replace all |
| 135 | + // versioned media types with the highest semantic version where the major version matches. |
| 136 | + // Setting useAcceptHeaderAsMediaTypeHeader=true in Config.groovy will return |
| 137 | + // the Accept request header as the X-Media-Type response header for some clients to |
| 138 | + // delay transitioning to full semantic versioning of the X-Media-Type response header. |
136 | 139 | ApiVersionParser apiVersionParser
|
137 | 140 | boolean overrideGenericMediaType
|
138 | 141 | List genericMediaTypeList
|
139 |
| - boolean overrideVersionRangeMediaType |
| 142 | + boolean useHighestSemanticVersion |
| 143 | + boolean useAcceptHeaderAsMediaTypeHeader |
140 | 144 |
|
141 | 145 | private Class pagedResultListClazz
|
142 | 146 |
|
@@ -181,7 +185,8 @@ class RestfulApiController {
|
181 | 185 |
|
182 | 186 | overrideGenericMediaType = getOverrideGenericMediaType()
|
183 | 187 | genericMediaTypeList = getGenericMediaTypeList()
|
184 |
| - overrideVersionRangeMediaType = getOverrideVersionRangeMediaType() |
| 188 | + useHighestSemanticVersion = getUseHighestSemanticVersion() |
| 189 | + useAcceptHeaderAsMediaTypeHeader = getUseAcceptHeaderAsMediaTypeHeader() |
185 | 190 |
|
186 | 191 | JSON.createNamedConfig('restapi-error:json') { }
|
187 | 192 | XML.createNamedConfig('restapi-error:xml') { }
|
@@ -228,13 +233,13 @@ class RestfulApiController {
|
228 | 233 | }
|
229 | 234 | }
|
230 | 235 | }
|
231 |
| - if (overrideVersionRangeMediaType && representation.apiVersion.version?.indexOf('.') == -1) { |
| 236 | + if (useHighestSemanticVersion && representation.apiVersion.version) { |
232 | 237 | if (representation.allMediaTypes.size() > 1 && !genericMediaTypeList.contains(representation.mediaType)) {
|
233 | 238 | List apiVersionList = []
|
234 | 239 | representation.allMediaTypes.each { mediaType ->
|
235 | 240 | if (!genericMediaTypeList.contains(mediaType)) {
|
236 | 241 | def testApiVersion = apiVersionParser.parseMediaType(resource.name, mediaType)
|
237 |
| - if (testApiVersion.version?.startsWith(representation.apiVersion.version+".")) { |
| 242 | + if (testApiVersion.majorVersion == representation.apiVersion.majorVersion) { |
238 | 243 | apiVersionList.add(testApiVersion)
|
239 | 244 | }
|
240 | 245 | }
|
@@ -723,7 +728,7 @@ class RestfulApiController {
|
723 | 728 | String responseMediaType = representation.mediaType
|
724 | 729 | String apiVersionMediaType = representation.apiVersion?.mediaType
|
725 | 730 | if (apiVersionMediaType) {
|
726 |
| - if (overrideVersionRangeMediaType || |
| 731 | + if ((useHighestSemanticVersion && !useAcceptHeaderAsMediaTypeHeader) || |
727 | 732 | (overrideGenericMediaType && genericMediaTypeList.contains(responseMediaType))) {
|
728 | 733 | responseMediaType = apiVersionMediaType
|
729 | 734 | }
|
@@ -1085,8 +1090,14 @@ class RestfulApiController {
|
1085 | 1090 | }
|
1086 | 1091 |
|
1087 | 1092 |
|
1088 |
| - private boolean getOverrideVersionRangeMediaType() { |
1089 |
| - def value = grailsApplication.config.restfulApi.overrideVersionRangeMediaType |
| 1093 | + private boolean getUseHighestSemanticVersion() { |
| 1094 | + def value = grailsApplication.config.restfulApi.useHighestSemanticVersion |
| 1095 | + (value instanceof Boolean) ? value : false |
| 1096 | + } |
| 1097 | + |
| 1098 | + |
| 1099 | + private boolean getUseAcceptHeaderAsMediaTypeHeader() { |
| 1100 | + def value = grailsApplication.config.restfulApi.useAcceptHeaderAsMediaTypeHeader |
1090 | 1101 | (value instanceof Boolean) ? value : false
|
1091 | 1102 | }
|
1092 | 1103 |
|
|
0 commit comments