Skip to content

Instantly share code, notes, and snippets.

@ishakoktn
Last active January 6, 2023 14:51
Show Gist options
  • Save ishakoktn/7ee948c5377c9895abd037b355addf65 to your computer and use it in GitHub Desktop.
Save ishakoktn/7ee948c5377c9895abd037b355addf65 to your computer and use it in GitHub Desktop.
from drf_yasg.generators import OpenAPISchemaGenerator
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework.permissions import IsAdminUser
class CustomSchemeGenerator(OpenAPISchemaGenerator):
def get_path_parameters(self, path, view_cls):
parameters = super().get_path_parameters(path, view_cls)
field = openapi.Parameter(
name='foo',
description="Set foo param",
required=True,
in_=openapi.IN_QUERY,
type=openapi.TYPE_INTEGER,
default=1,
)
parameters.append(field)
return parameters
schema_view = get_schema_view(
openapi.Info(title="MY API", default_version="v1"),
generator_class=CustomSchemeGenerator,
public=True,
)
# It will add to http://<domain>/path/to/?foo=<valeu> to end of all urls.
# You may would like to change IN_QUERY with IN_BODY, IN_PATH, IN_FORM or IN_HEADER.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment