mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
Generation of enum types for parameters and properties.
This commit is contained in:
parent
be44df44a5
commit
8f2523c448
@ -84,8 +84,8 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
apiPackage = packageName + ".Api";
|
||||
modelPackage = packageName + ".Models";
|
||||
apiPackage = packageName + ".Module";
|
||||
modelPackage = packageName + ".Model";
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", sourceFolder(), "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("RequestExtensions.mustache", sourceFolder(), "RequestExtensions.cs"));
|
||||
@ -104,12 +104,12 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder() + File.separator + "Api";
|
||||
return outputFolder + File.separator + sourceFolder() + File.separator + "Module";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder() + File.separator + "Models";
|
||||
return outputFolder + File.separator + sourceFolder() + File.separator + "Model";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,4 +128,22 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
// Converts, for example, PUT to HttpPut for controller attributes
|
||||
operation.httpMethod = operation.httpMethod.substring(0, 1) + operation.httpMethod.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
String enumName = sanitizeName(name);
|
||||
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
enumName = camelize(enumName);
|
||||
|
||||
LOGGER.info("toEnumVarName = " + enumName);
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace {{packageName}}.Api
|
||||
namespace {{packageName}}.Module
|
||||
{
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
|
@ -2,10 +2,13 @@ using Nancy;
|
||||
using Nancy.ModelBinding;
|
||||
using System.Collections.Generic;
|
||||
using Sharpility.Net;
|
||||
using {{packageName}}.Models;
|
||||
using {{packageName}}.Model;
|
||||
|
||||
namespace {{packageName}}.Api
|
||||
namespace {{packageName}}.Module
|
||||
{ {{#operations}}
|
||||
{{#operation}}{{#allParams}}{{#isEnum}}
|
||||
{{>innerEnum}}
|
||||
{{/isEnum}}{{/allParams}}{{/operation}}
|
||||
|
||||
public sealed class {{classname}}Module : NancyModule
|
||||
{
|
||||
|
@ -0,0 +1 @@
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}} { {{#allowableValues}}{{#enumVars}}{{{name}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} };
|
@ -6,11 +6,13 @@ using Sharpility.Extensions;
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
namespace {{packageName}}.Models
|
||||
namespace {{packageName}}.Model
|
||||
{
|
||||
public sealed class {{classname}}: {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>
|
||||
{
|
||||
{{#vars}}
|
||||
{{#vars}}{{#isEnum}}
|
||||
{{>innerEnum}}
|
||||
{{/isEnum}}{{/vars}}{{#vars}}
|
||||
public {{{datatype}}} {{name}} { get; private set; }
|
||||
{{/vars}}
|
||||
|
||||
@ -64,6 +66,9 @@ namespace {{packageName}}.Models
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builder of {{classname}} model
|
||||
/// </summary>
|
||||
public sealed class {{classname}}Builder
|
||||
{
|
||||
{{#vars}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user