Repository: marshmallow-code/apispec

Issue:
ordered is part of the Meta of a schema
ordered is part of Meta see https://marshmallow.readthedocs.io/en/stable/marshmallow.schema.html#marshmallow.schema.Schema.Meta, however it is currently pulled from the schema see https://github.com/marshmallow-code/apispec/blob/dev/src/apispec/ext/marshmallow/openapi.py#L180

Work around
```python
import marshmallow

class Foo(marshmallow.Schema):
    class Meta:
        ordered = True

    ordered = True
```

Discussion:

Patch:
diff --git a/src/apispec/ext/marshmallow/openapi.py b/src/apispec/ext/marshmallow/openapi.py
index 273af20..24866c2 100644
--- a/src/apispec/ext/marshmallow/openapi.py
+++ b/src/apispec/ext/marshmallow/openapi.py
@@ -177,7 +177,7 @@ class OpenAPIConverter(FieldConverterMixin):
         fields = get_fields(schema)
         Meta = getattr(schema, "Meta", None)
         partial = getattr(schema, "partial", None)
-        ordered = getattr(schema, "ordered", False)
+        ordered = getattr(Meta, "ordered", False)
 
         jsonschema = self.fields2jsonschema(fields, partial=partial, ordered=ordered)
 


Test patch:
diff --git a/tests/test_ext_marshmallow_openapi.py b/tests/test_ext_marshmallow_openapi.py
index 83ea7ad..f417377 100644
--- a/tests/test_ext_marshmallow_openapi.py
+++ b/tests/test_ext_marshmallow_openapi.py
@@ -1,4 +1,5 @@
 import pytest
+from collections import OrderedDict
 from datetime import datetime
 
 from marshmallow import EXCLUDE, fields, INCLUDE, RAISE, Schema, validate
@@ -102,6 +103,21 @@ class TestMarshmallowSchemaToModelDefinition:
         res = openapi.schema2jsonschema(BandSchema(partial=("drummer",)))
         assert res["required"] == ["bassist"]
 
+    @pytest.mark.parametrize("ordered_schema", (True, False))
+    def test_ordered(self, openapi, ordered_schema):
+        class BandSchema(Schema):
+            class Meta:
+                ordered = ordered_schema
+
+            drummer = fields.Str()
+            bassist = fields.Str()
+
+        res = openapi.schema2jsonschema(BandSchema)
+        assert isinstance(res["properties"], OrderedDict) == ordered_schema
+
+        res = openapi.schema2jsonschema(BandSchema())
+        assert isinstance(res["properties"], OrderedDict) == ordered_schema
+
     def test_no_required_fields(self, openapi):
         class BandSchema(Schema):
             drummer = fields.Str()