Git Product home page Git Product logo

Comments (6)

damianh avatar damianh commented on July 21, 2024 1

The issue seems related to this bit of code.

var name = generator.BaseSettings.OperationNameGenerator
.GetOperationName(document, kv.Key, verb, operation)
.CapitalizeFirstCharacter()
.ConvertKebabCaseToPascalCase();

from refitter.

damianh avatar damianh commented on July 21, 2024 1

I asked ChatGPT :).

Probably not quite correct but might be a pointer.


You are seeing the path in the operation name because of how NSwag generates operation names by default. NSwag uses the OperationNameGenerator to determine how to create operation names. By default, it uses the DefaultOperationNameGenerator, which simply concatenates the HTTP method and the path.

If you want to generate a different style of operation name, you will have to provide a custom implementation of IOperationNameGenerator. Here's a sample implementation that should create operation names in the format you want:

using System.Linq;
using NJsonSchema;
using NSwag;

public class CustomOperationNameGenerator : IOperationNameGenerator
{
    public bool SupportsMultipleClients { get; } = false;

    public string GetClientName(OpenApiDocument document, string path, OpenApiOperation operation, OpenApiSchemaResolver schemaResolver)
    {
        return string.Empty;
    }

    public string GetOperationName(OpenApiDocument document, string path, string httpMethod, OpenApiOperation operation, OpenApiSchemaResolver schemaResolver)
    {
        var operationName = $"{httpMethod.ToUpperInvariant()}{string.Join(string.Empty, path.Split('/').Select(p => p.ConvertKebabCaseToPascalCase()))}";

        return operationName;
    }
}

This implementation splits the path by /, converts each part from kebab case to Pascal case, then joins them together and prepends the HTTP method.

To use this OperationNameGenerator, set it in the BaseSettings of your generator:

generator.BaseSettings.OperationNameGenerator = new CustomOperationNameGenerator();

Now, if you run your generation with /events/v3/send as the kv.Key and post as the verb, you should get PostEventsV3Send.

from refitter.

christianhelle avatar christianhelle commented on July 21, 2024 1

@damianh Thanks for taking the time to report this. This is clearly a bug. The https://api.hubspot.com/api-catalog-public/v1/apis/events/v3/send OpenAPI spec seems to have a lot of details that I haven't tested with. I'll make sure that the code generated from the HubSpot API will build and work with Refiter

from refitter.

christianhelle avatar christianhelle commented on July 21, 2024

I have implemented the fix so the generated code for the HubSpot Events API now looks something like this:

// <auto-generated>
//     This code was generated by Refitter.
// </auto-generated>

using Refit;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Hubspotevents.Interface
{
    public interface ICustomBehavioralEventsAPI
    {

        /// <summary>
        /// Endpoint to send an instance of a behavioral event
        /// </summary>
        [Post("/events/v3/send")]
        Task PostEventsV3Send([Body] BehavioralEventHttpCompletionRequest body);
    }
}

from refitter.

christianhelle avatar christianhelle commented on July 21, 2024

This issue in resolved in v0.5.28

from refitter.

damianh avatar damianh commented on July 21, 2024

Nice, will take it for a spin.

from refitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.