Comments (2)
sorry, I wasn't very clear posting this. This idea is to expose the schema via an API endpoint so that another app can render a UI based on the schema. for something like a dropdown with labels and values, serialization like that would be necessary
from typical.
Hey @dodumosu -
Unfortunately, JsonSchema can't express enums in this way.
If I understand correctly, you want a schema something like this:
{
"type": "array",
"items": {
"type": "object",
"required": ["label", "value"],
"additionalProperties": false,
"properties": {
"label": {"type": "string"},
"value": {"type": "string"}
}
}
}
You could be exceptionally strict and create a unique object type for each enumerated choice, but that will be quite brittle and mean that with every addition or subtraction from your enumeration on the backend, you have a large schema migration on the frontend. In my experience, a solution like the above affords you some flexibility between backend and frontend while allowing your application to evolve.
It can also allow you to opt to change your storage format for these enumerations - perhaps one day you scale to a point where you want to make these choices configurable via updates from an operations team rather than engineers having to update them. In this scenario, you can migrate to storing these enumerations in a database and the frontend is none-the-wiser.
from typical.
Related Issues (20)
- AttributeError when the annotation contains Callable
- Support new type union operator `|` in Python3.10
- Still not working with PEP 604 Union Operators HOT 5
- Unpredictable behavior with Union[pd.Series, pd.DataFrame] HOT 1
- float should not been converted to int with Union[float, int] HOT 3
- typic.field not compatible with old version, parameter `default` should be postional
- Wrong behavior when Union with constrained types HOT 8
- Couldn't evaluate type ForwardRef pandas DataFrame HOT 2
- callable instance should be the treated as a function or class? HOT 1
- Not compatible with pandas v1.3.3 HOT 2
- add parameter to typic.klass
- Transmute is broken with dicts of dataclasses with default values HOT 2
- TypeError if annotated typing.Deque[int]
- issubclass error after version 2.6.4
- tojson and primitive fails when class is derived
- Decimal serialization and deserialization HOT 2
- Use orjson for other libraries benchmark
- Version conflicts installed the pinned typing-extensions HOT 2
- Question on your approach to strict mode HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typical.