# GSIP 234 - Advertise and Enforce Attribute Restrictions

## Overview

This proposal introduces support for defining, advertising, and enforcing restrictions on feature type attributes in
GeoServer. The goal is to improve data integrity and support clients by:

* Allowing administrators to configure restrictions on feature attributes (e.g., enumerations, min/max ranges).
* Advertising these restrictions to clients via `DescribeFeatureType` using standard XML Schema restrictions.
* Enforcing the restrictions during write operations (e.g., WFS-T, REST API).

### Proposed By

Alessandro Ricchiuti

### Assigned to Release

This proposal is for GeoServer 2.27.

### State

* [x] Under Discussion
* [ ] In Progress
* [ ] Completed
* [ ] Rejected
* [ ] Deferred

### Motivation

GeoServer currently lacks:

* A standardized way to expose attribute-level value restrictions to clients.
* Server-side enforcement of such restrictions on data writes.
* An API for programmatic constraint configuration.

Adding these capabilities will:

* Improve data quality by preventing invalid inputs.
* Enable client applications (e.g., MapStore, GeoNode) to provide appropriate user interfaces (e.g., dropdowns, numeric
  bounds).
* Ensure consistent behavior across services and interfaces.

## Proposal

### 1. Attribute Constraint Model

Extend the `AttributeTypeInfo` model to support:

* Enumerations of valid values for `string` and `int` attributes.
* Minimum and maximum inclusive bounds for numeric types.

Restrictions will be defined per attribute and stored persistently in the featuretype.xml.

### 2. Restriction Advertising in `DescribeFeatureType`

Modify the WFS DescribeFeatureType response to include attribute restrictions using standard XSD restriction elements:

* `xsd:simpleType` with `xsd:restriction` over the base type
* `xsd:enumeration` for fixed values
* `xsd:minInclusive` / `xsd:maxInclusive` for numeric ranges

Example:

```xml

<xsd:element name="status" minOccurs="1" maxOccurs="1" nillable="false">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="ACTIVE"/>
            <xsd:enumeration value="INACTIVE"/>
            <xsd:enumeration value="UNKNOWN"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>
```

```xml

<xsd:element name="value" minOccurs="1" maxOccurs="1" nillable="false">
    <xsd:simpleType>
        <xsd:restriction base="xsd:float">
            <xsd:minInclusive value="0.0"/>
            <xsd:maxInclusive value="100.0"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>
```

### 3. Constraint Enforcement on Write

Extend GeoServer's data validation pipeline to enforce the defined restrictions when receiving data write requests
via:

* WFS-T (Insert/Update)
* REST API (PUT/POST)

Restriction compliance checks will occur in `GeoserverFeatureStore` to centrally ensure consistent enforcement
regardless of service or store.

### 4. Admin UI Support

Enhance the GeoServer admin UI to allow configuring attribute-level restrictions (enumeration, min/max) through the
FeatureType editor.  
The main idea is to move all the editable HTML fields for the attributes in a dedicated pop-up.

The _Feature Type Details_ table will be made not-editable.

![](img/page.png)

Then, a click on the _Edit_ icon will open a pop-up, to edit the feature type details.  
The selection of a specific constraint depends on the type of the attribute.  
Example for a "Range" restriction:

![](img/popup-range.png)

Example for an "Options" restriction:

![](img/popup-options.png)

### Backwards Compatibility

This solution will be aimed to maintain the following:

* Fully backward-compatible: restrictions are optional.
* `DescribeFeatureType` output remains valid XSD.

## Feedback

## Voting

Project Steering Committee:

* Alessio Fabiani:
* Andrea Aime:
* Ian Turton:
* Jody Garnett:
* Jukka Rahkonen:
* Kevin Smith:
* Simone Giannecchini:
* Torben Barsballe:
* Nuno Oliveira:
* Peter Smythe:

## Links

* [Email Discussion (TBD)](https://discourse.osgeo.org/t/proposal-gsip-234-advertise-and-enforce-attribute-restrictions)