@@ -110,14 +110,12 @@ def spec_for_property(cls, prop):
110
110
d .get (method , {}),
111
111
{
112
112
"requestBody" : {
113
- "content" : {
114
- prop .content_type : { "schema" : class_schema }
115
- }
113
+ "content" : {prop .content_type : {"schema" : class_schema }}
116
114
},
117
115
"responses" : {
118
116
200 : {
119
117
"content" : {
120
- prop .content_type : { "schema" : class_schema }
118
+ prop .content_type : {"schema" : class_schema }
121
119
},
122
120
"description" : "Write property" ,
123
121
}
@@ -132,9 +130,7 @@ def spec_for_property(cls, prop):
132
130
{
133
131
"responses" : {
134
132
200 : {
135
- "content" : {
136
- prop .content_type : { "schema" : class_schema }
137
- },
133
+ "content" : {prop .content_type : {"schema" : class_schema }},
138
134
"description" : "Read property" ,
139
135
}
140
136
},
@@ -149,30 +145,42 @@ def spec_for_property(cls, prop):
149
145
150
146
def spec_for_action (self , action ):
151
147
action_input = ensure_schema (action .args , name = f"{ action .__name__ } InputSchema" )
152
- action_output = ensure_schema (action .schema , name = f"{ action .__name__ } OutputSchema" )
148
+ action_output = ensure_schema (
149
+ action .schema , name = f"{ action .__name__ } OutputSchema"
150
+ )
153
151
# We combine input/output parameters with ActionSchema using an
154
152
# allOf directive, so we don't end up duplicating the schema
155
153
# for every action.
156
154
if action_output or action_input :
157
155
# It would be neater to combine the schemas in OpenAPI with allOf
158
156
# I think the code below does it - but I'm not yet convinced it is working
159
- #TODO: add tests to validate this
157
+ # TODO: add tests to validate this
160
158
plugin = get_marshamallow_plugin (self .spec )
159
+ action_input_dict = (
160
+ plugin .resolver .resolve_schema_dict (action_input )
161
+ if action_input
162
+ else {}
163
+ )
164
+ action_output_dict = (
165
+ plugin .resolver .resolve_schema_dict (action_output )
166
+ if action_output
167
+ else {}
168
+ )
161
169
action_schema = {
162
170
"allOf" : [
163
171
plugin .resolver .resolve_schema_dict (ActionSchema ),
164
172
{
165
173
"type" : "object" ,
166
- "parameters " : {
167
- "input" : plugin . resolver . resolve_schema_dict ( action_input ) ,
168
- "output" : plugin . resolver . resolve_schema_dict ( action_output ) ,
169
- }
170
- }
174
+ "properties " : {
175
+ "input" : action_input_dict ,
176
+ "output" : action_output_dict ,
177
+ },
178
+ },
171
179
]
172
180
}
173
181
# The line below builds an ActionSchema subclass. This works and
174
182
# is valid, but results in ActionSchema being duplicated many times...
175
- #action_schema = build_action_schema(action_output, action_input)
183
+ # action_schema = build_action_schema(action_output, action_input)
176
184
else :
177
185
action_schema = ActionSchema
178
186
@@ -197,16 +205,12 @@ def spec_for_action(self, action):
197
205
"description" : "Action completed immediately" ,
198
206
# Allow customising 200 (immediate response) content type?
199
207
# TODO: I'm not convinced it's still possible to customise this.
200
- "content" : {
201
- "application/json" : { "schema" : action_schema }
202
- },
208
+ "content" : {"application/json" : {"schema" : action_schema }},
203
209
},
204
210
201 : {
205
211
"description" : "Action started" ,
206
212
# Our POST 201 MUST be application/json
207
- "content" : {
208
- "application/json" : { "schema" : action_schema }
209
- },
213
+ "content" : {"application/json" : {"schema" : action_schema }},
210
214
},
211
215
},
212
216
},
0 commit comments