Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pydantic.conlist to define coordinate arrays #44

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

geospatial-jeff
Copy link
Contributor

@geospatial-jeff geospatial-jeff commented Feb 20, 2022

What I am changing

Use pydantic.conlist to type coordinate arrays because it allows specifying min_items. The arguments to conlist appear in the auto-generated JSON schema which makes it a better representation of the geojson spec. Only LineString implemented this before this change, now all the geometry types have length constraints on their coordinate arrays.

I noticed this while using hypothesis-jsonschema to autogenerate fake data against the JSON schema created by geojson-pydantic. Hypothesis would generate coordinates arrays with invalid number of members (ex. a linear ring with one coordinate).

How I did it

Because the coordinates members for different geometries build off of eachother I decided to define types for each coordinates type in types.py and reference those types in the pydantic models.

How you can test it

Run pytest!

@codecov-commenter
Copy link

codecov-commenter commented Feb 20, 2022

Codecov Report

Merging #44 (12cf99b) into master (1302fb5) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #44      +/-   ##
==========================================
+ Coverage   98.05%   98.11%   +0.05%     
==========================================
  Files           4        4              
  Lines         103      106       +3     
==========================================
+ Hits          101      104       +3     
  Misses          2        2              
Flag Coverage Δ
unittests 98.11% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
geojson_pydantic/geometries.py 98.38% <100.00%> (-0.10%) ⬇️
geojson_pydantic/types.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1302fb5...12cf99b. Read the comment docs.

@vincentsarago vincentsarago merged commit 5baeb0d into developmentseed:master Feb 21, 2022
@vincentsarago
Copy link
Member

🙏 thanks @geospatial-jeff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants