question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Client method name change when using OpenAPI 3 instead of 2

See original GitHub issue

I wanted to use OpenAPI 3 to generate the axios typescript client I use for my project, mainly to use the same enum by reference, rather than having multiple instances being generated (this works fine).

For this, I’ve changed following references. Before:

<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="4.5.5" />

After:

<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.0-rc8" />

I use cake for the generation, but the generation is the same when using NswagStudio. With: #addin nuget:?package=Cake.CodeGen.NSwag&version=1.2.0&loaddependencies=true Before:

Task ("Frontend-Generate-API-Client")
    .Does (() => {
        var settings = new TypeScriptClientGeneratorSettings {
        ClassName = "{controller}Client",
        Template = TypeScriptTemplate.Axios,
        OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator (),
        ExceptionClass = "ApiException",
        GenerateDtoTypes = true
        };

        NSwag.FromJsonSpecification (new Uri (localApiUri))
            .GenerateTypeScriptClient (apiClientFilePath, settings);

        Information ($"The client API has been updated in '{apiClientFilePath}'");
    });

After:

Task ("Frontend-Generate-API-Client")
    .Does (() => {
        var settings = new TypeScriptClientGeneratorSettings {
            ClassName = "{controller}Client",
            Template = TypeScriptTemplate.Axios,
            OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator(),
            ExceptionClass = "ApiException",
            GenerateDtoTypes = true,
            CodeGeneratorSettings = {
                SchemaType = NJsonSchema.SchemaType.OpenApi3
            }
        };

        NSwag.FromJsonSpecification (new Uri (localApiUri))
            .GenerateTypeScriptClient (apiClientFilePath, settings);

        Information ($"The client API has been updated in '{apiClientFilePath}'");
    });

Now the method names in the client aren’t being generate as before. Here’s an example: Before: getUserByUserId(id: string): Promise<UserResponseDto> {...} After: users4(id: string): Promise<UserResponseDto> {...}

Here’s the commit including all relevant changes. It can easily be tested and reproduced with it, if needed.

What do I have to change in order to have nice method names again?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Sennevdscommented, Aug 24, 2020

I have the same problem. After updating to dotnet core 3 and updating Swashbuckle.AspNetCore the client generated files are different. @taconaut did you find a solution for this?

1reaction
RicoSutercommented, Dec 16, 2019

Are you sure you are still using nswag in the v3 case? Can you also provide the generated specs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

When using openapi-generator can you customize method ...
Using openapi -generator to generate a C# API client using an openapi v3.0 specification. Is there a way to customize the methodNames of...
Read more >
OpenAPI Specification - Version 3.0.3
The schema exposes two types of fields: Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for...
Read more >
Inheritance and Polymorphism
OAS 3 This guide is for OpenAPI 3.0. Inheritance and Polymorphism. Model Composition. In your API, you may have model schemas that share...
Read more >
Using OpenAPI and Swagger UI
This guide explains how your Quarkus application can expose its API description through an OpenAPI specification and how you can test it via...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & ...
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found