Skip to content

[BUG][csharp][generichost] api_test generates wrong per-parameter model type for un-merged sibling inline enums (CS1503) #24112

Closed as not planned

Description

@seonwooj0810

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?

Description

For the csharp generichost library, when two operation parameters reference distinct inline enum models, the generated API (FakeApi.cs) types each parameter with its own model, but the generated test (FakeApiTests.cs) declares all of them with the first (form) model. This produces a CS1503 compile error.

This stays hidden as long as the sibling inline enums are merged into a single model (the current default for the fake-endpoints spec). It surfaces the moment they are emitted as separate models.

openapi-generator version

master (reproduced on builds for #24007 / #23978, which stop merging description-only-different / same-valued sibling inline schemas)

Steps to reproduce

  1. On a build where sibling inline enums are no longer merged, regenerate bin/configs/csharp-generichost-net8-formModels.yaml.
  2. Inspect the testEnumParameters operation:
    • FakeApi.cs signature: Option<TestEnumParametersEnumHeaderStringParameter> enumHeaderString, ... enumQueryString
    • FakeApiTests.cs: Option<TestEnumParametersRequestEnumFormString> enumHeaderString = default; (and enumQueryString)
  3. dotnet build fails:
    FakeApiTests.cs(226): error CS1503: Argument 3: cannot convert from
    'Option<TestEnumParametersRequestEnumFormString>' to
    'Option<TestEnumParametersEnumHeaderStringParameter>'
    

Suggested area

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache renders params via {{#allParams}}{{>OperationDataType}} — the same construct api.mustache uses — yet the resolved dataType differs between the two outputs for these params. Root cause likely in how the per-parameter dataType is populated for the test context.

Activity

  1. seonwooj0810 commented on Jun 24, 2026

    @seonwooj0810
    ContributorAuthor

    Correction: this issue is mis-framed as a csharp generichost template bug. CI demonstrates that api_test.mustache emits the correct, self-consistent output (EnumHeaderStringParameter, matching the FakeApi signature), so the templates are not at fault.

    The real, narrower problem: the generated test parameter types for testEnumParameters are environment-dependent. In some environments (e.g. my macOS setup) the api_test generation path resolves enumHeaderString/enumQueryString to RequestEnumFormString — inconsistent with the API signature and uncompilable — while CI resolves them consistently to EnumHeaderStringParameter. It reproduces stably within an environment (so it is not run-to-run nondeterminism), and the variable is not isolated: not JDK (11 vs 25 identical), not locale; a Docker check was confounded by host-filesystem mounting.

    Most useful clue: within a single generation run, FakeApi.cs and FakeApiTests.cs disagree on the same parameter's model type, and FakeApi.cs is stable across environments. So the order/environment sensitivity is specific to the api_test generation path, not global inline-model naming.

    This surfaced via #24007 / #24009 (which stop merging description-only-different / same-valued sibling inline enums); both PRs are now green after committing the CI-consistent samples. If maintainers prefer, this issue can be closed and tracked within those PRs, or kept open to fix the underlying environment-dependent test-type resolution.

  2. devhl-labs commented on Jun 27, 2026

    @devhl-labs
    Contributor

    Is this a compile issue, or incorrect http messages? Please provide a minified yaml where you see the problem.

  3. seonwooj0810 commented on Sep 1, 2026

    @seonwooj0810
    ContributorAuthor

    @devhl-labs Sorry for the slow reply, and thanks for the triage.

    To answer your question directly: it's a compile issue, not incorrect HTTP messages. Within a single generation run, FakeApiTests.cs declares the parameter as RequestEnumFormString while FakeApi.cs declares the same parameter as EnumHeaderStringParameter, so the generated test file does not compile against the API it is testing.

    On the minified yaml — that's the part I can't deliver, and it's why I'm closing this rather than leaving it open. The trigger isn't a spec of mine: it reproduces with this repository's own generichost sample generation (the FakeApi spec already in the tree). What varies is the environment, not the input — the same spec at the same commit produces the consistent EnumHeaderStringParameter output on CI and the inconsistent one in my local macOS setup, stably in each. I ruled out JDK version (11 vs 25 identical) and locale, and a Docker comparison was confounded by host-filesystem mounting, so I never isolated the variable. A minified yaml wouldn't carry the difference that actually causes this.

    Two further reasons this issue is no longer the right container for the problem:

    1. As I noted above, it is mis-framed. The title blames the csharp generichost templates, but api_test.mustache emits correct, self-consistent output — the templates are not at fault. The fault is in the api_test type-resolution path.
    2. The inline-model merging behaviour this depended on has since changed: [BUG] fix(InlineModelResolver): do not merge distinct inline enums sharing the same values (#23978) #24009 ("do not merge distinct inline enums sharing the same values") is merged, along with CI-consistent samples.

    So I'm closing it as not actionable in its current form. If FakeApi.cs and FakeApiTests.cs disagree again on current master, I'll open a fresh issue describing the full generation environment rather than a spec excerpt — that's where the reproducer actually lives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions