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

Fix incorrect usage of Info Version #75

Closed christianhelle closed 3 years ago

christianhelle commented 3 years ago

This fixes issue #69

The idea behind all the changes here is to fix the incorrect usage of the Info Version according to the specification documentation

I also replaced hard coded route paths that start with /api/[version]/xxx to use what is specified in the OpenAPI spec Servers property if that is defined, otherwise default to /api/v1/xxx since that is what is being attempted in the BaseProjectOptions class

The documentation for the Server URL states:

A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions will be made when a variable is named in {brackets}.

The Swagger Online Editor using Swagger Petstore v3 spec generates a MVC API Controller like this:

public class PetApiController : ControllerBase
{ 
    /// <summary>
    /// Add a new pet to the store
    /// </summary>
    /// <remarks>Add a new pet to the store</remarks>
    /// <param name="body">Create a new pet in the store</param>
    /// <response code="200">Successful operation</response>
    /// <response code="405">Invalid input</response>
    [HttpPost]
    [Route("/api/v3/pet")]
    [ValidateModelState]
    [SwaggerOperation("AddPet")]
    [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "Successful operation")]
    public virtual IActionResult AddPet([FromBody]Pet body)
    { 
        throw new NotImplementedException();
    }
}

Here is a screenshot of Swagger UI when running generated code using Swagger Petstore v3 OpenAPI specifications document:

atc-generated-petstore3