Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The name 'StringObject' does not exist in the current context - .NET Client #2693

Closed
christiannagel opened this issue May 22, 2023 · 4 comments · Fixed by #2706
Closed

The name 'StringObject' does not exist in the current context - .NET Client #2693

christiannagel opened this issue May 22, 2023 · 4 comments · Fixed by #2706
Assignees
Labels
Csharp Pull requests that update .net code generator Issues or improvements relater to generation capabilities. type:bug A broken experience WIP
Milestone

Comments

@christiannagel
Copy link

Using the kiota CLI, source code was created which includes StringObject.

This results in this compiler error:

The name 'StringObject' does not exist in the current context

I couldn't find a NuGet package to reference to include this class.

CLI command:

kiota generate -d http://localhost:9400/swagger/v1/swagger.json -l csharp -o .

This is the generated code including StringObject:

public async Task<CreateGameResponse?> PostAsync(CreateGameRequest body, Action<GamesRequestBuilderPostRequestConfiguration>? requestConfiguration = default, CancellationToken cancellationToken = default) {
    _ = body ?? throw new ArgumentNullException(nameof(body));
    var requestInfo = ToPostRequestInformation(body, requestConfiguration);
    var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
        {"400", StringObject.CreateFromDiscriminatorValue},
    };
    return await RequestAdapter.SendAsync<CreateGameResponse>(requestInfo, CreateGameResponse.CreateFromDiscriminatorValue, errorMapping, cancellationToken);
}

I have these NuGet packages referenced:

  <ItemGroup>
    <PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.1.1" />
    <PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.0.2" />
    <PackageReference Include="Microsoft.Kiota.Cli.Commons" Version="0.2.1-preview.1" />
    <PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.0.2" />
    <PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.0.1" />
    <PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.0.6" />
    <PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.0.1" />
    <PackageReference Include="Microsoft.OpenApi.Kiota.ApiDescription.Client" Version="0.5.0-preview2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.OpenApi.Kiota.Builder" Version="1.2.1" />
  </ItemGroup>

I'm using version 1.2.1 with the dotnet tool microsoft.openapi.kiota

Copilot says, the StringObject class is part of Microsoft.Kiota.Abstractions. I couldn't find it in this and the abstractions repo.

@andrueastman
Copy link
Member

Thanks for raising this @christiannagel,

Any chance you can share a sample of the input OpenApi reference to help replicate the scenario?

@christiannagel
Copy link
Author

I made the repo available, @andrueastman:

https://github.com/CodebreakerApp/thrive2023/tree/main/monitoring/Codebreaker.GameAPIs

For an easy access of the OpenAPI defintion, I added swagger.json:

https://github.com/CodebreakerApp/thrive2023/blob/main/monitoring/Codebreaker.GameAPIs/swagger.json

@andrueastman andrueastman self-assigned this May 25, 2023
@andrueastman andrueastman added generator Issues or improvements relater to generation capabilities. Csharp Pull requests that update .net code labels May 25, 2023
@yoyos
Copy link

yoyos commented May 25, 2023

same problem here, do you have a quick fix to build successfully ?

@andrueastman
Copy link
Member

This is related/dependent on the #2435.

Kiota has the current limitation of expecting error responses to be classes/objects. For now, we've authored #2706 to fix the compilation error and unblock making of the requests and the handling of primitive error responses will be tracked via #2435

same problem here, do you have a quick fix to build successfully ?

@yoyos You can build build the main branch once #2706 is merged. Alternatively, strip the string error responses from the reference doc.

@andrueastman andrueastman added this to the Kiota v1.3 milestone May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code generator Issues or improvements relater to generation capabilities. type:bug A broken experience WIP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants