Skip to content

Commit

Permalink
made default strings use string literal (#15049)
Browse files Browse the repository at this point in the history
  • Loading branch information
devhl-labs authored Apr 1, 2023
1 parent 0dc8452 commit c838b1d
Show file tree
Hide file tree
Showing 133 changed files with 2,885 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace {{packageName}}.Client
{
"{{{name}}}", new Dictionary<string, object> {
{"description", "{{{description}}}{{^description}}No description provided{{/description}}"},
{"default_value", "{{{defaultValue}}}"},
{"default_value", {{#isString}}{{^isEnum}}@{{/isEnum}}{{/isString}}"{{{defaultValue}}}"},
{{#enumValues}}
{{#-first}}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#model.allVars}}{{>PropertyDataType}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#defaultValue}} = {{^isDateTime}}{{{defaultValue}}}{{/isDateTime}}{{#isDateTime}}default{{/isDateTime}}{{/defaultValue}}{{^defaultValue}}{{#isNullable}} = default{{/isNullable}}{{/defaultValue}} {{/model.allVars}}
{{#model.allVars}}{{>PropertyDataType}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#defaultValue}} = {{^isDateTime}}{{#isString}}{{^isEnum}}@{{/isEnum}}{{/isString}}{{{defaultValue}}}{{/isDateTime}}{{#isDateTime}}default{{/isDateTime}}{{/defaultValue}}{{^defaultValue}}{{#isNullable}} = default{{/isNullable}}{{/defaultValue}} {{/model.allVars}}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
{{#hasOnlyReadOnly}}
[JsonConstructorAttribute]
{{/hasOnlyReadOnly}}
public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}}{{/isEnum}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{#defaultValue}}{{^isDateTime}}{{{defaultValue}}}{{/isDateTime}}{{#isDateTime}}default({{{datatypeWithEnum}}}){{/isDateTime}}{{/defaultValue}}{{^defaultValue}}default({{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^-last}}, {{/-last}}{{/readWriteVars}}){{#parent}} : base({{#parentVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{^-last}}, {{/-last}}{{/parentVars}}){{/parent}}
public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}}{{/isEnum}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{#defaultValue}}{{^isDateTime}}{{#isString}}{{^isEnum}}@{{/isEnum}}{{/isString}}{{{defaultValue}}}{{/isDateTime}}{{#isDateTime}}default({{{datatypeWithEnum}}}){{/isDateTime}}{{/defaultValue}}{{^defaultValue}}default({{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^-last}}, {{/-last}}{{/readWriteVars}}){{#parent}} : base({{#parentVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{^-last}}, {{/-last}}{{/parentVars}}){{/parent}}
{
{{#vars}}
{{^isInherited}}
Expand Down Expand Up @@ -178,7 +178,7 @@
{{^conditionalSerialization}}
{{^vendorExtensions.x-csharp-value-type}}
// use default value if no "{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}" provided
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? {{{defaultValue}}};
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? {{#isString}}@{{/isString}}{{{defaultValue}}};
{{/vendorExtensions.x-csharp-value-type}}
{{#vendorExtensions.x-csharp-value-type}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2259,4 +2259,13 @@ components:
type: object
properties:
value:
type: string
type: string
LiteralStringClass:
type: object
properties:
escapedLiteralString:
type: string
default: C:\\Users\\username
unescapedLiteralString:
type: string
default: C:\Users\username
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ docs/HasOnlyReadOnly.md
docs/HealthCheckResult.md
docs/IsoscelesTriangle.md
docs/List.md
docs/LiteralStringClass.md
docs/Mammal.md
docs/MapTest.md
docs/MixedPropertiesAndAdditionalPropertiesClass.md
Expand Down Expand Up @@ -167,6 +168,7 @@ src/Org.OpenAPITools/Model/HasOnlyReadOnly.cs
src/Org.OpenAPITools/Model/HealthCheckResult.cs
src/Org.OpenAPITools/Model/IsoscelesTriangle.cs
src/Org.OpenAPITools/Model/List.cs
src/Org.OpenAPITools/Model/LiteralStringClass.cs
src/Org.OpenAPITools/Model/Mammal.cs
src/Org.OpenAPITools/Model/MapTest.cs
src/Org.OpenAPITools/Model/MixedPropertiesAndAdditionalPropertiesClass.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Class | Method | HTTP request | Description
- [Model.HealthCheckResult](docs/HealthCheckResult.md)
- [Model.IsoscelesTriangle](docs/IsoscelesTriangle.md)
- [Model.List](docs/List.md)
- [Model.LiteralStringClass](docs/LiteralStringClass.md)
- [Model.Mammal](docs/Mammal.md)
- [Model.MapTest](docs/MapTest.md)
- [Model.MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,15 @@ components:
value:
type: string
type: object
LiteralStringClass:
properties:
escapedLiteralString:
default: C:\\Users\\username
type: string
unescapedLiteralString:
default: C:\Users\username
type: string
type: object
_foo_get_default_response:
example:
string:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Org.OpenAPITools.Model.LiteralStringClass

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**EscapedLiteralString** | **string** | | [optional] [default to "C:\\Users\\username"]
**UnescapedLiteralString** | **string** | | [optional] [default to "C:\Users\username"]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using Xunit;

using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;

namespace Org.OpenAPITools.Test.Model
{
/// <summary>
/// Class for testing LiteralStringClass
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
public class LiteralStringClassTests : IDisposable
{
// TODO uncomment below to declare an instance variable for LiteralStringClass
//private LiteralStringClass instance;

public LiteralStringClassTests()
{
// TODO uncomment below to create an instance of LiteralStringClass
//instance = new LiteralStringClass();
}

public void Dispose()
{
// Cleanup when everything is done.
}

/// <summary>
/// Test an instance of LiteralStringClass
/// </summary>
[Fact]
public void LiteralStringClassInstanceTest()
{
// TODO uncomment below to test "IsType" LiteralStringClass
//Assert.IsType<LiteralStringClass>(instance);
}


/// <summary>
/// Test the property 'EscapedLiteralString'
/// </summary>
[Fact]
public void EscapedLiteralStringTest()
{
// TODO unit test for the property 'EscapedLiteralString'
}
/// <summary>
/// Test the property 'UnescapedLiteralString'
/// </summary>
[Fact]
public void UnescapedLiteralStringTest()
{
// TODO unit test for the property 'UnescapedLiteralString'
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected Animal()
/// </summary>
/// <param name="className">className (required).</param>
/// <param name="color">color (default to &quot;red&quot;).</param>
public Animal(string className = default(string), string color = "red")
public Animal(string className = default(string), string color = @"red")
{
// to ensure "className" is required (not null)
if (className == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected Cat()
/// <param name="declawed">declawed.</param>
/// <param name="className">className (required) (default to &quot;Cat&quot;).</param>
/// <param name="color">color (default to &quot;red&quot;).</param>
public Cat(bool declawed = default(bool), string className = "Cat", string color = "red") : base(className, color)
public Cat(bool declawed = default(bool), string className = @"Cat", string color = @"red") : base(className, color)
{
this._Declawed = declawed;
if (this.Declawed != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected Category()
/// </summary>
/// <param name="id">id.</param>
/// <param name="name">name (required) (default to &quot;default-name&quot;).</param>
public Category(long id = default(long), string name = "default-name")
public Category(long id = default(long), string name = @"default-name")
{
// to ensure "name" is required (not null)
if (name == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected Dog()
/// <param name="breed">breed.</param>
/// <param name="className">className (required) (default to &quot;Dog&quot;).</param>
/// <param name="color">color (default to &quot;red&quot;).</param>
public Dog(string breed = default(string), string className = "Dog", string color = "red") : base(className, color)
public Dog(string breed = default(string), string className = @"Dog", string color = @"red") : base(className, color)
{
this._Breed = breed;
if (this.Breed != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class Foo : IEquatable<Foo>, IValidatableObject
/// Initializes a new instance of the <see cref="Foo" /> class.
/// </summary>
/// <param name="bar">bar (default to &quot;bar&quot;).</param>
public Foo(string bar = "bar")
public Foo(string bar = @"bar")
{
this.AdditionalProperties = new Dictionary<string, object>();
}
Expand Down
Loading

0 comments on commit c838b1d

Please sign in to comment.