Skip to main content

NPDI OAS Schemas

How to Use OAS to Pydantic

The OAS specifications can be used to generate the Pydantic models that validate updates to the database.

Running the Script

  • Basic usage:
    python generate_pydantic_models.py path_to_your_oas.yaml generated_models.py
    
  • With verbose output:
    python generate_pydantic_models.py path_to_your_oas.yaml generated_models.py --verbose
    

Example Usage

python generate_pydantic_models.py models/agencies.yaml pydantic/agencies.py --verbose

Output:

Loaded OpenAPI Specification from 'models/agencies.yaml'.
Generating model code for BaseAgency
Generating model code for CreateAgency
Generating model code for UpdateAgency
Generating model code for AgencyList
Generating model code for Agency
Generating model code for CreateUnit
Generating model code for UpdateUnit
Generating model code for BaseUnit
Generating model code for Unit
Generating model code for UnitList
Generating model code for AddOfficer
Generating model code for AddOfficerList
Generating model code for AddOfficerFailed
Generating model code for AddOfficerResponse
Pydantic models have been successfully generated and saved to 'src_gen/agencies.py'.

Caveats

Polymorphism

The converter doesn't handle polymorphic properties yet. There's been a bit of effort put into making sure it can follow 'allOf' references, but I haven't done any investigation into how it handles 'oneOf' refs. For example, SourceDetails on complaints.

External File References

The generator only looks at one file at a time. It will not follow references to other files. The generator currently just assumes that those references exist and are valid.

Metadata

Release files for npdi-oas 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for npdi-oas 0.0.4
File Size Uploaded
npdi_oas-0.0.4.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for npdi-oas 0.0.4
File Interpreter ABI Platform
npdi_oas-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / npdi_oas-0.0.4.tar.gz

Download URL npdi_oas-0.0.4.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d32cf430f4c3975ebd9111004da471188332bf89eeb95b9c3307c1b3d91e8517
BLAKE2b-256 checksum
How to use checksums
30da2a9bb6002a50a64d9e8bbfc560061b3b2793cefac29dfd41ed8e4000cdb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / npdi_oas-0.0.4-py3-none-any.whl

Download URL npdi_oas-0.0.4-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2421a1fca08a9902c36b13d45646b82c2f499b2e2d7efe28baec557e72a3b28f
BLAKE2b-256 checksum
How to use checksums
5a628f96f79b7fa72b7a59626150a71ce008e25438040ebc4be9fc96df472c36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page