Comments (3)
Makes absolute sense, and I would happily welcome a PR. The code base was largely copied from the earlier sanic-openapi
package, which had very limited type hinting support. Because of that, there are a lot of fields that are implicit and not easily discovered. This is something that needs to be resolved in the long run. In the short run, I think that it exposed a problem that example
is not one of them as you indicated.
from sanic-ext.
Cool! I was thinking that since auto-generated examples could lead to unrealistic examples, it could be useful to have a FactoryBoy-ready type approach, where example
accepts an instance of RequestBody.body
, Response.content
etc
So you could have
@openapi.definition(
summary="Create a new MusicID",
description="Create a new **MusicID** via a deserialized MusicID",
body=RequestBody(serializers.MusicIDRequest, example=MusicIDRequestFactory.build()),
response=[
oa.Response(Error, status=429, description="too many requests"),
oa.Response(Error, status=400, description="bad request"),
oa.Response(Error, status=401, description="user not authenticated"),
oa.Response(serializers.MusicIDResponse, example=serializers.MusicIDResponseFactory.build()),
],
)
And the example fields would be realistic since we'd permit the usage of Faker
, FuzzyAttributes
...
So is up to the User to match the criteria of the field
class MusicIDRequestFactory(factory.Factory):
"""
MusicIDRequest factory
"""
name: str = factory.Sequence(lambda n: "Section configuration %s" % n)
identifier: str = faker.Faker('uuid')
creation_title: str = factory.Sequence(lambda n: "Create your Section %s!" % n)
source: str = fuzzy.FuzzyChoice(SectionConfig.Source, getter=lambda x: x[0])
optional: bool = False
max_items: int = fuzzy.FuzzyInteger(1, 10)
class Meta:
model = MusicIDRequestFactory
I'd love to hear your thoughts about it
from sanic-ext.
Ooo! That's a nice touch. I'm on board with this. Let me know if you want to spec it out with me, or if you want to just throw together a proposal first.
from sanic-ext.
Related Issues (20)
- [Feature Request] Blueprints cannot access the 'decorator way' of managing / rendering templates
- [Bug] Dependency injection not working for requests received during server is initializing HOT 1
- [Question] How to set field description on data class?
- [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 2
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.