Пример #1
0
        public void ParsingAttributeElsewhereThanInPathOrQueryShouldReturnNull(ParameterLocation parameterLocation)
        {
            OpenApiParameter parameter = new OpenApiParameter {
                In = parameterLocation
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.IsNull(parsedAttribute);
        }
Пример #2
0
        public void ParsingAttributeWithNoTypeOrFormatShouldReturnNull()
        {
            OpenApiParameter parameter = new OpenApiParameter {
                Schema = new OpenApiSchema {
                    Type = null, Format = null
                }
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.IsNull(parsedAttribute);
        }
Пример #3
0
        public void ParsingPathAttributeWithQueryLocation()
        {
            OpenApiParameter parameter = new OpenApiParameter
            {
                Schema = new OpenApiSchema {
                    Type = "string", Format = null
                },
                In = ParameterLocation.Query
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.AreEqual("Query", parsedAttribute.Location);
        }
Пример #4
0
        static List <UriAttribute> ParseUriAttributes(OpenApiOperation operation)
        {
            List <UriAttribute> attributes = new List <UriAttribute>();

            foreach (var parameter in operation.Parameters)
            {
                var attribute = AttributeParser.ParseAttribute(parameter);
                if (attribute != null)
                {
                    attributes.Add(attribute);
                }
            }

            return(attributes);
        }
Пример #5
0
        public void ParsingPathAttributeWithValidContentExample()
        {
            string           attributeContent = "test";
            OpenApiParameter parameter        = new OpenApiParameter
            {
                In = ParameterLocation.Path, Schema = new OpenApiSchema {
                    Type = "string", Format = null
                },
                Example = new OpenApiString(attributeContent)
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.AreEqual(attributeContent, parsedAttribute.ExampleValue);
        }
Пример #6
0
        public void ParsingAttributeWithInheritingExampleJustFromDataType()
        {
            OpenApiParameter parameter = new OpenApiParameter
            {
                In     = ParameterLocation.Path,
                Schema = new OpenApiSchema {
                    Type = "string", Format = null
                },
                Example  = null,
                Examples = new Dictionary <string, OpenApiExample>()
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.IsNotNull(parsedAttribute);
            Assert.IsTrue(!string.IsNullOrEmpty(parsedAttribute.ExampleValue));
        }
Пример #7
0
        public void CheckThatParsedAttributeHasCorrectlySetDataTypeAndFormat()
        {
            OpenApiParameter parameter = new OpenApiParameter
            {
                In     = ParameterLocation.Path,
                Schema = new OpenApiSchema {
                    Type = "string", Format = null
                },
                Example  = null,
                Examples = new Dictionary <string, OpenApiExample>()
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.IsNotNull(parsedAttribute);
            Assert.IsTrue(!string.IsNullOrEmpty(parsedAttribute.ExampleValue));
            Assert.AreEqual(parameter.Schema.Type, parsedAttribute.Type);
            Assert.AreEqual(parameter.Schema.Format, parsedAttribute.Format);
        }
Пример #8
0
        public void ParsingAttributeWithValidContentExamples()
        {
            string           attributeContent = "test";
            OpenApiParameter parameter        = new OpenApiParameter
            {
                In = ParameterLocation.Path, Schema = new OpenApiSchema {
                    Type = "string", Format = null
                },
                Examples = new Dictionary <string, OpenApiExample>
                {
                    { "testKey 1", new OpenApiExample {
                          Value = new OpenApiString(attributeContent)
                      } },
                    { "testKey 2", new OpenApiExample {
                          Value = new OpenApiString(attributeContent)
                      } }
                }
            };

            var parsedAttribute = AttributeParser.ParseAttribute(parameter);

            Assert.AreEqual(attributeContent, parsedAttribute.ExampleValue);
        }