cercide / fastapi-xml Goto Github PK
View Code? Open in Web Editor NEWadds xml support to fastapi
License: MIT License
adds xml support to fastapi
License: MIT License
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
Is there a way to set default data somehow?
Is it possible to define a dataclass that represents a string wrapped in CDATA
like:
<PromptData>
<prompt><![CDATA[
.....
]]></prompt>
</PromptData>
I just want to thank you for your great work! fastapi-xml is absolutely amazing and fills the gap in the FastAPI library !
๐ ๐ ๐ ๐
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,
}
)
Hi @cercide, any plans to support pydantic v2.x.x
?
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
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.