Swagger Documentation with flask_apispec = array of objects

324 views Asked by At

so I'm having an annoying problem with my flask_apispec documenter.

I want the post body of my api to receive this in

kwargs:
[
    {
      "CreatedUserGuid": "string",
      "DeviceGuid": "string",
      "DeviceMetaDataGuid": "string",
      "LastModifiedUserGuid": "string",
      "MetaDataTypeId": "string",
      "MetadataFieldGroupGuid": "string",
      "MetadataFieldName": "string",
      "MetadataFieldTemplateMapGuid": "string",
      "MetadataFieldValue": "string"
    }
]

Note: flat array as bulk input is what I want.

in the swagger.json it would look like this: ( I want to achieve this through the flask_restful and flask_apispec auto documenting)

        "DMDNEsted" : {
            "type":"object",
            "properties": {
                "PartyMetaData": {
                    "type":"array",
                    "items": { 
                        "$ref":"#/components/schemas/DMDSearch"
                            
                    }
                }

            }
        },

but I cant seem to achieve this .... Using below code (see bottom of screen) I obviously get this in swags:

swagger I dont want

The code at present is:

class DMDSearch(Schema):
    CreatedUserGuid= fields.String(required=False)
    DeviceGuid= fields.String(required=False)
    DeviceMetaDataGuid= fields.String(required=False)
    LastModifiedUserGuid= fields.String(required=False)
    MetaDataTypeId= fields.String(required=False)
    MetadataFieldGroupGuid    = fields.String(required=False)
    MetadataFieldName= fields.String(required=False)
    MetadataFieldTemplateMapGuid= fields.String(required=False)
    MetadataFieldValue= fields.String(required=False)
class DMDNEsted(Schema):
    deviceMetadata = fields.Nested(DMDSearch, many=True)

class DeviceMetaDataApi(MethodResource,Resource):
    @doc(description='Manage Device Meta Data',tags=['Device Linking','Device Management'], 
    @use_kwargs(DMDNEsted, location=('json'))
    @marshal_with(DeviceMetaDataSchemaAll)
    def post(self,**kwargs):
         #blah blah handle post
    
0

There are 0 answers