Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@ public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case

public static final String GENERATE_PROPERTY_CHANGED = "generatePropertyChanged";
public static final String GENERATE_PROPERTY_CHANGED_DESC = "Specifies that models support raising property changed events.";

public static final String NON_PUBLIC_API = "nonPublicApi";
public static final String NON_PUBLIC_API_DESC = "Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
protected Map<Character, String> regexModifiers;
protected final Map<String, String> frameworks;

// By default, generated code is considered public
protected boolean nonPublicApi = Boolean.FALSE;

public CSharpClientCodegen() {
super();
modelTemplateFiles.put("model.mustache", ".cs");
Expand Down Expand Up @@ -130,6 +133,14 @@ public CSharpClientCodegen() {
CodegenConstants.PACKAGE_DESCRIPTION_DESC,
this.generatePropertyChanged);

// NOTE: This will reduce visibility of all public members in templates. Users can use InternalsVisibleTo
// https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx
// to expose to shared code if the generated code is not embedded into another project. Otherwise, users of codegen
// should rely on default public visibility.
addSwitch(CodegenConstants.NON_PUBLIC_API,
CodegenConstants.NON_PUBLIC_API_DESC,
this.nonPublicApi);

regexModifiers = new HashMap<Character, String>();
regexModifiers.put('i', "IgnoreCase");
regexModifiers.put('m', "Multiline");
Expand Down Expand Up @@ -232,6 +243,10 @@ public void processOpts() {
.get(CodegenConstants.OPTIONAL_ASSEMBLY_INFO).toString()));
}

if (additionalProperties.containsKey(CodegenConstants.NON_PUBLIC_API)) {
setNonPublicApi(Boolean.valueOf(additionalProperties.get(CodegenConstants.NON_PUBLIC_API).toString()));
}

final String testPackageName = testPackageName();
String packageFolder = sourceFolder + File.separator + packageName;
String clientPackageDir = packageFolder + File.separator + clientPackage;
Expand Down Expand Up @@ -555,6 +570,14 @@ public void setGeneratePropertyChanged(final Boolean generatePropertyChanged){
this.generatePropertyChanged = generatePropertyChanged;
}

public boolean isNonPublicApi() {
return nonPublicApi;
}

public void setNonPublicApi(final boolean nonPublicApi) {
this.nonPublicApi = nonPublicApi;
}

@Override
public String toModelDocFilename(String name) {
return toModelFilename(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace {{packageName}}.Client
/// <summary>
/// API client is mainly responsible for making the HTTP call to the API backend.
/// </summary>
public partial class ApiClient
{{>visibility}} partial class ApiClient
{
private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace {{packageName}}.Client
/// <summary>
/// API Exception
/// </summary>
public class ApiException : Exception
{{>visibility}} class ApiException : Exception
{
/// <summary>
/// Gets or sets the error code (HTTP status code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace {{packageName}}.Client
/// <summary>
/// API Response
/// </summary>
public class ApiResponse<T>
{{>visibility}} class ApiResponse<T>
{
/// <summary>
/// Gets or sets the status code (HTTP status code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace {{packageName}}.Client
/// <summary>
/// Represents a set of configuration settings
/// </summary>
public class Configuration
{{>visibility}} class Configuration
{
/// <summary>
/// Initializes a new instance of the Configuration class with different settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace {{packageName}}.Client
/// </summary>
/// <param name="methodName">Method name</param>
/// <param name="response">Response</param>
/// <returns>Exceptions</returns>
public delegate Exception ExceptionFactory(string methodName, IRestResponse response);
/// <returns>Exceptions</returns>
{{>visibility}} delegate Exception ExceptionFactory(string methodName, IRestResponse response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace {{packageName}}.Client
/// <summary>
/// Represents configuration aspects required to interact with the API endpoints.
/// </summary>
public interface IApiAccessor
{{>visibility}} interface IApiAccessor
{
/// <summary>
/// Gets or sets the configuration object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace {{packageName}}.{{apiPackage}}
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public interface {{interfacePrefix}}{{classname}} : IApiAccessor
{{>visibility}} interface {{interfacePrefix}}{{classname}} : IApiAccessor
{
#region Synchronous Operations
{{#operation}}
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace {{packageName}}.{{apiPackage}}
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public partial class {{classname}} : {{interfacePrefix}}{{classname}}
{{>visibility}} partial class {{classname}} : {{interfacePrefix}}{{classname}}
{
private {{packageName}}.Client.ExceptionFactory _exceptionFactory = (name, response) => null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[JsonConverter(typeof(StringEnumConverter))]
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
{{>visibility}} enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[JsonConverter(typeof(StringEnumConverter))]
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
{{>visibility}} enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{#generatePropertyChanged}}
[ImplementPropertyChanged]
{{/generatePropertyChanged}}
public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>, IValidatableObject
{{>visibility}} partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>, IValidatableObject
{
{{#vars}}
{{#isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[JsonConverter(typeof(StringEnumConverter))]
public enum {{#datatypeWithEnum}}{{&.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
{{>visibility}} enum {{#datatypeWithEnum}}{{&.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ protected void setExpectations() {
times = 1;
clientCodegen.setGeneratePropertyChanged(true);
times = 1;
clientCodegen.setNonPublicApi(true);
times = 1;
clientCodegen.setInterfacePrefix("X");
times = 1;
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Map<String, String> createOptions() {
.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, "true")
.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "true")
.put(CodegenConstants.GENERATE_PROPERTY_CHANGED, "true")
.put(CodegenConstants.NON_PUBLIC_API, "true")
.put(CodegenConstants.INTERFACE_PREFIX, "X")
.build();
}
Expand Down