Ejemplo n.º 1
0
        public void TestConsumes()
        {
            var openApiDoc = new OpenApiDocument();
            var pathItem   = new PathItem();
            var operation  = new Operation
            {
                RequestBody = new RequestBody
                {
                    Content = new Dictionary <string, MediaType>()
                    {
                        { "application/vnd.collection+json", new MediaType
                          {
                          } }
                    }
                },
                Responses = new Dictionary <string, Response> {
                    { "200", new Response()
                      {
                          Description = "Success"
                      } }
                }
            };

            pathItem.AddOperation(OperationType.Get, operation);
            openApiDoc.Paths.PathItems.Add("/resource", pathItem);

            JObject jObject = ExportV2ToJObject(openApiDoc);

            Assert.Equal("application/vnd.collection+json", (string)jObject["paths"]["/resource"]["get"]["consumes"][0]);
        }
Ejemplo n.º 2
0
        public void TestParameter()
        {
            var openApiDoc = new OpenApiDocument();
            var pathItem   = new PathItem();
            var operation  = new Operation
            {
                Parameters = new List <Parameter> {
                    new Parameter {
                        Name   = "param1",
                        In     = InEnum.query,
                        Schema = new Schema
                        {
                            Type = "string"
                        }
                    }
                },
                Responses = new Dictionary <string, Response> {
                    { "200", new Response()
                      {
                          Description = "Success"
                      } }
                }
            };

            pathItem.AddOperation(OperationType.Get, operation);
            openApiDoc.Paths.AddPathItem("/resource", pathItem);

            JObject jObject = ExportV2ToJObject(openApiDoc);

            Assert.Equal("string", (string)jObject["paths"]["/resource"]["get"]["parameters"][0]["type"]);
        }
Ejemplo n.º 3
0
        public void TestRequestBody()
        {
            var openApiDoc = new OpenApiDocument();
            var pathItem   = new PathItem();
            var operation  = new Operation
            {
                RequestBody = new RequestBody
                {
                    Content = new Dictionary <string, MediaType>()
                    {
                        { "application/vnd.collection+json", new MediaType
                          {
                              Schema = new Schema
                              {
                                  Type      = "string",
                                  MaxLength = 100
                              }
                          } }
                    }
                },
                Responses = new Dictionary <string, Response> {
                    { "200", new Response()
                      {
                          Description = "Success"
                      } }
                }
            };

            pathItem.AddOperation(OperationType.Post, operation);
            openApiDoc.Paths.PathItems.Add("/resource", pathItem);

            JObject jObject = ExportV2ToJObject(openApiDoc);

            var bodyparam = jObject["paths"]["/resource"]["post"]["parameters"][0];

            Assert.Equal("body", (string)bodyparam["in"]);
            Assert.Equal("string", (string)bodyparam["schema"]["type"]);
            Assert.Equal("100", (string)bodyparam["schema"]["maxLength"]);
        }