Skip to content

Commit cce9ada

Browse files
committed
Get "ordered" attribute from Meta
1 parent 64d3718 commit cce9ada

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/apispec/ext/marshmallow/openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def schema2jsonschema(self, schema):
177177
fields = get_fields(schema)
178178
Meta = getattr(schema, "Meta", None)
179179
partial = getattr(schema, "partial", None)
180-
ordered = getattr(schema, "ordered", False)
180+
ordered = getattr(Meta, "ordered", False)
181181

182182
jsonschema = self.fields2jsonschema(fields, partial=partial, ordered=ordered)
183183

tests/test_ext_marshmallow_openapi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from collections import OrderedDict
23
from datetime import datetime
34

45
from marshmallow import EXCLUDE, fields, INCLUDE, RAISE, Schema, validate
@@ -102,6 +103,21 @@ class BandSchema(Schema):
102103
res = openapi.schema2jsonschema(BandSchema(partial=("drummer",)))
103104
assert res["required"] == ["bassist"]
104105

106+
@pytest.mark.parametrize("ordered_schema", (True, False))
107+
def test_ordered(self, openapi, ordered_schema):
108+
class BandSchema(Schema):
109+
class Meta:
110+
ordered = ordered_schema
111+
112+
drummer = fields.Str()
113+
bassist = fields.Str()
114+
115+
res = openapi.schema2jsonschema(BandSchema)
116+
assert isinstance(res["properties"], OrderedDict) == ordered_schema
117+
118+
res = openapi.schema2jsonschema(BandSchema())
119+
assert isinstance(res["properties"], OrderedDict) == ordered_schema
120+
105121
def test_no_required_fields(self, openapi):
106122
class BandSchema(Schema):
107123
drummer = fields.Str()

0 commit comments

Comments
 (0)