Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7093
Closed
Open
Issue created Jul 31, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][aspnetcore] Doesn't work well with WebApplicationFactory

Created by: Sshnyari

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Starting from asp.net core 3.0, when making integration tests with WebApplicationFactory, it searches for either

  • a method called CreateWebHostBuilder with a return an IWebHostBuilder
  • or one called CreateHostBuilder returning an IHostBuilder.

It crashes if it doesn't find any of those two.

In the mustache template for Program.cs, we have a mix of both (IHostBuilder CreateWebHostBuilder).

I suggest changing it to IHostBuilder CreateHostBuilder().

openapi-generator version

v4.3.1

OpenAPI declaration file content or url

the petstore.yaml file would do

Command line used for generation

the default one

Steps to reproduce
  1. generate the code
  2. add a integration tests project that uses WebApplicationFactory
  3. start the test it crashes with the message : System.InvalidOperationException : No method 'public static IHostBuilder CreateHostBuilder(string[] args)' or 'public static IWebHostBuilder CreateWebHostBuilder(string[] args)' found on 'API.Program'. Alternatively, WebApplicationFactory`1 can be extended and 'CreateHostBuilder' or 'CreateWebHostBuilder' can be overridden to provide your own instance.
Related issues/PRs

none

Suggest a fix

I suggest changing it to IHostBuilder CreateHostBuilder().

Assignee
Assign to
Time tracking