Skip to content

Commit

Permalink
Add the extracted generation templates (#98)
Browse files Browse the repository at this point in the history
* Add the extracted generation templates
  • Loading branch information
AndrewBenzSW authored Jul 10, 2024
1 parent 8e62ec7 commit 27a6a6e
Show file tree
Hide file tree
Showing 131 changed files with 16,663 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ To build the project locally on your computer:
By default, the test project targets all supported frameworks, if your environment only supports a subset then you can specify in the CLI. <br><br>
`dotnet test -f net5.0`

### Generating from OpenAPI

The templates for autogeneration were extracted using the command:
```bash
npx @openapitools/openapi-generator-cli author template -g csharp -o generation/templates
```

## Release
Create a [fork](https://docs.github.com/en/get-started/quickstart/contributing-to-projects) for your changes.

Expand Down
68 changes: 68 additions & 0 deletions generation/templates/AbstractOpenAPISchema.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{>partial_header}}

using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace {{packageName}}.{{modelPackage}}
{
/// <summary>
/// Abstract base class for oneOf, anyOf schemas in the OpenAPI specification
/// </summary>
{{>visibility}} abstract partial class AbstractOpenAPISchema
{
/// <summary>
/// Custom JSON serializer
/// </summary>
static public readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
// OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
MissingMemberHandling = MissingMemberHandling.Error,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
OverrideSpecifiedNames = false
}
}
};

/// <summary>
/// Custom JSON serializer for objects with additional properties
/// </summary>
static public readonly JsonSerializerSettings AdditionalPropertiesSerializerSettings = new JsonSerializerSettings
{
// OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
MissingMemberHandling = MissingMemberHandling.Ignore,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
OverrideSpecifiedNames = false
}
}
};

/// <summary>
/// Gets or Sets the actual instance
/// </summary>
public abstract Object ActualInstance { get; set; }

/// <summary>
/// Gets or Sets IsNullable to indicate whether the instance is nullable
/// </summary>
public bool IsNullable { get; protected set; }

/// <summary>
/// Gets or Sets the schema type, which can be either `oneOf` or `anyOf`
/// </summary>
public string SchemaType { get; protected set; }

/// <summary>
/// Converts the instance into JSON string.
/// </summary>
public abstract string ToJson();
}
}
Loading

0 comments on commit 27a6a6e

Please sign in to comment.