Exemplo n.º 1
0
        public void ReadMetadata_WithSpecifiedMethodName_ReturnsEndpointMetadataWithCorrectNumberOfRequests(string method, bool shouldHaveRequest)
        {
            string  json    = @"{
  ""openapi"": ""3.0.0"",
  ""paths"": {
    ""/pets"": {
      """ + method + @""": """"
    }
  }
}";
            JObject jobject = JObject.Parse(json);
            OpenApiV3EndpointMetadataReader openApiV3EndpointMetadataReader = new OpenApiV3EndpointMetadataReader();

            List <EndpointMetadata> endpointMetadata = openApiV3EndpointMetadataReader.ReadMetadata(jobject).ToList();

            Assert.Single(endpointMetadata);
            Assert.Equal("/pets", endpointMetadata[0].Path);
            if (shouldHaveRequest)
            {
                Assert.Single(endpointMetadata[0].AvailableRequests);
                Assert.True(endpointMetadata[0].AvailableRequests.ContainsKey(method));
            }
            else
            {
                Assert.Empty(endpointMetadata[0].AvailableRequests);
            }
        }
Exemplo n.º 2
0
        public void ReadMetadata_WithNoResponses_ReturnsEndpointMetadata()
        {
            string  json    = @"{
  ""openapi"": ""3.0.0"",
  ""paths"": {
    ""/pets"": {
      ""post"": {
        ""summary"": ""Create a pet"",
        ""operationId"": ""createPets"",
        ""requestBody"": {
          ""content"": {

          }
        }
      }
    }
  }
}";
            JObject jobject = JObject.Parse(json);
            OpenApiV3EndpointMetadataReader openApiV3EndpointMetadataReader = new OpenApiV3EndpointMetadataReader();

            List <EndpointMetadata> endpointMetadata = openApiV3EndpointMetadataReader.ReadMetadata(jobject).ToList();

            Assert.Single(endpointMetadata);
            Assert.Equal("/pets", endpointMetadata[0].Path);
            Assert.Single(endpointMetadata[0].AvailableRequests);
            Assert.True(endpointMetadata[0].AvailableRequests.ContainsKey("post"));
        }
Exemplo n.º 3
0
        public void ReadMetadata_WithNoContent_ReturnsEndpointMetadataWithRequestButNoContentTypes()
        {
            string  json    = @"{
  ""openapi"": ""3.0.0"",
  ""paths"": {
    ""/pets"": {
      ""post"": {
        ""summary"": ""Create a pet"",
        ""operationId"": ""createPets"",
        ""responses"": {
          ""201"": {
            ""description"": ""Null response""
          }
        },
        ""requestBody"": {
          ""description"": ""A Request Body"",
          ""required"": false
        }
      }
    }
  }
}";
            JObject jobject = JObject.Parse(json);
            OpenApiV3EndpointMetadataReader openApiV3EndpointMetadataReader = new OpenApiV3EndpointMetadataReader();

            List <EndpointMetadata> endpointMetadata = openApiV3EndpointMetadataReader.ReadMetadata(jobject).ToList();

            Assert.Single(endpointMetadata);
            Assert.Equal("/pets", endpointMetadata[0].Path);
            Assert.Single(endpointMetadata[0].AvailableRequests);
            Assert.True(endpointMetadata[0].AvailableRequests.ContainsKey("post"));
            Assert.Empty(endpointMetadata[0].AvailableRequests["post"]);
        }
Exemplo n.º 4
0
        public void ReadMetadata_WithValidInput_ReturnsEndpointMetadata()
        {
            string  json    = @"{
  ""openapi"": ""3.0.0"",
  ""paths"": {
    ""/pets"": {
      ""get"": {
        ""summary"": ""List all pets"",
        ""operationId"": ""listPets"",
        ""parameters"": [
          {
            ""name"": ""limit"",
            ""in"": ""query"",
            ""required"": false,
            ""schema"": {
              ""type"": ""integer"",
              ""format"": ""int32""
            }
          }
        ],
        ""responses"": {
          ""200"": {
            ""description"": ""An paged array of pets""
          }
        }
      },
      ""post"": {
        ""summary"": ""Create a pet"",
        ""operationId"": ""createPets"",
        ""responses"": {
          ""201"": {
            ""description"": ""Null response""
          }
        },
        ""requestBody"": {
          ""content"": {
            
          }
        }
      }
    }
  }
}";
            JObject jobject = JObject.Parse(json);
            OpenApiV3EndpointMetadataReader openApiV3EndpointMetadataReader = new OpenApiV3EndpointMetadataReader();

            List <EndpointMetadata> endpointMetadata = openApiV3EndpointMetadataReader.ReadMetadata(jobject).ToList();

            IReadOnlyDictionary <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > availableRequests = endpointMetadata[0].AvailableRequests;

            Assert.Single(endpointMetadata);
            Assert.Equal("/pets", endpointMetadata[0].Path);

            Assert.Equal(2, availableRequests.Count);
            Assert.True(availableRequests.ContainsKey("get"));
            Assert.True(availableRequests.ContainsKey("post"));
        }
Exemplo n.º 5
0
        public void ReadMetadata_WithNoPaths_ReturnsEmptyListOfEndPointMetaData()
        {
            string  json    = @"{
  ""openapi"": ""3.0.0"",
  ""info"": {
    ""version"": ""v1""
  }
}";
            JObject jobject = JObject.Parse(json);
            OpenApiV3EndpointMetadataReader openApiV3EndpointMetadataReader = new OpenApiV3EndpointMetadataReader();

            List <EndpointMetadata> endpointMetadata = openApiV3EndpointMetadataReader.ReadMetadata(jobject).ToList();

            Assert.Empty(endpointMetadata);
        }
Exemplo n.º 6
0
        public void ReadMetadata_WithNoRequestBody_ReturnsEndpointMetadata()
        {
            string  json    = @"{
  ""openapi"": ""3.0.0"",
  ""paths"": {
    ""/pets"": {
      ""get"": {
        ""responses"": {
          ""200"": {
            ""description"": ""Success""
          }
        }
      },
      ""post"": {
        ""summary"": ""Create a pet"",
        ""operationId"": ""createPets"",
        ""responses"": {
          ""201"": {
            ""description"": ""Null response""
          }
        },
        ""requestBody"": {
          ""content"": {
            
          }
        }
      }
    }
  }
}";
            JObject jobject = JObject.Parse(json);
            OpenApiV3EndpointMetadataReader openApiV3EndpointMetadataReader = new OpenApiV3EndpointMetadataReader();

            List <EndpointMetadata> endpointMetadata = openApiV3EndpointMetadataReader.ReadMetadata(jobject).ToList();

            IReadOnlyDictionary <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > availableRequests = endpointMetadata[0].AvailableRequests;

            Assert.Single(endpointMetadata);
            Assert.Equal("/pets", endpointMetadata[0].Path);

            Assert.Equal(2, availableRequests.Count);
            Assert.True(availableRequests.ContainsKey("get"));
            Assert.True(availableRequests.ContainsKey("post"));
        }