public void SerializeBasicOperationAsV3JsonWorks() { // Arrange var expected = @"{ ""responses"": { } }"; // Act var actual = BasicOperation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual.Should().Be(expected); }
public void GenerationDoesNotThrow() { var provider = new Mock <IWebHookTriggerProvider>(); provider.Setup(p => p.GetAvailableTriggers()).Returns(new Dictionary <string, WebHookTrigger> { ["my.trigger"] = new WebHookTrigger { Description = "blabla", Id = "my.trigger", Template = new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { ["prop1"] = new OpenApiSchema { Type = "string" } } } }, ["my.trigger.2"] = new WebHookTrigger { Description = "blabla2", Id = "my.trigger.2", Template = new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { ["prop2"] = new OpenApiSchema { Type = "integer" } } } } }); var generator = new CallbacksGenerator(provider.Object); var result = generator.GenerateCallbacks(); var operation = new OpenApiOperation { Callbacks = result }; var json = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); var yaml = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); }
public void GenerationDoesNotThrow() { var provider = new Mock <IWebHookTriggerProvider>(); provider.Setup(p => p.GetAvailableTriggers()).Returns(new Dictionary <string, WebHookTrigger> { ["my.trigger"] = new WebHookTrigger { Description = "blabla", Id = "my.trigger", Schema = new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { ["prop1"] = new OpenApiSchema { Type = "string" } } } }, ["my.trigger.2"] = new WebHookTrigger { Description = "blabla2", Id = "my.trigger.2", Schema = new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { ["prop2"] = new OpenApiSchema { Type = "integer" } } } } }); var filter = new WebHookSubscriptionFilter(provider.Object); var context = new OperationFilterContext(null, new SchemaGenerator(new SchemaGeneratorOptions(), null), new SchemaRepository(), typeof(CallbackGeneratorTests).GetMethod(nameof(WebHookSubscriptionFilterTests))); var operation = new OpenApiOperation(); filter.Apply(operation, context); var json = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); var yaml = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); }
public void SerializeOperationWithNullCollectionAsV2JsonWorks() { // Arrange var expected = @"{ ""responses"": { } }"; var operation = new OpenApiOperation { Parameters = null, Servers = null, }; // Act var actual = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual.Should().Be(expected); }
public void SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() { // Arrange var expected = @"{ ""tags"": [ ""tagName1"", ""tagId1"" ], ""summary"": ""summary1"", ""description"": ""operationDescription"", ""externalDocs"": { ""description"": ""externalDocsDescription"", ""url"": ""http://external.com"" }, ""operationId"": ""operationId1"", ""parameters"": [ { ""name"": ""parameter1"", ""in"": ""path"" }, { ""name"": ""parameter2"", ""in"": ""header"" } ], ""requestBody"": { ""description"": ""description2"", ""content"": { ""application/json"": { ""schema"": { ""maximum"": 10, ""minimum"": 5, ""type"": ""number"" } } }, ""required"": true }, ""responses"": { ""200"": { ""$ref"": ""#/components/responses/response1"" }, ""400"": { ""content"": { ""application/json"": { ""schema"": { ""maximum"": 10, ""minimum"": 5, ""type"": ""number"" } } } } }, ""security"": [ { ""securitySchemeId1"": [ ], ""securitySchemeId2"": [ ""scopeName1"", ""scopeName2"" ] } ], ""servers"": [ { ""url"": ""http://server.com"", ""description"": ""serverDescription"" } ] }"; // Act var actual = AdvancedOperationWithTagsAndSecurity.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual.Should().Be(expected); }
private static OpenApiOperation Clone(OpenApiOperation operation) { var json = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); return(JsonConvert.DeserializeObject <OpenApiOperation>(json)); }
public void SerializeOperationWithFormDataAsV3JsonWorks() { // Arrange var expected = @"{ ""summary"": ""Updates a pet in the store with form data"", ""description"": """", ""operationId"": ""updatePetWithForm"", ""parameters"": [ { ""name"": ""petId"", ""in"": ""path"", ""description"": ""ID of pet that needs to be updated"", ""required"": true, ""schema"": { ""type"": ""string"" } } ], ""requestBody"": { ""content"": { ""application/x-www-form-urlencoded"": { ""schema"": { ""required"": [ ""name"" ], ""properties"": { ""name"": { ""type"": ""string"", ""description"": ""Updated name of the pet"" }, ""status"": { ""type"": ""string"", ""description"": ""Updated status of the pet"" } } } }, ""multipart/form-data"": { ""schema"": { ""required"": [ ""name"" ], ""properties"": { ""name"": { ""type"": ""string"", ""description"": ""Updated name of the pet"" }, ""status"": { ""type"": ""string"", ""description"": ""Updated status of the pet"" } } } } } }, ""responses"": { ""200"": { ""description"": ""Pet updated."" }, ""405"": { ""description"": ""Invalid input"" } } }"; // Act var actual = _operationWithFormData.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual.Should().Be(expected); }