cercide / fastapi-xml

adds xml support to fastapi
MIT License
12 stars 2 forks source link

Is it possible to set default values for dataClasses in fastapi-xml? #10

Closed rsoika closed 4 months ago

rsoika commented 5 months ago

Currently my metadata seems to be ignored by the swager UI

example class:

@dataclass
class PromptData:
    model_id: str = field()

    prompt: str = field(
        metadata={
            "example": "What is the Imixs-Workflow engine?",
            "name": "prompt", 
            "type": "Element"
        }
    )    

    output: str = field(
        metadata={
            "name": "output", 
            "type": "Element"
        }
    )   

Post Method

@app.post("/prompt", response_model=datamodel.PromptData, tags=["Imixs-AI"])
def prompt(data: datamodel.PromptData = XmlBody()) -> datamodel.PromptData:
  ...

Results in

grafik

Is there a way to set default data somehow?

cercide commented 4 months ago

Since the original json openapi fails to represent the example value, it seems that pydantic discards/ignores it somehow. Newertheless, when using examples it seems to work.

"examples": ["What is the Imixs-Workflow engine?"],

Please let me know If this solves your issue.

rsoika commented 4 months ago

Yes, this works, packaging the example text int [ ] works!

Thanks!

You just should update your examples.