cercide / fastapi-xml

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

How to define a data class with list of elements? #12

Open rsoika opened 4 months ago

rsoika commented 4 months ago

Hi, my goal is to define a data class with fastapi-xml that a request body can look like this:

<?xml version="1.0" encoding="UTF-8"?>
<PromptDefinitionEmbeddings>
    <model>abc</model>
    <prompt>What is your name?</prompt>
    <embeddings>
        <embeddingData>embedding1</embeddingData>
        <embeddingData>embedding2</embeddingData>
    </embeddings>
</PromptDefinitionEmbeddings>

My current dataClass looks like this:


@dataclass
class PromptDefinition:

    model: str = field(
        metadata={
            "examples": ["mistral-7b-instruct-v0.2.Q3_K_S.gguf"],
            "name": "model", 
            "type": "Element"
        }
    )    

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

But I did not find out how to define a tag list in fastapi-xml. Can someone help me?

cercide commented 3 months ago

Hi @rsoika, xsdata has a pseudo wrapper Element. There is a related issue: https://github.com/tefra/xsdata/pull/710 Likewise, this is the doc reference: https://xsdata.readthedocs.io/en/latest/models/fields/#wrapper

I hope this adresses your issue.