Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latest NJS and Namotion.Reflection (v13) #2178

Merged
merged 22 commits into from
May 24, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor NJS types
RicoSuter committed May 20, 2019
commit e6e66183cfe389b20809ef53e05cfd8b51bd040e
Original file line number Diff line number Diff line change
@@ -255,21 +255,21 @@ public async Task When_the_generation_of_dto_classes_are_disabled_then_file_is_g

private async Task<SwaggerDocument> GetSwaggerDocument()
{
JsonSchema4 complexTypeSchema = new JsonSchema4();
JsonSchema complexTypeSchema = new JsonSchema();
complexTypeSchema.Title = "ComplexType";
complexTypeSchema.Properties["Prop1"] = new JsonProperty { Type = JsonObjectType.String, IsRequired = true };
complexTypeSchema.Properties["Prop2"] = new JsonProperty { Type = JsonObjectType.Integer, IsRequired = true };
complexTypeSchema.Properties["Prop3"] = new JsonProperty { Type = JsonObjectType.Boolean, IsRequired = true };
complexTypeSchema.Properties["Prop4"] = new JsonProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true };
complexTypeSchema.Properties["Prop1"] = new JsonSchemaProperty { Type = JsonObjectType.String, IsRequired = true };
complexTypeSchema.Properties["Prop2"] = new JsonSchemaProperty { Type = JsonObjectType.Integer, IsRequired = true };
complexTypeSchema.Properties["Prop3"] = new JsonSchemaProperty { Type = JsonObjectType.Boolean, IsRequired = true };
complexTypeSchema.Properties["Prop4"] = new JsonSchemaProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true };

JsonSchema4 complexTypeReponseSchema = new JsonSchema4();
JsonSchema complexTypeReponseSchema = new JsonSchema();
complexTypeReponseSchema.Title = "ComplexTypeResponse";
complexTypeReponseSchema.Properties["Prop1"] = new JsonProperty { Type = JsonObjectType.String, IsRequired = true };
complexTypeReponseSchema.Properties["Prop2"] = new JsonProperty { Type = JsonObjectType.Integer, IsRequired = true };
complexTypeReponseSchema.Properties["Prop3"] = new JsonProperty { Type = JsonObjectType.Boolean, IsRequired = true };
complexTypeReponseSchema.Properties["Prop4"] = new JsonProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true };
complexTypeReponseSchema.Properties["Prop1"] = new JsonSchemaProperty { Type = JsonObjectType.String, IsRequired = true };
complexTypeReponseSchema.Properties["Prop2"] = new JsonSchemaProperty { Type = JsonObjectType.Integer, IsRequired = true };
complexTypeReponseSchema.Properties["Prop3"] = new JsonSchemaProperty { Type = JsonObjectType.Boolean, IsRequired = true };
complexTypeReponseSchema.Properties["Prop4"] = new JsonSchemaProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true };

var typeString = await JsonSchema4.FromTypeAsync(typeof(string));
var typeString = await JsonSchema.FromTypeAsync(typeof(string));

var document = new SwaggerDocument();
document.Paths["Foo"] = new SwaggerPathItem
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ namespace NSwag.CodeGeneration.CSharp.Models
public class CSharpClientTemplateModel : CSharpTemplateModelBase
{
private readonly SwaggerDocument _document;
private readonly JsonSchema4 _exceptionSchema;
private readonly JsonSchema _exceptionSchema;
private readonly SwaggerToCSharpClientGeneratorSettings _settings;

/// <summary>Initializes a new instance of the <see cref="CSharpClientTemplateModel" /> class.</summary>
@@ -31,7 +31,7 @@ public CSharpClientTemplateModel(
string controllerName,
string controllerClassName,
IEnumerable<CSharpOperationModel> operations,
JsonSchema4 exceptionSchema,
JsonSchema exceptionSchema,
SwaggerDocument document,
SwaggerToCSharpClientGeneratorSettings settings)
: base(controllerName, settings)
Original file line number Diff line number Diff line change
@@ -243,7 +243,7 @@ protected override string ResolveParameterType(SwaggerParameter parameter)
/// <param name="resolver">The resolver.</param>
/// <param name="settings">The settings.</param>
/// <returns></returns>
protected override CSharpResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings)
protected override CSharpResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings)
{
return new CSharpResponseModel(this, operation, statusCode, response, response == GetSuccessResponse().Value, exceptionSchema, generator, resolver, settings.CodeGeneratorSettings);
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public class CSharpResponseModel : ResponseModelBase
/// <param name="resolver">The resolver.</param>
/// <param name="settings">The settings.</param>
public CSharpResponseModel(IOperationModel operationModel, SwaggerOperation operation, string statusCode, SwaggerResponse response,
bool isPrimarySuccessResponse, JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, CodeGeneratorSettingsBase settings)
bool isPrimarySuccessResponse, JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, CodeGeneratorSettingsBase settings)
: base(operationModel, operation, statusCode, response, isPrimarySuccessResponse, exceptionSchema, resolver, settings, generator)
{
}
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ protected SwaggerToCSharpGeneratorBase(SwaggerDocument document, SwaggerToCSharp
/// <param name="isNullable">Specifies whether the type is nullable..</param>
/// <param name="typeNameHint">The type name hint.</param>
/// <returns>The type name.</returns>
public override string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint)
public override string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint)
{
if (schema == null)
return "void";
Original file line number Diff line number Diff line change
@@ -23,23 +23,7 @@ protected SwaggerToCSharpGeneratorSettings()
CSharpGeneratorSettings = new CSharpGeneratorSettings
{
Namespace = "MyNamespace",
SchemaType = SchemaType.Swagger2,

// TODO: Remove these defaults when NJS is updated with them
ClassStyle = CSharpClassStyle.Poco,

DateType = "System.DateTimeOffset",
DateTimeType = "System.DateTimeOffset",
TimeType = "System.TimeSpan",
TimeSpanType = "System.TimeSpan",

ArrayType = "System.Collections.Generic.ICollection",
ArrayInstanceType = "System.Collections.ObjectModel.Collection",
ArrayBaseType = "System.Collections.ObjectModel.Collection",

DictionaryType = "System.Collections.Generic.IDictionary",
DictionaryInstanceType = "System.Collections.Generic.Dictionary",
DictionaryBaseType = "System.Collections.Generic.Dictionary"
SchemaType = SchemaType.Swagger2
};

CSharpGeneratorSettings.TemplateFactory = new DefaultTemplateFactory(CSharpGeneratorSettings, new[]
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ public async Task When_using_json_schema_with_references_in_service_then_referen
}";

//// Act
var schema = await JsonSchema4.FromJsonAsync(jsonSchema);
var schema = await JsonSchema.FromJsonAsync(jsonSchema);
var document = new SwaggerDocument();
document.Definitions["Foo"] = schema;

@@ -125,7 +125,7 @@ private static async Task<SwaggerDocument> CreateDocumentAsync()
{
"200", new SwaggerResponse
{
Schema = new JsonSchema4
Schema = new JsonSchema
{
Reference = await generator.GenerateAsync(typeof(Person), new SwaggerSchemaResolver(document, settings))
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema;
using NJsonSchema.Generation;
using NSwag.SwaggerGeneration.WebApi;
using Xunit;

Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ protected override string ResolveParameterType(SwaggerParameter parameter)
/// <param name="settings">The settings.</param>
/// <returns></returns>
protected override TypeScriptResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response,
JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings)
JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings)
{
return new TypeScriptResponseModel(this, operation, statusCode, response, response == GetSuccessResponse().Value,
exceptionSchema, generator, resolver, (SwaggerToTypeScriptClientGeneratorSettings)settings);
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public class TypeScriptResponseModel : ResponseModelBase
/// <param name="resolver">The resolver.</param>
/// <param name="settings">The settings.</param>
public TypeScriptResponseModel(IOperationModel operationModel, SwaggerOperation operation, string statusCode, SwaggerResponse response, bool isPrimarySuccessResponse,
JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, SwaggerToTypeScriptClientGeneratorSettings settings)
JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, SwaggerToTypeScriptClientGeneratorSettings settings)
: base(operationModel, operation, statusCode, response, isPrimarySuccessResponse, exceptionSchema, resolver, settings.TypeScriptGeneratorSettings, generator)
{
_settings = settings;
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ public SwaggerToTypeScriptClientGenerator(SwaggerDocument document, SwaggerToTyp
/// <param name="isNullable">Specifies whether the type is nullable..</param>
/// <param name="typeNameHint">The type name hint.</param>
/// <returns>The type name.</returns>
public override string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint)
public override string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint)
{
if (schema == null)
return "void";
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public class TypeScriptTypeNameGenerator : DefaultTypeNameGenerator
/// <param name="schema">The schema.</param>
/// <param name="typeNameHint">The type name hint.</param>
/// <returns>The type name.</returns>
protected override string Generate(JsonSchema4 schema, string typeNameHint)
protected override string Generate(JsonSchema schema, string typeNameHint)
{
if (typeNameHint == "Error")
typeNameHint = "ErrorDto";
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/ClientGeneratorBase.cs
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public virtual string GetBinaryResponseTypeName()
/// <param name="isNullable">Specifies whether the type is nullable..</param>
/// <param name="typeNameHint">The type name hint.</param>
/// <returns>The type name.</returns>
public abstract string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint);
public abstract string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint);

/// <summary>Generates the the whole file containing all needed types.</summary>
/// <returns>The code</returns>
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/IClientGenerator.cs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public interface IClientGenerator
/// <param name="isNullable">Specifies whether the type is nullable..</param>
/// <param name="typeNameHint">The type name hint.</param>
/// <returns>The type name.</returns>
string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint);
string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint);

/// <summary>Gets the file/binary response type name.</summary>
/// <returns>The type name.</returns>
6 changes: 3 additions & 3 deletions src/NSwag.CodeGeneration/JsonSchemaExtensions.cs
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@ public static class JsonSchema4Extensions
/// <summary>Checks whether the schema uses an object schema somewhere (i.e. does it require a DTO class).</summary>
/// <param name="schema">The schema.</param>
/// <returns>true or false</returns>
public static bool UsesComplexObjectSchema(this JsonSchema4 schema)
public static bool UsesComplexObjectSchema(this JsonSchema schema)
{
return UsesComplexObjectSchema(schema, new List<JsonSchema4>());
return UsesComplexObjectSchema(schema, new List<JsonSchema>());
}

private static bool UsesComplexObjectSchema(this JsonSchema4 schema, List<JsonSchema4> checkedSchemas)
private static bool UsesComplexObjectSchema(this JsonSchema schema, List<JsonSchema> checkedSchemas)
{
schema = schema.ActualTypeSchema;

6 changes: 3 additions & 3 deletions src/NSwag.CodeGeneration/Models/OperationModelBase.cs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public abstract class OperationModelBase<TParameterModel, TResponseModel> : IOpe
/// <param name="resolver">The resolver.</param>
/// <param name="generator">The generator.</param>
/// <param name="settings">The settings.</param>
protected OperationModelBase(JsonSchema4 exceptionSchema, SwaggerOperation operation, TypeResolverBase resolver, IClientGenerator generator, ClientGeneratorBaseSettings settings)
protected OperationModelBase(JsonSchema exceptionSchema, SwaggerOperation operation, TypeResolverBase resolver, IClientGenerator generator, ClientGeneratorBaseSettings settings)
{
_operation = operation;
_resolver = resolver;
@@ -58,7 +58,7 @@ protected OperationModelBase(JsonSchema4 exceptionSchema, SwaggerOperation opera
/// <param name="resolver">The resolver.</param>
/// <param name="settings">The settings.</param>
/// <returns>The response model.</returns>
protected abstract TResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema4 exceptionSchema, IClientGenerator generator,
protected abstract TResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema exceptionSchema, IClientGenerator generator,
TypeResolverBase resolver, ClientGeneratorBaseSettings settings);

/// <summary>Gets the operation ID.</summary>
@@ -307,7 +307,7 @@ protected virtual string ResolveParameterType(SwaggerParameter parameter)

if (parameter.CollectionFormat == SwaggerParameterCollectionFormat.Multi && !schema.Type.HasFlag(JsonObjectType.Array))
{
schema = new JsonSchema4 { Type = JsonObjectType.Array, Item = schema };
schema = new JsonSchema { Type = JsonObjectType.Array, Item = schema };
}

var typeNameHint = !schema.HasTypeNameTitle ? ConversionUtilities.ConvertToUpperCamelCase(parameter.Name, true) : null;
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/Models/ParameterModelBase.cs
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ public IEnumerable<PropertyModel> CollectionPropertyNames
public string Description => ConversionUtilities.TrimWhiteSpaces(_parameter.Description);

/// <summary>Gets the schema.</summary>
public JsonSchema4 Schema => _parameter.ActualSchema;
public JsonSchema Schema => _parameter.ActualSchema;

/// <summary>Gets a value indicating whether the parameter is required.</summary>
public bool IsRequired => _parameter.IsRequired;
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration/Models/PropertyModel.cs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ public class PropertyModel
/// <summary>
/// The <see cref="JsonProperty"/> represented by this <see cref="PropertyModel"/>
/// </summary>
public JsonProperty JsonProperty { get; }
public JsonSchemaProperty JsonProperty { get; }

/// <summary>
/// The generated property name suitable for use in the target language
@@ -28,7 +28,7 @@ public class PropertyModel
public bool IsCollection => JsonProperty.Type == JsonObjectType.Array;

/// <inheritdoc />
public PropertyModel(string key, JsonProperty jsonProperty, string name)
public PropertyModel(string key, JsonSchemaProperty jsonProperty, string name)
{
Key = key;
JsonProperty = jsonProperty;
8 changes: 4 additions & 4 deletions src/NSwag.CodeGeneration/Models/ResponseModelBase.cs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public abstract class ResponseModelBase
private readonly IOperationModel _operationModel;
private readonly SwaggerResponse _response;
private readonly SwaggerOperation _operation;
private readonly JsonSchema4 _exceptionSchema;
private readonly JsonSchema _exceptionSchema;
private readonly IClientGenerator _generator;
private readonly CodeGeneratorSettingsBase _settings;
private readonly TypeResolverBase _resolver;
@@ -37,7 +37,7 @@ public abstract class ResponseModelBase
protected ResponseModelBase(IOperationModel operationModel,
SwaggerOperation operation,
string statusCode, SwaggerResponse response, bool isPrimarySuccessResponse,
JsonSchema4 exceptionSchema, TypeResolverBase resolver, CodeGeneratorSettingsBase settings, IClientGenerator generator)
JsonSchema exceptionSchema, TypeResolverBase resolver, CodeGeneratorSettingsBase settings, IClientGenerator generator)
{
_response = response;
_operation = operation;
@@ -56,7 +56,7 @@ protected ResponseModelBase(IOperationModel operationModel,
public string StatusCode { get; }

/// <summary>Gets the actual response schema.</summary>
public JsonSchema4 ActualResponseSchema { get; }
public JsonSchema ActualResponseSchema { get; }

/// <summary>Gets a value indicating whether to check for the chunked HTTP status code (206, true when file response and 200/204).</summary>
public bool CheckChunkedStatusCode => IsFile && (StatusCode == "200" || StatusCode == "204");
@@ -96,7 +96,7 @@ public bool IsDate
"A server side error occurred.";

/// <summary>Gets the response schema.</summary>
public JsonSchema4 ResolvableResponseSchema => _response.Schema != null ? _resolver.GetResolvableSchema(_response.Schema) : null;
public JsonSchema ResolvableResponseSchema => _response.Schema != null ? _resolver.GetResolvableSchema(_response.Schema) : null;

/// <summary>Gets a value indicating whether the response is nullable.</summary>
public bool IsNullable => _response.IsNullable(_settings.SchemaType);
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public override async Task<object> RunAsync(CommandLineProcessor processor, ICon

public async Task<SwaggerDocument> RunAsync()
{
var schema = await JsonSchema4.FromJsonAsync(Schema).ConfigureAwait(false);
var schema = await JsonSchema.FromJsonAsync(Schema).ConfigureAwait(false);
var document = new SwaggerDocument();

var rootSchemaName = string.IsNullOrEmpty(Name) && Regex.IsMatch(schema.Title ?? string.Empty, "^[a-zA-Z0-9_]*$") ? schema.Title : Name;
Loading