Giter Club home page Giter Club logo

fastapi-xml's People

Contributors

cercide avatar va-h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fastapi-xml's Issues

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

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?

CDATA element in dataclass?

Is it possible to define a dataclass that represents a string wrapped in CDATA

like:

<PromptData>
	<prompt><![CDATA[
.....
]]></prompt>
</PromptData> 

Great Work! :thumbsup:

I just want to thank you for your great work! fastapi-xml is absolutely amazing and fills the gap in the FastAPI library !

๐Ÿ’– ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘

FastAPI with xsData generated classes raises FastAPIError

I just by accident found your project, and I would consider the approach to be both interesting and useful. As a xsData user I am very interested in this bridge. You write that FastAPI-XML supports xsData classes "Together, fastapi handles xml data structures using dataclasses generated by xsdata."

I have created ``xsdata generate -p ojp -ss clusters --compound-fields /home/skinkie/Sources/OJP/OJP.xsd``` I have modified the "HelloWorld" example with my root element "Ojp". Still I end up with the error below. What would create the full end to end solution to support below?

@[app.post](http://app.post/)("/ojp2023", response_model=Ojp, tags=["Open Journey Planner"])
def echo(x: Ojp = XmlBody()) -> Ojp:
    return x
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'ojp.ojp.Ojp'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/

Your HelloWorld looks like:

@dataclass
class HelloWorld:
    message: str = field(metadata={"example": "Foo","name": "Message", "type": "Element"})

While the generated Ojp interface looks like below.

@dataclass
class Ojp:
    """
    Root element for OJP messages based on SIRI message exchange protocol.
    """
    class Meta:
        name = "OJP"
        namespace = "http://www.siri.org.uk/siri"

    ojprequest: Optional[Ojprequest] = field(
        default=None,
        metadata={
            "name": "OJPRequest",
            "type": "Element",
        }
    )
    ojpresponse: Optional[Ojpresponse] = field(
        default=None,
        metadata={
            "name": "OJPResponse",
            "type": "Element",
        }
    )
    extensions: Optional[Extensions2] = field(
        default=None,
        metadata={
            "name": "Extensions",
            "type": "Element",
        }
    )
    version: str = field(
        init=False,
        default="1.1-dev",
        metadata={
            "type": "Attribute",
            "required": True,
        }
    )

Example app using FastAPI routes folder

Can you provide an example of a fastapi-xml/FastAPI app using a routes folder?

If you place your echo example in echo.py in a routes folder we no longer have the @app.get decorator defined and using

This can issue can be closed.

Here is a working routes/health.py example.

from dataclasses import dataclass, field
from fastapi import APIRouter
from fastapi_xml import XmlBody
from fastapi_xml import NonJsonRoute

router = APIRouter()
router.route_class = NonJsonRoute

@dataclass
class HealthBody:
    message: str = field(metadata={"example": "Server Health","name": "Message", "type": "Element"})

@router.post('/health', response_model=HealthBody, tags=["Health"])
async def postHealth(x: HealthBody = XmlBody()) -> HealthBody:
    x.message += ' Healthy!'
    return x

Example returns bad request error

Hi,

I need to develop a simple xml api and wanted to make use of your package but I'm having some issues getting the example to work. Opening the docs and executing the example request on the /echo post endpoint at "Try it out" returns a bad request error with response body:

{
  "detail": "Unknown property echo:message"
}

Can you guide me to a solution?

Thanks in advance

How to define a data class with list of elements?

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?

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.