/// <summary>Creates the serializer contract resolver based on the <see cref="NJsonSchema.SchemaType"/>.</summary>
        /// <param name="schemaType">The schema type.</param>
        /// <returns>The settings.</returns>
        public static PropertyRenameAndIgnoreSerializerContractResolver CreateJsonSerializerContractResolver(SchemaType schemaType)
        {
            var resolver = JsonSchema4.CreateJsonSerializerContractResolver(schemaType);

            if (schemaType == SchemaType.OpenApi3)
            {
                resolver.IgnoreProperty(typeof(SwaggerDocument), "swagger");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "host");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "basePath");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "schemes");

                //resolver.IgnoreProperty(typeof(SwaggerDocument), "consumes");
                //resolver.IgnoreProperty(typeof(SwaggerDocument), "produces");

                resolver.IgnoreProperty(typeof(SwaggerOperation), "schemes");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "consumes");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "produces");

                //resolver.IgnoreProperty(typeof(SwaggerResponse), "consumes"); => TODO map to response.content
                //resolver.IgnoreProperty(typeof(SwaggerResponse), "produces");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "definitions");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "parameters");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "responses");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "securityDefinitions");

                resolver.IgnoreProperty(typeof(SwaggerResponse), "schema");
                resolver.IgnoreProperty(typeof(SwaggerResponse), "examples");
            }
            else if (schemaType == SchemaType.Swagger2)
            {
                resolver.IgnoreProperty(typeof(SwaggerDocument), "openapi");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "servers");
                resolver.IgnoreProperty(typeof(SwaggerParameter), "title");

                // TODO: Use rename for not mapped properties!
                resolver.IgnoreProperty(typeof(SwaggerPathItem), "summary");
                resolver.IgnoreProperty(typeof(SwaggerPathItem), "description");
                resolver.IgnoreProperty(typeof(SwaggerPathItem), "servers");

                resolver.IgnoreProperty(typeof(SwaggerOperation), "callbacks");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "servers");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "requestBody");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "components");
                resolver.IgnoreProperty(typeof(SwaggerParameter), "examples");

                resolver.IgnoreProperty(typeof(SwaggerResponse), "content");
                resolver.IgnoreProperty(typeof(SwaggerResponse), "links");
            }

            return(resolver);
        }
Exemple #2
0
        /// <summary>Creates the serializer contract resolver based on the <see cref="SchemaType"/>.</summary>
        /// <param name="schemaType">The schema type.</param>
        /// <returns>The settings.</returns>
        public static PropertyRenameAndIgnoreSerializerContractResolver CreateJsonSerializerContractResolver(SchemaType schemaType)
        {
            var resolver = JsonSchema4.CreateJsonSerializerContractResolver(schemaType);

            if (schemaType == SchemaType.OpenApi3)
            {
                resolver.IgnoreProperty(typeof(SwaggerDocument), "swagger");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "definitions");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "parameters");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "responses");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "securityDefinitions");
            }
            else if (schemaType == SchemaType.Swagger2)
            {
                resolver.IgnoreProperty(typeof(SwaggerDocument), "openapi");
                resolver.IgnoreProperty(typeof(SwaggerParameter), "title");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "components");
            }

            return(resolver);
        }
Exemple #3
0
        private static PropertyRenameAndIgnoreSerializerContractResolver CreateJsonSerializerContractResolver(SchemaType schemaType)
        {
            var resolver = JsonSchema4.CreateJsonSerializerContractResolver(schemaType);

            if (schemaType == SchemaType.Swagger2)
            {
                resolver.IgnoreProperty(typeof(SwaggerDocument), "openapi");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "servers");
                resolver.IgnoreProperty(typeof(SwaggerParameter), "title");

                // TODO: Use rename for not mapped properties!
                resolver.IgnoreProperty(typeof(SwaggerPathItem), "summary");
                resolver.IgnoreProperty(typeof(SwaggerPathItem), "description");
                resolver.IgnoreProperty(typeof(SwaggerPathItem), "servers");

                resolver.IgnoreProperty(typeof(SwaggerOperation), "callbacks");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "servers");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "requestBody");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "components");
                resolver.IgnoreProperty(typeof(SwaggerParameter), "examples");
                resolver.IgnoreProperty(typeof(SwaggerParameter), "x-position");

                resolver.IgnoreProperty(typeof(SwaggerResponse), "content");
                resolver.IgnoreProperty(typeof(SwaggerResponse), "links");

                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "scheme");
                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "bearerFormat");
                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "openIdConnectUrl");
                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "flows");
            }
            else if (schemaType == SchemaType.OpenApi3)
            {
                resolver.IgnoreProperty(typeof(SwaggerDocument), "swagger");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "host");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "basePath");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "schemes");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "consumes");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "produces");

                resolver.IgnoreProperty(typeof(SwaggerOperation), "schemes");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "consumes");
                resolver.IgnoreProperty(typeof(SwaggerOperation), "produces");

                //resolver.IgnoreProperty(typeof(SwaggerParameter), "x-nullable");

                //resolver.IgnoreProperty(typeof(SwaggerResponse), "consumes"); => TODO map to response.content
                //resolver.IgnoreProperty(typeof(SwaggerResponse), "produces");

                resolver.IgnoreProperty(typeof(SwaggerDocument), "definitions");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "parameters");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "responses");
                resolver.IgnoreProperty(typeof(SwaggerDocument), "securityDefinitions");

                resolver.IgnoreProperty(typeof(SwaggerResponse), "schema");
                resolver.IgnoreProperty(typeof(SwaggerResponse), "examples");
                resolver.IgnoreProperty(typeof(SwaggerResponse), "x-nullable");

                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "flow");
                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "authorizationUrl");
                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "tokenUrl");
                resolver.IgnoreProperty(typeof(SwaggerSecurityScheme), "scopes");
            }
            else
            {
                throw new ArgumentException("The given schema type is not supported.");
            }

            return(resolver);
        }