Search code examples
asp.net-corecode-generationopenapiswagger-codegenopenapi-generator

How to generate ASP.NET Core 2 controllers from OpenAPI 3.0 schema?


I have an OpenAPI 3.0 schema YAML document that defines some API endpoints with all the required parameters and responses.

Now, I'd like to generate some boilerplate server-side code: the controllers and their methods. My API will be written using ASP.NET Core 2. So, is it possible to use some kind of generators or should I do it manually?

P.S. I know that I can generate the client-side code, but I don't need it right now...


Solution

  • Please try OpenAPI Generator, which is a community-driven version of Swagger Codegen and supports both OpenAPI spec v2, v3.

    For more information on why we (top contributors) forked it, please refer to the Q&A

    If you've docker installed, you can easily try it with the following command

    docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
        -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml \
        -g aspnetcore \
        -o /local/out/aspnetcore
    

    For any question or feedback, please open a ticket via https://github.com/OpenAPITools/openapi-generator/issues/new