ansys / ansys/pyhps

Consider replacing Marshmallow with Pydantic for REST models

Open
#76 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
5
Forks
1
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Reasons:
* `marshmallow` requires splitting models into schemas and actual resources
* `pydantic` has an interesting [code generator](https://pydantic-docs.helpmanual.io/datamodel_code_generator/) we could use to auto-generate (some of the) models from the openapi spec
* `pydantic` has native support for typehints

Possible critical points:
* We currently rely on marshmallow.missing to mark undefined fields (either not specified client-side or not returned by the server for a certain request). How to best implement this concept in pydantic? See e.g. https://github.com/pydantic/pydantic/issues/1223 and https://stackoverflow.com/questions/66229384/pydantic-detect-if-a-field-value-is-missing-or-given-as-null
* Auto-generated models probably wouldn't cover well some of the "polymorphic" resources we have, like parameter definitions. We might need to handle those manually.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the current Marshmallow schemas and REST resources, then compare their missing-field behavior with the Pydantic references linked in the issue. Examine whether the OpenAPI code generator can cover the existing models, especially polymorphic resources such as parameter definitions. Done would require an agreed migration approach that addresses these gaps.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.