Comments (6)
The issue seems related to this bit of code.
refitter/src/Refitter.Core/RefitInterfaceGenerator.cs
Lines 50 to 53 in fdac7fa
from refitter.
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.
@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.
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.
This issue in resolved in v0.5.28
from refitter.
Nice, will take it for a spin.
from refitter.
Related Issues (20)
- Add support for old core frameworks versions from .net6 HOT 5
- More than one generated Client Api will result in an Extension Method Conflict for ConfigureRefitClients HOT 6
- IAsyncEnumerable - JSONL/application/x-ndjson HOT 7
- Hyphens with JsonStringEnumConverter results in `JSON value could not be converted` HOT 7
- Response is always nullable under `generateNullableReferenceTypes` HOT 2
- Source generator does not work in .Net 8 HOT 1
- Support for OpenAPI version 3.1.0 HOT 2
- Non string/boolean CodeGeneratorSettings are not honored HOT 3
- Generate the client from multiple versions HOT 1
- `remove-unused-schema` not working for collection-type responses HOT 1
- Asana API "cannot derive from sealed type" HOT 4
- Code Generator creates unsafe interface method names HOT 1
- Code Generator adds numeric suffix to Interface method name when not needed HOT 3
- Add the facility to exclude namespaces from generated code HOT 5
- Asana API specs strange naming HOT 2
- Refit Fails on Jira OpenAPI specs HOT 5
- Serializer improvements HOT 1
- All Contributors Bot HOT 12
- Polly.Extensions.Http deprecated in favour of Microsoft.Extensions.Http.Resilience HOT 3
- Support generating immutable records HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from refitter.