Giter Site home page Giter Site logo

Enum Support about ormar HOT 4 CLOSED

collerek avatar collerek commented on May 18, 2024
Enum Support

from ormar.

Comments (4)

collerek avatar collerek commented on May 18, 2024 1

Ah, yeah forgot about the schema, will check how to add this info with choices and if/how support enum field. Thanks for the idea!

from ormar.

collerek avatar collerek commented on May 18, 2024 1

Added in 0.9.1 with #93

As for now choices appear in schema and in OpenApi schema - it's easier than defining all variants of Enums (depending on the field type) and it's more intuitive to use in my opinion.

You can always use Enum and pass it to choices as you already described. Updated the docs in this regard.

choices use the same schema options as actual Enum so should be intuitive and easy to use by API consumers in fastapi.

from ormar.

collerek avatar collerek commented on May 18, 2024

Actually it's the other way around. It's used in pydantic only, but since you cannot set the value on ormar model you cannot save it in database through ormar.

Choices adds pydantic validator to the model and that's why it should work with fastapi too (don't remember if tested this specifically).

from ormar.

jbertman avatar jbertman commented on May 18, 2024

AFAICT, I don't see the enum options in FastAPI's OpenAPI spec when I provide a choices list. The choices validator does fire after submitting a payload. It's also possible I'm just using it wrong - do you happen to have a working case with FastAPI?

Making use of Pydantic enums fed to FastAPI does a good job of informing the frontend of available options. So it would be really great to have this as feature.

from ormar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.