Comments (7)
@ahopkins thank you you're a legend
from sanic-ext.
This issue cause my application not to start under Python 3.10.
from sanic-ext.
Can you provide a minimal sample code snippet?
from sanic-ext.
Maybe fixed by #98?
from sanic-ext.
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:
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.
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.
Just pushed a 22.6.1
from sanic-ext.
Related Issues (20)
- [Question] OpenAPI spec available on all subdomains, and route exclusion without decorators does not seem to work.
- [Bug] Dependeny Injection throw exceptions by default if @classmethod constructors don't return value/objects
- [Feature Request]
- [Bug] OpenAPI definition does not include placeholder for "headers"
- [Bug] Json validator throws 500 instead of 400
- [Feature Request] Response Compression
- [Bug] Can't use `pydantic>=2.0` model in OpenAPI definition HOT 1
- [Bug] Can't document/exclude websocket routes with OpenAPI decorator
- [Bug] Subheader "parameter" missing in sanic extensions document
- [Bug] Can't apply openapi decorators to blueprintss' routes
- [Bug]TypeError: listener() got an unexpected keyword argument 'priority' HOT 1
- [Bug] Documentation: dead link to the setting
- Query params validation is completely broken HOT 2
- Question regarding licensing info
- [Bug] Doubly defined objects in the output specification #260 HOT 2
- [Bug] The tags in OpenAPI yaml are not effective
- [Bug] Pydantic query validation with extra data not defined in model raise's KeyError HOT 1
- add project to nix packages
- Add support for scalar.com OpenAPI documentation
- [Bug] Sanic validation extension failed to validate aliased pydantic model field
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic-ext.