Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5ac1607

Browse files
sha016sliverc
authored andcommitted
Format fields in OpenAPI Schema
1 parent f32e823 commit 5ac1607

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

‎AUTHORS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Safa AlFulaij <safa1996alfulaij@gmail.com>
3939
santiavenda <santiavenda2@gmail.com>
4040
Sergey Kolomenkin <https://kolomenkin.com>
4141
Stas S. <stas@nerd.ro>
42+
Steven A. <sha0160@protonmail.com>
4243
Swaraj Baral <baralswaraj40@gmail.com>
4344
Tim Selman <timcbaoth@gmail.com>
4445
Tom Glowka <glowka.tom@gmail.com>

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ any parts of the framework not mentioned in the documentation should generally b
1616
* Avoid error when `parser_context` is `None` while parsing.
1717
* Raise comprehensible error when reserved field names `meta` and `results` are used.
1818
* Use `relationships` in the error object `pointer` when the field is actually a relationship.
19+
* Added missing inflection to the generated OpenAPI schema.
1920

2021
### Changed
2122

‎example/tests/__snapshots__/test_openapi.ambr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"entries": {
134134
"$ref": "#/components/schemas/reltomany"
135135
},
136-
"first_entry": {
136+
"firstEntry": {
137137
"$ref": "#/components/schemas/reltoone"
138138
},
139139
"type": {
@@ -541,7 +541,7 @@
541541
"entries": {
542542
"$ref": "#/components/schemas/reltomany"
543543
},
544-
"first_entry": {
544+
"firstEntry": {
545545
"$ref": "#/components/schemas/reltoone"
546546
},
547547
"type": {

‎rest_framework_json_api/schemas/openapi.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rest_framework.schemas.utils import is_list_view
88

99
from rest_framework_json_api import serializers, views
10+
from rest_framework_json_api.utils import format_field_name
1011

1112

1213
class SchemaGenerator(drf_openapi.SchemaGenerator):
@@ -655,12 +656,12 @@ def map_serializer(self, serializer):
655656
if isinstance(field, serializers.HiddenField):
656657
continue
657658
if isinstance(field, serializers.RelatedField):
658-
relationships[field.field_name] = {
659+
relationships[format_field_name(field.field_name)] = {
659660
"$ref": "#/components/schemas/reltoone"
660661
}
661662
continue
662663
if isinstance(field, serializers.ManyRelatedField):
663-
relationships[field.field_name] = {
664+
relationships[format_field_name(field.field_name)] = {
664665
"$ref": "#/components/schemas/reltomany"
665666
}
666667
continue
@@ -682,7 +683,7 @@ def map_serializer(self, serializer):
682683
schema["description"] = str(field.help_text)
683684
self.map_field_validators(field, schema)
684685

685-
attributes[field.field_name] = schema
686+
attributes[format_field_name(field.field_name)] = schema
686687

687688
result = {
688689
"type": "object",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /