public void CreateSecuritySchemesWorksForAuthorizationsOnEntitySetContainer() { // Arrange ODataContext context = new ODataContext(GetEdmModel()); // Act var schemes = context.CreateSecuritySchemes(); // Assert Assert.NotNull(schemes); Assert.NotEmpty(schemes); Assert.Equal(new[] { "OAuth2ClientCredentials Name", "Http Name" }, schemes.Keys); var scheme = schemes["OAuth2ClientCredentials Name"]; Assert.Equal(SecuritySchemeType.OAuth2, scheme.Type); Assert.NotNull(scheme.Flows.ClientCredentials); Assert.Equal("http://TokenUrl", scheme.Flows.ClientCredentials.TokenUrl.OriginalString); Assert.Equal("http://RefreshUrl", scheme.Flows.ClientCredentials.RefreshUrl.OriginalString); Assert.Equal("OAuth2ClientCredentials Description", scheme.Description); string json = scheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); Assert.Equal(@"{ ""type"": ""oauth2"", ""description"": ""OAuth2ClientCredentials Description"", ""flows"": { ""clientCredentials"": { ""tokenUrl"": ""http://tokenurl/"", ""refreshUrl"": ""http://refreshurl/"", ""scopes"": { ""Scope1"": ""Description 1"" } } } }".ChangeLineBreaks(), json); scheme = schemes["Http Name"]; Assert.Equal(SecuritySchemeType.Http, scheme.Type); json = scheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); Assert.Equal(@"{ ""type"": ""http"", ""description"": ""Http Description"", ""scheme"": ""Http Scheme"", ""bearerFormat"": ""Http BearerFormat"" }".ChangeLineBreaks(), json); }
/// <summary> /// Create a <see cref="OpenApiComponents"/>. /// The value of components is a Components Object. /// It holds maps of reusable schemas describing message bodies, operation parameters, and responses. /// </summary> /// <param name="context">The OData to Open API context.</param> /// <returns>The created <see cref="OpenApiComponents"/> object.</returns> public static OpenApiComponents CreateComponents(this ODataContext context) { Utils.CheckArgumentNull(context, nameof(context)); // "components": { // "schemas": …, // "parameters": …, // "responses": …, // "requestBodies": … // } return(new OpenApiComponents { // The value of schemas is a map of Schema Objects. // Each entity type, complex type, enumeration type, and type definition directly // or indirectly used in the paths field is represented as a name/value pair of the schemas map. Schemas = context.CreateSchemas(), // The value of parameters is a map of Parameter Objects. // It allows defining query options and headers that can be reused across operations of the service. Parameters = context.CreateParameters(), // The value of responses is a map of Response Objects. // It allows defining responses that can be reused across operations of the service. Responses = context.CreateResponses(), // The value of requestBodies is a map of RequestBody Objects. // It allows refining request bodies that can be reused across operations of the service. RequestBodies = context.CreateRequestBodies(), Examples = context.CreateExamples(), SecuritySchemes = context.CreateSecuritySchemes(), // Make others as null. Links = null, Callbacks = null, Extensions = null }); }