I have a pydantic model ModelX, with member Enums defined. The script should run as is.
from enum import Enum from pydantic import BaseModel,Field,schema_json_of from typing import Optional class FirstEnumList(str, Enum): VAL1="VAL1" VAL2="VAL2" VAL3="VAL3" class SecondEnumList(str, Enum): VAL4="VAL4" VAL5="VAL5" class ModelX(BaseModel): V: Optional[FirstEnumList]=Field(FirstEnumList.VAL1, alias='value1') A: Optional[str] B: Optional[int] P: Optional[SecondEnumList]=Field(SecondEnumList.VAL4, alias='valueP') print (schema_json_of(ModelX)) '''Output below for schema_json_of {"title": "ParsingModel[ModelX]", "$ref": "#/definitions/ModelX", "definitions": { "FirstEnumList": { "title": "FirstEnumList", "description": "An enumeration.", "enum": ["VAL1", "VAL2", "VAL3"], "type": "string" }, "SecondEnumList": { "title": "SecondEnumList", "description": "An enumeration.", "enum": ["VAL4", "VAL5"], "type": "string" }, "ModelX": { "title": "ModelX", "type": "object", "properties": { "value1": { "default": "VAL1", "allOf": [{"$ref": "#/definitions/FirstEnumList"}] }, "A": { "title": "A", "type": "string" }, "B": { "title": "B", "type": "integer" }, "valueP": { "default": "VAL4", "allOf": [{"$ref": "#/definitions/SecondEnumList"}]} } } } } ''' I want to export this model as a JSON with the list of all Enum values. Something like
{ "value1": { "allOf": [ "VAL1", "VAL2", "VAL3" ] }, "A": { "type": "string" }, "B": { "type": "integer" }, "valueP": { "allOf": [ "VAL4", "VAL5" ] } } I am looking to return this Json as a response of my api call, all Enum values, it can be under "allOf" key or some other better way. This way the response has all the possible enum values and the consumer of this response can use it to pre-validate requests, or even show them on a UI screen.
Let me know in case more details or explanation is required.
AandB? Why doesAmap to an empty string? What doesBmap to? (This isn't even valid JSON at all.) Please provide a complete reproducible example and desired output that is actually valid..