Skip to content

Commit 734354e

Browse files
committed
Basic PathItemAsset creation
1 parent 8f871f4 commit 734354e

File tree

10 files changed

+83
-77
lines changed

10 files changed

+83
-77
lines changed

Assets/Editor/OpenApiParser.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using HttpMono;
77
using Microsoft.OpenApi.Models;
88
using UnityOpenApi;
9+
using System.Linq;
910

1011
[CreateAssetMenu(menuName = "Unity Open API/Parser")]
1112
public class OpenApiParser : ScriptableObject
@@ -65,7 +66,13 @@ public void GenerateAssets(OpenApiDocument openApiDocument)
6566

6667
foreach(var p in openApiDocument.Paths)
6768
{
68-
69+
string fileName = PathItemAsset.PrepareFileName(p.Key);
70+
PathItemAsset a = AssetsHelper.GetOrCreateScriptableObject<PathItemAsset>(assetsPath, fileName);
71+
a.ApiAsset = apiAsset;
72+
a.Summary = p.Value.Summary;
73+
a.Description = p.Value.Description;
74+
75+
a.Servers = p.Value.Servers.Select(s => new OAServer(s)).ToList();
6976
}
7077

7178
AssetDatabase.SaveAssets();

Assets/PetStore/Swagger Petstore.asset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ MonoBehaviour:
2424
Title: Swagger Petstore
2525
Description: A sample API that uses a petstore as an example to demonstrate features
2626
in the OpenAPI 3.0 specification
27-
Version:
27+
Version: 1.0.0
2828
TermsOfService: http://swagger.io/terms/
2929
Contact:
3030
Name: Swagger API Team
3131
Url: http://swagger.io/
3232
Email: apiteam@swagger.io
33-
Present: 0
33+
Present: 1
3434
License:
3535
Name: Apache 2.0
3636
Url: https://www.apache.org/licenses/LICENSE-2.0.html
37-
Present: 0
37+
Present: 1

Assets/PetStore/USPTO Data Set API.asset

Lines changed: 0 additions & 57 deletions
This file was deleted.

Assets/PetStore/_pets.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: da4dbea4eac91844abcb0f7cba90820a, type: 3}
13+
m_Name: _pets
14+
m_EditorClassIdentifier:
15+
ApiAsset: {fileID: 11400000, guid: d8d8582a2c4342949889e466c17358c0, type: 2}
16+
Summary:
17+
Description:
18+
Operations: []
19+
Servers: []
20+
Parameters: []

Assets/PetStore/USPTO Data Set API.asset.meta renamed to Assets/PetStore/_pets.asset.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/PetStore/_pets_{id}.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: da4dbea4eac91844abcb0f7cba90820a, type: 3}
13+
m_Name: _pets_{id}
14+
m_EditorClassIdentifier:
15+
ApiAsset: {fileID: 11400000, guid: d8d8582a2c4342949889e466c17358c0, type: 2}
16+
Summary:
17+
Description:
18+
Operations: []
19+
Servers: []
20+
Parameters: []

Assets/PetStore/_pets_{id}.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/UnityOpenApi/OpenApiAssets/ApiAsset.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,7 @@ public class ApiAsset : ScriptableObject
2929

3030
public void UpdateWithApiDocument(OpenApiDocument openApiDocument)
3131
{
32-
_servers = openApiDocument.Servers.Select(s => new OAServer
33-
{
34-
Description = s.Description,
35-
Url = s.Url,
36-
Variables = s.Variables.ToDictionary(v => v.Key, v => new OAServerVariable()
37-
{
38-
Name = v.Key,
39-
Description = v.Value.Description,
40-
Default = v.Value.Default,
41-
Enum = new List<string>(v.Value.Enum),
42-
Current = v.Value.Enum.IndexOf(v.Value.Default)
43-
}).Values.ToList()
44-
}).ToList();
45-
32+
_servers = openApiDocument.Servers.Select(s => new OAServer(s)).ToList();
4633

4734
_info = new OAInfo(openApiDocument.Info);
4835
}

Assets/UnityOpenApi/OpenApiAssets/PathItemAsset.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ public class PathItemAsset : ScriptableObject
1616
public List<OAOperation> Operations;
1717
public List<OAServer> Servers;
1818
public List<OAParameter> Parameters;
19+
20+
public static string PrepareFileName(string path)
21+
{
22+
return path.Replace('/', '_');
23+
}
1924
}
2025
}

Assets/UnityOpenApi/OpenApiModel/OAServer.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System;
1+
using Microsoft.OpenApi.Models;
2+
using System;
23
using System.Collections.Generic;
4+
using System.Linq;
35

46
namespace UnityOpenApi
57
{
@@ -9,5 +11,19 @@ public class OAServer
911
public string Description;
1012
public string Url;
1113
public List<OAServerVariable> Variables;
14+
15+
public OAServer(OpenApiServer s)
16+
{
17+
Description = s.Description;
18+
Url = s.Url;
19+
Variables = s.Variables.ToDictionary(v => v.Key, v => new OAServerVariable()
20+
{
21+
Name = v.Key,
22+
Description = v.Value.Description,
23+
Default = v.Value.Default,
24+
Enum = new List<string>(v.Value.Enum),
25+
Current = v.Value.Enum.IndexOf(v.Value.Default)
26+
}).Values.ToList();
27+
}
1228
}
1329
}

0 commit comments

Comments
 (0)