Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin committed Sep 27, 2024
1 parent 43f67db commit 9c172b4
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/release_nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Nuget Release

on:
release:
types: [created, edited]

jobs:
run_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.100
- name: Build/Check for compile errors (dotnet build)
working-directory: "MaLoIdentModels"
run: dotnet build --configuration Release
- name: Run Unit Tests (dotnet test) # never ever release with failing tests!
working-directory: "AhbichtClient"
run: dotnet test --configuration Release
push_release:
needs: run_tests
if: startsWith(github.ref, 'refs/tags/v')
runs-on: windows-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.100
- uses: olegtarasov/get-tag@v2.1
id: tagTBC
with:
tagRegex: "v(\\d+\\.\\d+\\.\\d+)"
- name: Build/Check for compile errors (dotnet build)
working-directory: "AhbichtClient"
run: dotnet build --configuration Release
- name: Create Package AhbichtClient (dotnet pack)
working-directory: "MaLoIdentModels/MaLoIdentModels"
run: dotnet pack MaLoIdentModels.csproj --configuration Release -p:PackageVersion="${{ steps.tagTBC.outputs.tag }}"
- name: Setup Nuget.exe
uses: warrenbuckley/Setup-Nuget@v1
- name: Nuget push MaLoIdentModels
working-directory: "MaLoIdentModels/MaLoIdentModels"
# token: https://github.com/Hochfrequenz/MaLoIdentModels/settings/secrets/actions/NUGET_ORG_PUSH_TOKEN
# expires 2025-07-17; token is owned by konstantin as of now.
run: |
nuget setApiKey ${{ secrets.NUGET_ORG_PUSH_TOKEN }}
nuget push .\bin\Release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -NoSymbols
15 changes: 14 additions & 1 deletion MaLoIdentModels/MaLoIdentModelsTests/RoundTripTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using FluentAssertions;
using MaLoIdentModels;
using Xunit;

namespace MaLoIdentModelsTests;

Expand Down Expand Up @@ -52,4 +51,18 @@ public void Test_Positive_Negative()
);
deserialized.Should().BeEquivalentTo(model);
}

[Fact]
public void Test_README_Example()
{
var myNegativeResponse = new ResultNegative()
{
DecisionTree = "E_0594",
ResponseCode = "A10",
Reason = "Ich bin ein Freitext.",
NetworkOperator = 9900987654321,
};
var myJson = System.Text.Json.JsonSerializer.Serialize(myNegativeResponse);
Console.Out.WriteLine(myJson);
}
}
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
![Nuget Package](https://badgen.net/nuget/v/MaLoIdentModels)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

# MaLo Ident .NET Models
This repository contains the nuget package `MaLoIdentModels` which contains C# model classes with `System.Text.Json` attributes for the Marktlokation Identification API by EDI@Energy.

## Installation and Use
Install it from nuget [MaLoIdentModels](https://www.nuget.org/packages/MaLoIdentModels):

```bash
dotnet add package MaLoIdentModels
```
Then use it
```c#
using MaLoIdentModels;
// ...
var myNegativeResponse = new ResultNegative()
{
DecisionTree = "E_0594",
ResponseCode = "A10",
Reason = "Ich bin ein Freitext.",
NetworkOperator = 9900987654321
};
var myJson = System.Text.Json.JsonSerializer.Serialize(myNegativeResponse);
Console.Out.WriteLine(myJson);
```

## Why is the code only partly autogenerated?
The classes are generally based on the [MaLo Ident OpenAPI specification](https://app.swaggerhub.com/apis/edi-energy/MaLoIdent_2024-07-03/v1.0.0).
But although auto-generation of code is theoretically possible, the classes are _not_ autogenerated for multiple reasons:
1. The OpenAPI spec as of 2024-07-03 v1.0.0 contains obvious errors in the `marketLocationProperty`:
- It's missing the `measured` valued which is given as example but not part of the enum members (or the example is wrong).
- there is a typo in a enum member: `nonActice` should be `nonActive`
2. Although the OpenAPI is syntactically valid, it is poorly designed <!-- as you'd expect from edi@energy -->:
- For datetimes, instead of using the obvious and easy choice - the dedicated [`date-time` format](https://swagger.io/docs/specification/v3_0/data-models/data-types/#string-formats), the OpenApi by EDI@Energy uses wild regex patterns (e.g. `creationDateTime`: `20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.[\\d]{1,4})?Z` - are you serious?). My best guess is, that they're too afraid of !=0 UTC offsets.
- For the property `marketPartnerId`, the type `integer` (together with a `\d{13}` pattern) was used, although `string` would be the right choice (for the same reasons as you don't use integer for Postleitzahlen or MaLo-IDs). As a consequence, the autogenerated code uses type `int`, but the 13-digit number is too large for a plain int32.
3. (Technical) We wanted to use System.Text.Json in .NET8 (and not Newtonsoft in .NET6) and did not find a a working code generator.

## See also
We also maintain a [Python version of this data model](https://github.com/Hochfrequenz/malo-ident-python-models).

## Contributing
You are very welcome to contribute to this template repository by opening a pull request against the main branch.

0 comments on commit 9c172b4

Please sign in to comment.