Skip to content

Commit 31d225d

Browse files
authored
Merge pull request #26 from MobileTeleSystems/dev
Release
2 parents 5eb60af + 02c3274 commit 31d225d

File tree

5 files changed

+401
-129
lines changed

5 files changed

+401
-129
lines changed

.github/workflows/publish.yml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,63 @@ on:
1010
default: true
1111
type: boolean
1212
required: true
13+
description: Set as pre-release
1314
push:
1415
default: false
1516
type: boolean
1617
description: Push to nuget.org
1718

1819
push:
19-
branches: [ "main" ]
20+
branches: ["master"]
2021

2122
jobs:
2223
publish:
23-
2424
runs-on: ubuntu-latest
2525
env:
2626
PackageOutputDir: ".packages"
2727
Prerelease: ${{ github.event.inputs.prerelease || 'false' }}
2828
PushPackage: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event.inputs.push }}
2929

3030
steps:
31-
- uses: actions/checkout@v4
32-
with:
33-
fetch-depth: 0
34-
35-
- name: Setup .NET
36-
uses: actions/setup-dotnet@v4
37-
with:
38-
dotnet-version: 9.0.x
39-
40-
- name: Install GitVersion
41-
uses: gittools/actions/gitversion/[email protected]
42-
with:
43-
versionSpec: '6.0.5'
44-
45-
- name: Determine Version
46-
run: |
47-
${GITVERSION_PATH}/dotnet-gitversion /output buildserver /output json
48-
49-
- name: Pack
50-
run: |
51-
dotnet pack --nologo -o ${PackageOutputDir} \
52-
-p:PackageVersion=${GitVersion_SemVer} \
53-
-p:AssemblyVersion=${GitVersion_AssemblySemFileVer} \
54-
-p:FileVersion=${GitVersion_MajorMinorPatch} \
55-
-p:AssemblyVersion=${GitVersion_AssemblySemVer} \
56-
-p:FileVersion=${GitVersion_MajorMinorPatch} \
57-
-p:Configuration=Release
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v4
37+
with:
38+
dotnet-version: 9.0.x
39+
40+
- name: Install GitVersion
41+
uses: gittools/actions/gitversion/[email protected]
42+
with:
43+
versionSpec: "6.0.5"
44+
45+
- name: Determine Version
46+
run: |
47+
${GITVERSION_PATH}/dotnet-gitversion /output buildserver /output json
5848
59-
- name: Nuget Push
60-
if: env.PushPackage == 'true'
61-
working-directory: ${{ env.PackageOutputDir }}
62-
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}}
49+
- name: Pack
50+
run: |
51+
dotnet pack --nologo -o ${PackageOutputDir} \
52+
-p:PackageVersion=${GitVersion_SemVer} \
53+
-p:AssemblyVersion=${GitVersion_AssemblySemFileVer} \
54+
-p:FileVersion=${GitVersion_MajorMinorPatch} \
55+
-p:AssemblyVersion=${GitVersion_AssemblySemVer} \
56+
-p:FileVersion=${GitVersion_MajorMinorPatch} \
57+
-p:Configuration=Release
6358
64-
- name: Create Release
65-
uses: ncipollo/release-action@v1
66-
with:
67-
name: v${{ env.GitVersion_SemVer }}
68-
tag: v${{ env.GitVersion_SemVer }}
69-
artifacts: ${{ env.PackageOutputDir }}/*.nupkg
70-
generateReleaseNotes: true
71-
commit: ${{ env.GitVersion_Sha}}
72-
prerelease: ${{ env.Prerelease }}
59+
- name: Nuget Push
60+
if: env.PushPackage == 'true'
61+
working-directory: ${{ env.PackageOutputDir }}
62+
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}}
7363

64+
- name: Create Release
65+
uses: ncipollo/release-action@v1
66+
with:
67+
name: v${{ env.GitVersion_SemVer }}
68+
tag: v${{ env.GitVersion_SemVer }}
69+
artifacts: ${{ env.PackageOutputDir }}/*.nupkg
70+
generateReleaseNotes: true
71+
commit: ${{ env.GitVersion_Sha}}
72+
prerelease: ${{ env.Prerelease }}

schemas/nswag.json

Lines changed: 90 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,120 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"type": "object",
4-
"properties": {
5-
"runtime": {
6-
"type": "string",
7-
"enum": [
8-
"Default",
9-
"WinX64",
10-
"WinX86",
11-
"NetCore10",
12-
"NetCore11",
13-
"NetCore20",
14-
"NetCore21",
15-
"NetCore22",
16-
"NetCore30",
17-
"Debug"
18-
]
19-
},
20-
"defaultVariables": {
21-
"type": [
22-
"string",
23-
"null"
24-
]
4+
"allOf": [
5+
{
6+
"$ref": "#/definitions/nswagDocument"
257
},
26-
"documentGenerator": {
8+
{
9+
"properties": {
10+
"codeGenerators": {
11+
"$ref": "#/definitions/codeGenerators"
12+
}
13+
}
14+
}
15+
],
16+
"definitions": {
17+
"nswagDocument": {
2718
"type": "object",
2819
"properties": {
29-
"fromDocument": {
20+
"runtime": {
21+
"type": "string",
22+
"enum": [
23+
"Default",
24+
"WinX64",
25+
"WinX86",
26+
"NetCore10",
27+
"NetCore11",
28+
"NetCore20",
29+
"NetCore21",
30+
"NetCore22",
31+
"NetCore30",
32+
"Debug"
33+
]
34+
},
35+
"defaultVariables": {
36+
"type": [
37+
"string",
38+
"null"
39+
]
40+
},
41+
"documentGenerator": {
3042
"type": "object",
3143
"properties": {
32-
"json": {
33-
"type": "string",
34-
"description": "Path to file or JSON text."
44+
"fromDocument": {
45+
"type": "object",
46+
"properties": {
47+
"json": {
48+
"type": "string",
49+
"description": "Path to file or JSON text."
50+
},
51+
"url": {
52+
"type": "string",
53+
"description": "Document URL. Dont used if 'json' property is set."
54+
},
55+
"output": {
56+
"type": "null"
57+
}
58+
},
59+
"anyOf": [
60+
{
61+
"required": [
62+
"json"
63+
]
64+
},
65+
{
66+
"required": [
67+
"url"
68+
]
69+
}
70+
]
3571
},
36-
"url": {
37-
"type": "string",
38-
"description": "Document URL. Dont used if 'json' property is set."
72+
"jsonSchemaToOpenApi": {
73+
"properties": {
74+
"name": {
75+
"type": "string",
76+
"description": "Name of schema`"
77+
},
78+
"schema": {
79+
"type": "string",
80+
"description": "Path to file or text of schema."
81+
}
82+
},
83+
"required": [
84+
"name",
85+
"schema"
86+
]
3987
},
40-
"output": {
41-
"type": "null"
88+
"preprocessors": {
89+
"additionalProperties": {
90+
"type": "object"
91+
},
92+
"description": "List of using preprocessors."
4293
}
4394
},
4495
"anyOf": [
4596
{
4697
"required": [
47-
"json"
98+
"fromDocument"
4899
]
49100
},
50101
{
51102
"required": [
52-
"url"
103+
"jsonSchemaToOpenApi"
53104
]
54-
}
55-
]
56-
},
57-
"jsonSchemaToOpenApi": {
58-
"properties": {
59-
"name": {
60-
"type": "string",
61-
"description": "Name of schema`"
62105
},
63-
"schema": {
64-
"type": "string",
65-
"description": "Path to file or text of schema."
106+
{
107+
"required": [
108+
"preprocessors"
109+
]
66110
}
67-
},
68-
"required": [
69-
"name",
70-
"schema"
71111
]
72-
},
73-
"preprocessors": {
74-
"additionalProperties": {
75-
"type": "object"
76-
},
77-
"description": "List of using preprocessors."
78112
}
79113
},
80-
"anyOf": [
81-
{
82-
"required": [
83-
"fromDocument"
84-
]
85-
},
86-
{
87-
"required": [
88-
"jsonSchemaToOpenApi"
89-
]
90-
},
91-
{
92-
"required": [
93-
"preprocessors"
94-
]
95-
}
114+
"required": [
115+
"codeGenerators"
96116
]
97117
},
98-
"codeGenerators": {
99-
"$ref": "#/definitions/codeGenerators"
100-
}
101-
},
102-
"required": [
103-
"codeGenerators"
104-
],
105-
"definitions": {
106118
"codeGenerators": {
107119
"description": "Generator used for code generation.",
108120
"type": "object",

src/ApiCodeGenerator.AsyncApi/DOM/AsyncApiDocument.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json;
22
using Newtonsoft.Json.Linq;
33
using NJsonSchema;
4+
using NJsonSchema.CodeGeneration;
45
using NJsonSchema.Generation;
56
using NJsonSchema.Yaml;
67
using YamlDotNet.Serialization;
@@ -59,11 +60,13 @@ public static Task<AsyncApiDocument> FromJsonAsync(string data)
5960
/// <param name="data">JSON text.</param>
6061
/// <param name="documentPath"> Path to document. </param>
6162
/// <returns>AsyncApi document object model.</returns>
62-
public static Task<AsyncApiDocument> FromJsonAsync(string data, string? documentPath)
63+
public static async Task<AsyncApiDocument> FromJsonAsync(string data, string? documentPath)
6364
{
6465
var document = JsonConvert.DeserializeObject<AsyncApiDocument>(data, JSONSERIALIZERSETTINGS)!;
6566
document.DocumentPath = documentPath;
66-
return UpdateSchemaReferencesAsync(document);
67+
await UpdateSchemaReferencesAsync(document);
68+
BuildAsyncApiDescriminatorMapping(document);
69+
return document;
6770
}
6871

6972
/// <summary>
@@ -80,7 +83,7 @@ public static Task<AsyncApiDocument> FromYamlAsync(string data)
8083
/// <param name="data">YAML text.</param>
8184
/// <param name="documentPath"> Path to document. </param>
8285
/// <returns>AsyncApi document object model.</returns>
83-
public static Task<AsyncApiDocument> FromYamlAsync(string data, string? documentPath)
86+
public static async Task<AsyncApiDocument> FromYamlAsync(string data, string? documentPath)
8487
{
8588
var deserializer = new DeserializerBuilder().Build();
8689
using var reader = new StringReader(data);
@@ -90,15 +93,40 @@ public static Task<AsyncApiDocument> FromYamlAsync(string data, string? document
9093
var serializer = JsonSerializer.Create(JSONSERIALIZERSETTINGS);
9194
var doc = jObject.ToObject<AsyncApiDocument>(serializer)!;
9295
doc.DocumentPath = documentPath;
93-
return UpdateSchemaReferencesAsync(doc);
96+
await UpdateSchemaReferencesAsync(doc);
97+
BuildAsyncApiDescriminatorMapping(doc);
98+
return doc;
9499
}
95100

96-
private static async Task<AsyncApiDocument> UpdateSchemaReferencesAsync(AsyncApiDocument document)
101+
private static Task UpdateSchemaReferencesAsync(AsyncApiDocument document)
97102
{
98-
await JsonSchemaReferenceUtilities.UpdateSchemaReferencesAsync(
103+
return JsonSchemaReferenceUtilities.UpdateSchemaReferencesAsync(
99104
document,
100105
new JsonAndYamlReferenceResolver(new AsyncApiSchemaResolver(document, new SystemTextJsonSchemaGeneratorSettings())));
101-
return document;
106+
}
107+
108+
private static void BuildAsyncApiDescriminatorMapping(AsyncApiDocument document)
109+
{
110+
foreach (var schema in document.Components?.Schemas.Values ?? [])
111+
{
112+
var discriminatorPropName = schema.DiscriminatorObject?.PropertyName;
113+
if (discriminatorPropName != null)
114+
{
115+
var derivedSchemas = schema.GetDerivedSchemas(document);
116+
foreach (var item in derivedSchemas)
117+
{
118+
var derivedSchema = item.Key;
119+
if ((derivedSchema.Properties.TryGetValue(discriminatorPropName, out var discriminatorProp)
120+
|| derivedSchema.AllOf?.FirstOrDefault(i => i != schema && i.Properties.ContainsKey(discriminatorPropName))?.Properties.TryGetValue(discriminatorPropName, out discriminatorProp) == true)
121+
&& discriminatorProp.ExtensionData?.TryGetValue("const", out var constValue) == true)
122+
{
123+
var constValueStr = constValue!.ToString();
124+
discriminatorProp.ParentSchema!.Properties.Remove(discriminatorPropName);
125+
schema.DiscriminatorObject!.Mapping.Add(constValueStr, derivedSchema);
126+
}
127+
}
128+
}
129+
}
102130
}
103131
}
104132
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

0 commit comments

Comments
 (0)