Browse Source

Polishing in VersionRequestCondition

See gh-35237
pull/35247/head
rstoyanchev 5 months ago
parent
commit
2c32c770d5
  1. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/VersionRequestCondition.java
  2. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/VersionRequestCondition.java

5
spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/VersionRequestCondition.java

@ -128,9 +128,10 @@ public final class VersionRequestCondition extends AbstractRequestCondition<Vers
return (-1 * compareVersions(this.version, otherVersion)); return (-1 * compareVersions(this.version, otherVersion));
} }
else { else {
// Prefer mapping without version for unversioned request // Prefer mappings with a version unless the request is without a version
int result = this.version != null ? -1 : 1;
Comparable<?> version = exchange.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE); Comparable<?> version = exchange.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE);
return (version != null ? (this.version != null ? -1 : 1) : (this.version != null ? 1 : -1)); return (version == null ? -1 * result : result);
} }
} }

5
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/VersionRequestCondition.java

@ -127,9 +127,10 @@ public final class VersionRequestCondition extends AbstractRequestCondition<Vers
return (-1 * compareVersions(this.version, otherVersion)); return (-1 * compareVersions(this.version, otherVersion));
} }
else { else {
// Prefer mapping without version for unversioned request // Prefer mappings with a version unless the request is without a version
int result = this.version != null ? -1 : 1;
Comparable<?> version = (Comparable<?>) request.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE); Comparable<?> version = (Comparable<?>) request.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE);
return (version != null ? (this.version != null ? -1 : 1) : (this.version != null ? 1 : -1)); return (version == null ? -1 * result : result);
} }
} }

Loading…
Cancel
Save