Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added multiple clients from first tag and operation id generator (#2169)
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...eGeneration/OperationNameGenerators/MultipleClientsFromFirstTagAndOperationIdGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
//----------------------------------------------------------------------- | |||
// <copyright file="MultipleClientsFromFirstTagAndOperationIdGenerator.cs" company="NSwag"> | |||
// Copyright (c) Rico Suter. All rights reserved. | |||
// </copyright> | |||
// <license>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</license> | |||
// <author>Rico Suter, mail@rsuter.com</author> | |||
//----------------------------------------------------------------------- | |||
|
|||
using NJsonSchema; | |||
using System.Linq; | |||
|
|||
namespace NSwag.CodeGeneration.OperationNameGenerators | |||
{ | |||
/// <summary>Generates the client name based on the first tag and operation name based on the operation id (operation name = operationId, client name = first tag).</summary> | |||
public class MultipleClientsFromFirstTagAndOperationIdGenerator : IOperationNameGenerator | |||
{ | |||
/// <summary>Gets a value indicating whether the generator supports multiple client classes.</summary> | |||
public bool SupportsMultipleClients { get; } = true; | |||
|
|||
/// <summary>Gets the client name for a given operation (may be empty).</summary> | |||
/// <param name="document">The Swagger document.</param> | |||
/// <param name="path">The HTTP path.</param> | |||
/// <param name="httpMethod">The HTTP method.</param> | |||
/// <param name="operation">The operation.</param> | |||
/// <returns>The client name.</returns> | |||
public virtual string GetClientName(SwaggerDocument document, string path, string httpMethod, SwaggerOperation operation) | |||
{ | |||
return ConversionUtilities.ConvertToUpperCamelCase(operation.Tags.FirstOrDefault(), false); | |||
} | |||
|
|||
/// <summary>Gets the operation name for a given operation.</summary> | |||
/// <param name="document">The Swagger document.</param> | |||
/// <param name="path">The HTTP path.</param> | |||
/// <param name="httpMethod">The HTTP method.</param> | |||
/// <param name="operation">The operation.</param> | |||
/// <returns>The operation name.</returns> | |||
public virtual string GetOperationName(SwaggerDocument document, string path, string httpMethod, SwaggerOperation operation) | |||
{ | |||
var operationName = operation.OperationId; | |||
return operationName; | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters