Coder Social home page Coder Social logo

Comments (7)

FlyinPancake avatar FlyinPancake commented on July 2, 2024 1

@ahopkins thank you you're a legend

from sanic-ext.

FlyinPancake avatar FlyinPancake commented on July 2, 2024

This issue cause my application not to start under Python 3.10.

from sanic-ext.

ahopkins avatar ahopkins commented on July 2, 2024

Can you provide a minimal sample code snippet?

from sanic-ext.

ahopkins avatar ahopkins commented on July 2, 2024

Maybe fixed by #98?

from sanic-ext.

FlyinPancake avatar FlyinPancake commented on July 2, 2024

Okay so I checked and found some bad stuff with the new serialization

from dataclasses import dataclass
from pydantic import BaseModel
from sanic import Sanic, text
from sanic_ext import openapi

app = Sanic("test")


@dataclass
class Body:
    name: str

    @classmethod
    def ctor_method(cls):
        return cls("default")


@app.post("/")
@openapi.body({"application/json": Body})
async def test(request):
    return text("Test")

This gets us a doc entry like:
image

If I try to give a type even in ""-s the server refuses to start.

But since I posted this issue, I started using pydantic models for validation and simplicity. If I switch the dataclass for an equvivalent pydantic representation like:

class Body(BaseModel):
    name: str

It throws an error:

NameError: name 'unicode' is not defined

I don't know how I'm supposed to proceed, I'll revert to 22.3 for the meantime.

from sanic-ext.

ahopkins avatar ahopkins commented on July 2, 2024

The classmethod will be a nice quick fix that I will get out and released. But unicode? 😕 Where is there Python 2 code?!

UPDATE: Looks like it it coming from standard lib. I will get this patch out and looks like it will resolve both issues.

diff --git a/sanic_ext/extensions/openapi/types.py b/sanic_ext/extensions/openapi/types.py
index 191132d..76a9c70 100644
--- a/sanic_ext/extensions/openapi/types.py
+++ b/sanic_ext/extensions/openapi/types.py
@@ -2,7 +2,7 @@ import json
 import uuid
 from datetime import date, datetime, time
 from enum import Enum
-from inspect import getmembers, isfunction
+from inspect import getmembers, isfunction, ismethod
 from typing import (
     Any,
     Dict,
@@ -312,7 +312,7 @@ def _properties(value: object) -> Dict:
         fields = {
             x: val
             for x, v in getmembers(value, _is_property)
-            if (val := _extract(v))
+            if (val := _extract(v)) and x in value.__dict__
         }
     except AttributeError:
         fields = {}
@@ -333,4 +333,4 @@ def _extract(item):
 
 
 def _is_property(item):
-    return not isfunction(item)
+    return not isfunction(item) and not ismethod(item)

from sanic-ext.

ahopkins avatar ahopkins commented on July 2, 2024

Just pushed a 22.6.1

from sanic-ext.

Related Issues (20)

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.