atc-net / atc-rest-api-generator

A REST API code generator from OpenAPI Specification in YAML or Json file format
https://atc-net.github.io/repository/atc-rest-api-generator
MIT License
19 stars 4 forks source link

Code generation based on Swagger Petstore v3 OpenAPI specifications #63

Open christianhelle opened 3 years ago

christianhelle commented 3 years ago

The purpose of this issue is to align the code produced by the ATC REST API Generator to be as close as possible to what is defined in the OpenAPI specifications document in terms of how Swagger UI is rendered. A good way of testing this is to use the Swagger Petstore v3 example specification, which has become the standard specifications document to test against used when building code generators

Tasks:

Swagger UI differences

Here are some screenshots that indicate some pretty obvious differences between the original Swagger Petstore v3 rendered by https://petstore3.swagger.io (or https://editor.swagger.io) and the ATC generated code renders Swagger UI

swagger-petstore3

atc-swagger-petstore3

Implementing missing Info metadata

The OpenAPI Info object is represented by the Microsoft.OpenApi.Models.OpenApiInfo class and is used when configuring SwaggerGenOptions

Example usage:

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddSwaggerGen(c =>
        {
            c.SwaggerDoc("1.0.5", new OpenApiInfo
            {
                Version = "1.0.5",
                Title = "Swagger Petstore - OpenAPI 3.0",
                Description = "Swagger Petstore - OpenAPI 3.0 (ASP.NET Core 3.1)",
                Contact = new OpenApiContact()
                {
                    Name = "Swagger Codegen Contributors",
                    Url = new Uri("https://github.com/swagger-api/swagger-codegen"),
                    Email = "apiteam@swagger.io"
                },
                TermsOfService = new Uri("http://swagger.io/terms/")
            });
        });
}

The correct way of doing this is by implementing IConfigureOptions<SwaggerGenOptions> so that developers can have multiple implementations of IConfigureOptions<SwaggerGenOptions> whereas using the AddSwaggerGen extension method will prevent IConfigureOptions<SwaggerGenOptions> implementations from being called

MrAndersPedersen commented 3 years ago

Hi @christianhelle Do you still need help? Please reach out.