Skip to content

Commit e3e7640

Browse files
committed
fix readme and add note on enforced keys
1 parent 0307e67 commit e3e7640

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
## Description
2828

29-
`geojson_pydantic` provides a suite of Pydantic models matching the GeoJSON specification [rfc7946](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1). Those models can be used for creating or validating geojson data.
29+
`geojson_pydantic` provides a suite of Pydantic models matching the GeoJSON specification [rfc7946](https://datatracker.ietf.org/doc/html/rfc7946). Those models can be used for creating or validating geojson data.
3030

3131
## Install
3232

@@ -70,7 +70,7 @@ assert feat.type == "Feature"
7070
assert type(feat.geometry) == Point
7171
assert feat.properties["name"] == "jeff"
7272

73-
fc = FeatureCollection(features=[geojson_feature, geojson_feature])
73+
fc = FeatureCollection(type="FeatureCollection", features=[geojson_feature, geojson_feature])
7474
assert fc.type == "FeatureCollection"
7575
assert len(fc) == 2
7676
assert type(fc.features[0].geometry) == Point
@@ -182,6 +182,44 @@ feat = MyPointFeatureModel(**geojson_feature)
182182
assert feat.properties.name == "drew"
183183
```
184184

185+
## Enforced Keys
186+
187+
Starting with version `0.6.0`, geojson-pydantic's classes will not define default keys such has `type`, `geometry` or `properties`.
188+
This is to make sure the library does well its first goal, which is `validating` GeoJSON object based on the [specification](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1)
189+
190+
o A GeoJSON object has a member with the name "type". The value of
191+
the member MUST be one of the GeoJSON types.
192+
193+
o A Feature object HAS a "type" member with the value "Feature".
194+
195+
o A Feature object HAS a member with the name "geometry". The value
196+
of the geometry member SHALL be either a Geometry object as
197+
defined above or, in the case that the Feature is unlocated, a
198+
JSON null value.
199+
200+
o A Feature object HAS a member with the name "properties". The
201+
value of the properties member is an object (any JSON object or a
202+
JSON null value).
203+
204+
205+
```python
206+
from geojson_pydantic import Point
207+
208+
## Before 0.6
209+
Point(coordinates=(0,0))
210+
>> Point(type='Point', coordinates=(0.0, 0.0), bbox=None)
211+
212+
## After 0.6
213+
Point(coordinates=(0,0))
214+
>> ValidationError: 1 validation error for Point
215+
type
216+
field required (type=value_error.missing)
217+
218+
Point(type="Point", coordinates=(0,0))
219+
>> Point(type='Point', coordinates=(0.0, 0.0), bbox=None)
220+
```
221+
222+
185223
## Contributing
186224

187225
See [CONTRIBUTING.md](CONTRIBUTING.md).

0 commit comments

Comments
 (0)