# Video

# Bootstrapping A Project Using OpenAPI Generator

  1. Clone our starter repository from GitHub:
    git clone --recursive https://github.com/redhat-appdev-practice/runtimes-dotnet-ef6-openapi.git
    • This starter repo will have:
      • OpenAPI Specification for our Todo API (todo_openapi.yaml)
      • A script to launch OpenAPI Generator (generate.sh)
      • Customized Generator Templates for ASP.NETCore 3.1 Development (openapi-generator-aspnetcore3-templates)
      • A Compose file to launching all of the components together locally (docker-compose.yaml)
      • A Helm Chart for deploying the application to OpenShift or another Kubernetes platform (helm)
  2. The API Specification we are using is for a TodoList application and the API Docs can be seen HERE (opens new window)
  3. Change into the cloned directory (which will from here on be referred to as <solution root>) and generate the solution
  4. Add some of the generated classes to .gitignore
    • The code created by OpenAPI Generator should never be added to source control. It is meant to be re-generated at build time, every time. Some files, such as Startup.cs or Program.cs will probably end up being modified by us, the developers, and as such should be added to the .openapi-generator-ignore and never re-generated.
  5. Open the newly created project in your IDE
  6. Run a restore on the project
    dotnet restore
  7. Create a new directory under the RedHat.TodoList project called ControllersImpl
    • This is where our implementation code which extends the abstract generated code will live.
  8. Create a new class which extends the DefaultApiController class and name it DefaultApiControllerImpl
    • In your IDE, ensure that the new class stubs out the required abstract methods as shown below:
      public class DefaultApiControllerImpl: DefaultApiController
         public override ActionResult CreateTodo(Todo todo)
             throw new System.NotImplementedException();
         public override ActionResult DeleteTodo(Guid todoId)
             throw new System.NotImplementedException();
         public override ActionResult<Todo> GetTodo(Guid todoId)
             throw new System.NotImplementedException();
         public override ActionResult<List<Todo>> Gettodos()
             throw new System.NotImplementedException();
         public override ActionResult UpdateTodo(Guid todoId, Todo todo)
             throw new System.NotImplementedException();
  9. At this point, you can build and run the service and see the Swagger/OpenAPI Docs
    cd src/RedHat.TodoList
    dotnet run
    • Open A Browser and point it to http://localhost:8080/
    • You should see the Swagger/OpenAPI Documentation, but any attempt to use the API should return a NotImplementedException.
Last Updated: 12/18/2021, 5:53:27 PM