Setting the schema ref in IOperationFilter

98 views
Skip to first unread message

Tom Allen

unread,
Jul 5, 2017, 6:44:02 AM7/5/17
to Swagger
I am trying to write my own filter and am having an issue with setting the schema.ref

My Apply method currently looks something like this:

public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
   
if (operation.operationId == "Image_Test")
   
{
        operation
.consumes.Add("multipart/form-data");
        operation
.parameters = new List<Parameter>
       
{
           
new Parameter
           
{
                name
= "imageJson",
                required
= true,
                description
= "Image data (json)",
               
@in = "formData",
                type
= "string",
                schema
= new Schema {@ref = "ImageData"}
           
},
           
new Parameter
           
{
                name
= "fileStream",
                required
= true,
                type
= "file",
                description
= "File stream",
               
@in = "formData"
           
}
       
};
   
}
}


When I start my service, I see the ImageData model correctly defined under the DataType column, but I am also getting the following validation error:

{"messages":["attribute paths.'/api/Image/AddWithFile'(post).[imageJson].schema is unexpected"],"schemaValidationMessages":[{"level":"error","domain":"validation","keyword":"oneOf","message":"instance failed to match exactly one schema (matched 0 out of 2)","schema":{"loadingURI":"http://swagger.io/v2/schema.json#","pointer":"/definitions/parametersList/items"},"instance":{"pointer":"/paths/~1api~1Image~1AddWithFile/post/parameters/0"}}]}

What am I doing wrong in my filter?

Ron Ratovsky

unread,
Jul 5, 2017, 12:33:45 PM7/5/17
to swagger-sw...@googlegroups.com

Is this Swashbuckle? If so, questions regarding it should go to the project’s repo as it’s not a project we maintain.

 

That said, it looks like you’re trying to set a schema to a formData parameter, and that’s not supported by the spec.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages