Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            //services.AddApiVersioning(options =>
            //{
            //    options.ReportApiVersions = true;
            //    options.DefaultApiVersion = new ApiVersion(1, 0);
            //    //options.AssumeDefaultVersionWhenUnspecified = true;
            //});
            //services.AddVersionedApiExplorer(options =>
            //{
            //    options.GroupNameFormat = "'v'VVV";
            //    options.SubstituteApiVersionInUrl = true;
            //});

            // >>>> setup NRestGen services
            services.AddNRestGen();
            AddODataFormatters(services);

            // >>>> Set JSON serialization options
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.IgnoreNullValues            = true;
                options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
#if DEBUG
                options.JsonSerializerOptions.WriteIndented = true;
#endif
            });

            // Register the Swagger Generator service. This service is responsible for genrating Swagger Documents.
            // Note: Add this service at the end after AddMvc() or AddMvcCore().
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "NRestGen Demo API",
                    Version     = "v1",
                    Description = "This API is generated by NRestGen.",
                    Contact     = new OpenApiContact
                    {
                        Name  = "Marc Jacobi",
                        Email = "*****@*****.**",
                        Url   = new Uri("https://github.com/obiwanjacobi/NRestGen"),
                    },
                });
            });

#if DEBUG
            var resourceModel = ResourceModelBuilder.Build();
            using var writer = XmlWriter.Create("ResourceModel.xml");
            CsdlWriter.TryWriteCsdl(resourceModel, writer, CsdlTarget.OData, out var errors);
#endif
        }
Exemple #2
0
        public static IEndpointRouteBuilder AddNRestGen(this IEndpointRouteBuilder endpoints)
        {
            var resourceModel = ResourceModelBuilder.Build();

            endpoints.MapODataRoute("OData", "api", resourceModel);
            endpoints.EnableDependencyInjection();
            return(endpoints
                   .Select()
                   .Filter()
                   .Count()
                   .MaxTop(100)
                   );
        }