Skip to content

Commit 7b51522

Browse files
committed
2 parents dfce0da + 0f32837 commit 7b51522

File tree

14 files changed

+293
-11
lines changed

14 files changed

+293
-11
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class CodegenModel {
3737

3838
public Set<String> imports = new TreeSet<String>();
3939
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, isArrayModel;
40+
public Boolean hasOnlyReadOnly = true; // true if all properties are read-only
4041
public ExternalDocs externalDocs;
4142

4243
public Map<String, Object> vendorExtensions;

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,11 @@ private void addVars(CodegenModel m, List<CodegenProperty> vars, Map<String, Pro
25922592
m.hasEnums = true;
25932593
}
25942594

2595+
// set model's hasOnlyReadOnly to false if the property is read-only
2596+
if (!Boolean.TRUE.equals(cp.isReadOnly)) {
2597+
m.hasOnlyReadOnly = false;
2598+
}
2599+
25952600
if (i+1 != totalCount) {
25962601
cp.hasMore = true;
25972602
// check the next entry to see if it's read only

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
259259
// check to see if model name is same as the property name
260260
// which will result in compilation error
261261
// if found, prepend with _ to workaround the limitation
262-
if (var.name.equals(cm.name)) {
262+
if (var.name.equalsIgnoreCase(cm.name)) {
263263
var.name = "_" + var.name;
264264
}
265265
}
@@ -615,8 +615,6 @@ public String toEnumVarName(String name, String datatype) {
615615

616616
enumName = camelize(enumName) + "Enum";
617617

618-
LOGGER.info("toEnumVarName = " + enumName);
619-
620618
if (enumName.matches("\\d.*")) { // starts with number
621619
return "_" + enumName;
622620
} else {

modules/swagger-codegen/src/main/resources/csharp/modelGeneric.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
{{/isEnum}}
2626
{{/vars}}
2727
{{#hasRequired}}
28+
{{^hasOnlyReadOnly}}
2829
/// <summary>
2930
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
3031
/// </summary>
3132
[JsonConstructorAttribute]
3233
protected {{classname}}() { }
34+
{{/hasOnlyReadOnly}}
3335
{{/hasRequired}}
3436
/// <summary>
3537
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
@@ -39,6 +41,9 @@
3941
/// <param name="{{name}}">{{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}.</param>
4042
{{/isReadOnly}}
4143
{{/vars}}
44+
{{#hasOnlyReadOnly}}
45+
[JsonConstructorAttribute]
46+
{{/hasOnlyReadOnly}}
4247
public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}?{{/isEnum}} {{name}} = null{{^-last}}, {{/-last}}{{/readWriteVars}})
4348
{
4449
{{#vars}}

modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,15 @@ definitions:
985985
readOnly: true
986986
baz:
987987
type: string
988+
hasOnlyReadOnly:
989+
type: object
990+
properties:
991+
bar:
992+
type: string
993+
readOnly: true
994+
foo:
995+
type: string
996+
readOnly: true
988997
ArrayTest:
989998
type: object
990999
properties:

samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 2012
33
VisualStudioVersion = 12.0.0.0
44
MinimumVisualStudioVersion = 10.0.0.1
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{BF42B49D-37A0-49C4-A405-24CD946ADAA7}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{EC130B5E-75A2-4FA3-BEE2-634A4FFF231C}"
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
88
EndProject
@@ -12,10 +12,10 @@ Debug|Any CPU = Debug|Any CPU
1212
Release|Any CPU = Release|Any CPU
1313
EndGlobalSection
1414
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15-
{BF42B49D-37A0-49C4-A405-24CD946ADAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16-
{BF42B49D-37A0-49C4-A405-24CD946ADAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
17-
{BF42B49D-37A0-49C4-A405-24CD946ADAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
18-
{BF42B49D-37A0-49C4-A405-24CD946ADAA7}.Release|Any CPU.Build.0 = Release|Any CPU
15+
{EC130B5E-75A2-4FA3-BEE2-634A4FFF231C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{EC130B5E-75A2-4FA3-BEE2-634A4FFF231C}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{EC130B5E-75A2-4FA3-BEE2-634A4FFF231C}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{EC130B5E-75A2-4FA3-BEE2-634A4FFF231C}.Release|Any CPU.Build.0 = Release|Any CPU
1919
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2020
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
2121
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU

samples/client/petstore/csharp/SwaggerClient/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This C# SDK is automatically generated by the [Swagger Codegen](https://github.c
66

77
- API version: 1.0.0
88
- SDK version: 1.0.0
9-
- Build date: 2016-06-12T16:29:47.553+08:00
9+
- Build date: 2016-06-21T16:06:28.848+08:00
1010
- Build package: class io.swagger.codegen.languages.CSharpClientCodegen
1111

1212
## Frameworks supported
@@ -123,6 +123,7 @@ Class | Method | HTTP request | Description
123123
- [Model.EnumClass](docs/EnumClass.md)
124124
- [Model.EnumTest](docs/EnumTest.md)
125125
- [Model.FormatTest](docs/FormatTest.md)
126+
- [Model.HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
126127
- [Model.MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
127128
- [Model.Model200Response](docs/Model200Response.md)
128129
- [Model.ModelReturn](docs/ModelReturn.md)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# IO.Swagger.Model.HasOnlyReadOnly
2+
## Properties
3+
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**Bar** | **string** | | [optional]
7+
**Foo** | **string** | | [optional]
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+

samples/client/petstore/csharp/SwaggerClient/docs/Model200Response.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**Name** | **int?** | | [optional]
7+
**_Class** | **string** | | [optional]
78

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

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Swagger Petstore
3+
*
4+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
*
6+
* OpenAPI spec version: 1.0.0
7+
* Contact: [email protected]
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
24+
using NUnit.Framework;
25+
26+
using System;
27+
using System.Linq;
28+
using System.IO;
29+
using System.Collections.Generic;
30+
using IO.Swagger.Api;
31+
using IO.Swagger.Model;
32+
using IO.Swagger.Client;
33+
using System.Reflection;
34+
35+
namespace IO.Swagger.Test
36+
{
37+
/// <summary>
38+
/// Class for testing HasOnlyReadOnly
39+
/// </summary>
40+
/// <remarks>
41+
/// This file is automatically generated by Swagger Codegen.
42+
/// Please update the test case below to test the model.
43+
/// </remarks>
44+
[TestFixture]
45+
public class HasOnlyReadOnlyTests
46+
{
47+
// TODO uncomment below to declare an instance variable for HasOnlyReadOnly
48+
//private HasOnlyReadOnly instance;
49+
50+
/// <summary>
51+
/// Setup before each test
52+
/// </summary>
53+
[SetUp]
54+
public void Init()
55+
{
56+
// TODO uncomment below to create an instance of HasOnlyReadOnly
57+
//instance = new HasOnlyReadOnly();
58+
}
59+
60+
/// <summary>
61+
/// Clean up after each test
62+
/// </summary>
63+
[TearDown]
64+
public void Cleanup()
65+
{
66+
67+
}
68+
69+
/// <summary>
70+
/// Test an instance of HasOnlyReadOnly
71+
/// </summary>
72+
[Test]
73+
public void HasOnlyReadOnlyInstanceTest()
74+
{
75+
// TODO uncomment below to test "IsInstanceOfType" HasOnlyReadOnly
76+
//Assert.IsInstanceOfType<HasOnlyReadOnly> (instance, "variable 'instance' is a HasOnlyReadOnly");
77+
}
78+
79+
/// <summary>
80+
/// Test the property 'Bar'
81+
/// </summary>
82+
[Test]
83+
public void BarTest()
84+
{
85+
// TODO unit test for the property 'Bar'
86+
}
87+
/// <summary>
88+
/// Test the property 'Foo'
89+
/// </summary>
90+
[Test]
91+
public void FooTest()
92+
{
93+
// TODO unit test for the property 'Foo'
94+
}
95+
96+
}
97+
98+
}

0 commit comments

Comments
 (0)