forked from HumanSignal/label-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: RND-72: Add vendor extensions support in openapi autoschema (Hu…
…manSignal#5908) drf-yasg default `SwaggerAutoSchema` doesn’t provide a way to include custom extensions in the generated openapi.json. For example, we need to produce the following path to be able to use[ idiomatic method naming with fern](https://buildwithfern.com/learn/api-definition/openapi/extensions#sdk-method-names) ```yaml paths: "/api/annotations/{id}/": get: x-fern-sdk-group-name: annotations x-fern-sdk-method-name: get operationId: api_annotations_read summary: Get annotation by its ID description: Retrieve a specific annotation for a task using the annotation result ID. responses: "200": description: "" content: application/json: schema: $ref: "#/components/schemas/Annotation" tags: - Annotations ``` **Proposed solution**: - Extend SwaggerAutoSchema to include extra operation without modifying the names - Allow base settings config to specify vendor extensions prefixes **Additional changes** - openapi 3.0 incompatible namings in some paths - example of using x-fern in annotations.get --------- Co-authored-by: nik <[email protected]>
- Loading branch information
Showing
6 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.conf import settings | ||
from drf_yasg.inspectors import SwaggerAutoSchema | ||
|
||
|
||
class XVendorExtensionsAutoSchema(SwaggerAutoSchema): | ||
allowed_extensions = tuple([e.replace('-', '_') for e in settings.X_VENDOR_OPENAPI_EXTENSIONS]) | ||
|
||
def get_operation(self, operation_keys=None): | ||
operation = super(XVendorExtensionsAutoSchema, self).get_operation(operation_keys) | ||
for key, value in self.overrides.items(): | ||
if key.startswith(self.allowed_extensions): | ||
operation[key.replace('_', '-')] = value | ||
return operation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters