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

Refactor projects (v10) #969

Merged
merged 8 commits into from
May 20, 2019
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ CI NuGet Feed: https://www.myget.org/gallery/njsonschema-ci

**Features:**

- [Read existing JSON Schemas](https://github.com/RSuter/NJsonSchema/wiki/JsonSchema4) and [validate JSON data](https://github.com/RSuter/NJsonSchema/wiki/JsonSchemaValidator) (`JsonSchema4.FromJsonAsync()`)
- [Generate JSON Schema from .NET type via reflection](https://github.com/RSuter/NJsonSchema/wiki/JsonSchemaGenerator) (with support for many attributes/annotations) (`JsonSchema4.FromTypeAsync<MyType>()`)
- [Generate JSON Schema from sample JSON data](https://github.com/RSuter/NJsonSchema/wiki/SampleJsonSchemaGenerator) (`JsonSchema4.FromSampleJson()`)
- [Read existing JSON Schemas](https://github.com/RSuter/NJsonSchema/wiki/JsonSchema) and [validate JSON data](https://github.com/RSuter/NJsonSchema/wiki/JsonSchemaValidator) (`JsonSchema.FromJsonAsync()`)
- [Generate JSON Schema from .NET type via reflection](https://github.com/RSuter/NJsonSchema/wiki/JsonSchemaGenerator) (with support for many attributes/annotations) (`JsonSchema.FromTypeAsync<MyType>()`)
- [Generate JSON Schema from sample JSON data](https://github.com/RSuter/NJsonSchema/wiki/SampleJsonSchemaGenerator) (`JsonSchema.FromSampleJson()`)
- Support for schema references ($ref) (relative, URL and file)
- Generate C# and TypeScript code from JSON Schema
- Support for .NET Core (via PCL 259 / .NET Standard 1.0, also see [XML Documentation](https://github.com/NJsonSchema/NJsonSchema/wiki/XML-Documentation))
Expand All @@ -41,17 +41,17 @@ The project is developed and maintained by [Rico Suter](http://rsuter.com) and o

## NJsonSchema usage

The [JsonSchema4](https://github.com/NJsonSchema/NJsonSchema/wiki/JsonSchema4) class can be used as follows:
The [JsonSchema](https://github.com/NJsonSchema/NJsonSchema/wiki/JsonSchema) class can be used as follows:

```csharp
var schema = await JsonSchema4.FromTypeAsync<Person>();
var schema = await JsonSchema.FromTypeAsync<Person>();
var schemaData = schema.ToJson();
var errors = schema.Validate("{...}");

foreach (var error in errors)
Console.WriteLine(error.Path + ": " + error.Kind);

schema = await JsonSchema4.FromJsonAsync(schemaData);
schema = await JsonSchema.FromJsonAsync(schemaData);
```

The `Person` class:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Setup(BenchmarkContext context)
[CounterThroughputAssertion("Iterations", MustBe.GreaterThan, 100)]
public void GenerateSchema()
{
var schema = JsonSchema4.FromTypeAsync<Container>().GetAwaiter().GetResult();
var schema = JsonSchema.FromTypeAsync<Container>().GetAwaiter().GetResult();
_counter.Increment();
}

Expand Down
8 changes: 4 additions & 4 deletions src/NJsonSchema.Benchmark/SerializationPerformance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NJsonSchema.Benchmark
public class SerializationPerformance
{
private readonly string _json;
private readonly JsonSchema4 _schema;
private readonly JsonSchema _schema;

public SerializationPerformance()
{
Expand All @@ -22,7 +22,7 @@ public SerializationPerformance()
_json = reader.ReadToEnd();
}

_schema = JsonSchema4.FromJsonAsync(_json).Result;
_schema = JsonSchema.FromJsonAsync(_json).Result;
}

[Benchmark]
Expand All @@ -32,9 +32,9 @@ public string ToJson()
}

[Benchmark]
public JsonSchema4 FromJson()
public JsonSchema FromJson()
{
return JsonSchema4.FromJsonAsync(_json).Result;
return JsonSchema.FromJsonAsync(_json).Result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class AbstractClass
public async Task When_class_is_abstract_then_is_abstract_CSharp_keyword_is_generated()
{
/// Arrange
var schema = await JsonSchema4.FromTypeAsync<AbstractClass>();
var schema = await JsonSchema.FromTypeAsync<AbstractClass>();

/// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task When_additionalProperties_schema_is_set_for_object_then_specia
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);

//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
Expand Down
10 changes: 5 additions & 5 deletions src/NJsonSchema.CodeGeneration.CSharp.Tests/AllOfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task When_allOf_has_two_schemas_then_referenced_schema_is_inherited
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);

//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task When_allOf_has_one_schema_then_it_is_inherited()
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);

//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task When_all_of_has_multiple_refs_then_the_properties_should_expan
}";

//// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var settings = new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco, Namespace = "ns" };
var generator = new CSharpGenerator(schema, settings);
var output = generator.GenerateFile("Foo");
Expand Down Expand Up @@ -188,7 +188,7 @@ public async Task When_more_properties_are_defined_in_allOf_and_type_none_then_a
}";

//// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
var code = generator.GenerateFile("Foo").Replace("\r\n", "\n");

Expand Down Expand Up @@ -231,7 +231,7 @@ public async Task When_allOf_schema_is_object_type_then_it_is_an_inherited_class
}";

//// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
var code = generator.GenerateFile("Foo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MyRequiredTest
public async Task When_array_property_is_not_nullable_then_it_does_not_have_a_setter()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<MyRequiredTest>();
var schema = await JsonSchema.FromTypeAsync<MyRequiredTest>();
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings
{
ClassStyle = CSharpClassStyle.Poco,
Expand Down
4 changes: 2 additions & 2 deletions src/NJsonSchema.CodeGeneration.CSharp.Tests/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ArrayTest
public async Task When_array_property_is_required_then_array_instance_can_be_changed()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<ArrayTest>();
var schema = await JsonSchema.FromTypeAsync<ArrayTest>();
var data = schema.ToJson();

//// Act
Expand All @@ -45,7 +45,7 @@ public class ClassWithNullableArrayItems
public async Task When_array_item_is_nullable_then_generated_CSharp_is_correct()
{
// Arrange
var schema = await JsonSchema4.FromTypeAsync<ClassWithNullableArrayItems>();
var schema = await JsonSchema.FromTypeAsync<ClassWithNullableArrayItems>();
var json = schema.ToJson();
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task When_property_has_interger_default_it_is_reflected_in_the_poco
}
}}";

var schema = await JsonSchema4.FromJsonAsync(data);
var schema = await JsonSchema.FromJsonAsync(data);
var settings = new CSharpGeneratorSettings
{
ClassStyle = CSharpClassStyle.Poco,
Expand All @@ -39,7 +39,7 @@ public async Task When_property_has_boolean_default_it_is_reflected_in_the_poco(
}
}}";

var schema = await JsonSchema4.FromJsonAsync(data);
var schema = await JsonSchema.FromJsonAsync(data);
var settings = new CSharpGeneratorSettings
{
ClassStyle = CSharpClassStyle.Poco,
Expand All @@ -62,7 +62,7 @@ public async Task When_property_has_boolean_default_and_default_value_generation
}
}}";

var schema = await JsonSchema4.FromJsonAsync(data);
var schema = await JsonSchema.FromJsonAsync(data);
var settings = new CSharpGeneratorSettings
{
ClassStyle = CSharpClassStyle.Poco,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class EnumKeyDictionaryTest
public async Task When_dictionary_key_is_enum_then_csharp_has_enum_key()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<EnumKeyDictionaryTest>();
var schema = await JsonSchema.FromTypeAsync<EnumKeyDictionaryTest>();
var data = schema.ToJson();

//// Act
Expand All @@ -41,7 +41,7 @@ public async Task When_dictionary_key_is_enum_then_csharp_has_enum_key()
public async Task When_dictionary_property_is_required_then_dictionary_instance_can_be_changed()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<EnumKeyDictionaryTest>();
var schema = await JsonSchema.FromTypeAsync<EnumKeyDictionaryTest>();
var data = schema.ToJson();

//// Act
Expand Down
18 changes: 9 additions & 9 deletions src/NJsonSchema.CodeGeneration.CSharp.Tests/EnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task When_enum_has_no_type_then_enum_is_generated()
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema);

//// Act
Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task When_enum_has_no_type_then_enum_is_generated_with_flags()
}
}";

var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { EnforceFlagEnums = true });

//// Act
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task When_enum_name_contains_colon_then_it_is_removed_and_next_word
}
}";

var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema);

//// Act
Expand Down Expand Up @@ -137,7 +137,7 @@ public enum MyStringEnum
public async Task When_enum_list_uses_string_enums_then_ItemConverterType_is_set()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<MyStringEnumListTest>();
var schema = await JsonSchema.FromTypeAsync<MyStringEnumListTest>();
var data = schema.ToJson();
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });

Expand All @@ -152,7 +152,7 @@ public async Task When_enum_list_uses_string_enums_then_ItemConverterType_is_set
public async Task When_enum_is_nullable_then_StringEnumConverter_is_set()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<MyStringEnumListTest>();
var schema = await JsonSchema.FromTypeAsync<MyStringEnumListTest>();
var data = schema.ToJson();
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });

Expand All @@ -175,7 +175,7 @@ public class SomeClass
public async Task When_class_has_enum_array_property_then_enum_name_is_preserved()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync<SomeClass>(new JsonSchemaGeneratorSettings());
var schema = await JsonSchema.FromTypeAsync<SomeClass>(new JsonSchemaGeneratorSettings());
var json = schema.ToJson();

//// Act
Expand Down Expand Up @@ -216,7 +216,7 @@ public async Task When_type_name_hint_has_generics_then_they_are_converted()
}
}";
/// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);

var settings = new CSharpGeneratorSettings();
var generator = new CSharpGenerator(schema, settings);
Expand Down Expand Up @@ -250,7 +250,7 @@ public async Task When_enum_property_is_not_required_in_Swagger2_then_it_is_null
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { SchemaType = SchemaType.Swagger2 });

//// Act
Expand Down Expand Up @@ -298,7 +298,7 @@ public async Task When_array_item_enum_is_not_referenced_then_type_name_hint_is_
}
}";
/// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var schema = await JsonSchema.FromJsonAsync(json);

var settings = new CSharpGeneratorSettings();
var generator = new CSharpGenerator(schema, settings);
Expand Down
Loading