airtai / fastagency

The fastest way to bring multi-agent workflows to production.
https://fastagency.ai/latest
Apache License 2.0
93 stars 7 forks source link

Fix OpenAPI client for endpoints with Path variables #234

Open rjambrecic opened 2 days ago

rjambrecic commented 2 days ago

openapi_json

  "paths": {
    "/gifs/{gifId}": {
      "get": {
        "description": "Returns a GIF given that GIF's unique ID",
        "operationId": "getGifById",
        "parameters": [
          {
            "$ref": "#/components/parameters/gifId"
          }
        ],
....
"components": {
    "parameters": {
      "gifId": {
        "description": "Filters results by specified GIF ID.",
        "in": "path",
        "name": "gifId",
        "required": true,
        "schema": {
          "format": "int32",
          "type": "integer"
        }
      },
@app.get('/gifs/{gifId}', response_model=GifsGifIdGetResponse, tags=['gifs'])
def get_gif_by_id(gif_id: int = Path(..., alias='gifId')) -> GifsGifIdGetResponse:
    """
    Get GIF by Id
    """
    pass

tools

{
            "type": "function",
            "function": {
                "description": "Returns a GIF given that GIF's unique ID",
                "name": "get_gif_by_id",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "gif_id": {
                            "type": "integer",
                            "default": Path(PydanticUndefined),
                            "description": "Filters results by specified GIF ID.",
                        }
                    },
                    "required": [],
                },
            },
        },

TypeError: Object of type Path is not JSON serializable

In this case Path parameter is 'gifId' which isn't python convention, so fastapi_code_generator changes the param name to 'gif_id' (and ads alias='gifId')

@app.get('/gifs/{gifId}', response_model=GifsGifIdGetResponse, tags=['gifs'])
def get_gif_by_id(gif_id: int = Path(..., alias='gifId')) -> GifsGifIdGetResponse:
    """
    Get GIF by Id
    """
    pass

The problems can happen foe Path/Query param names if the name isn't lower cased (or if it contains '-' char probably..)