Class OpenapiValidationGatewayFilterFactory
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory<OpenapiValidationGatewayFilterFactory.Config>, org.springframework.cloud.gateway.support.Configurable<OpenapiValidationGatewayFilterFactory.Config>, org.springframework.cloud.gateway.support.ShortcutConfigurable, org.springframework.context.ApplicationEventPublisherAware
OpenapiValidation filter
name, giving it the location of the contract.
What happens to a message that breaks its contract is configured globally, per
direction, through OpenapiValidationProperties: a request is rejected with
400 Bad Request and a response replaced by 502 Bad Gateway in
ENFORCE mode, while REPORT mode forwards both and only records the
violations. Either way the outcome is stamped on the exchange for the auditing plugin
and counted in ValidationMetrics.
A body is only ever buffered when there is something to gain from it: it has to be
JSON, uncompressed, and announce a length within the configured maximum. That is what
keeps a file upload streaming straight through — a multipart/form-data or
application/octet-stream payload carries nothing a JSON schema applies to, so
it is never read into memory, however large it is. A chunked body announcing no length
is left alone for the same reason: buffering it could not be bounded. Each of these is
counted, so what is not being validated stays visible.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration forOpenapiValidationGatewayFilterFactory.Nested classes/interfaces inherited from class org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory
org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory.NameConfigNested classes/interfaces inherited from interface org.springframework.cloud.gateway.support.ShortcutConfigurable
org.springframework.cloud.gateway.support.ShortcutConfigurable.GatewayBeanFactoryResolver, org.springframework.cloud.gateway.support.ShortcutConfigurable.GatewayEvaluationContext, org.springframework.cloud.gateway.support.ShortcutConfigurable.RestrictivePropertyAccessor, org.springframework.cloud.gateway.support.ShortcutConfigurable.ShortcutType -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration key holding the gateway side path prefix to strip.static final StringConfiguration key holding the location of the contract.Fields inherited from interface org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory
NAME_KEY, VALUE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionOpenapiValidationGatewayFilterFactory(OpenapiContractRegistry registry, OpenapiValidationProperties properties, ValidationMetrics metrics) Creates the factory. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.cloud.gateway.filter.GatewayFilterBuilds the filter validating the exchange against the configured contract.Methods inherited from class org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory
enableBodyCaching, getPublisher, setApplicationEventPublisherMethods inherited from class org.springframework.cloud.gateway.support.AbstractConfigurable
getConfigClass, newConfig, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory
apply, apply, apply, getConfigClass, name, newConfigMethods inherited from interface org.springframework.cloud.gateway.support.ShortcutConfigurable
shortcutFieldPrefix, shortcutType
-
Field Details
-
SPEC_URL_KEY
Configuration key holding the location of the contract.- See Also:
-
PATH_PREFIX_KEY
Configuration key holding the gateway side path prefix to strip.- See Also:
-
-
Constructor Details
-
OpenapiValidationGatewayFilterFactory
public OpenapiValidationGatewayFilterFactory(OpenapiContractRegistry registry, OpenapiValidationProperties properties, ValidationMetrics metrics) Creates the factory.- Parameters:
registry- the registry the contracts are read throughproperties- the per direction validation settingsmetrics- the counters the outcomes are published to
-
-
Method Details
-
shortcutFieldOrder
-
apply
public org.springframework.cloud.gateway.filter.GatewayFilter apply(OpenapiValidationGatewayFilterFactory.Config config) Builds the filter validating the exchange against the configured contract.- Parameters:
config- the filter configuration holding the contract location- Returns:
- the gateway filter
-