Skip to content

Commit

Permalink
Sort Definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Jun 14, 2023
1 parent b800360 commit 0223a23
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Items : Reference
public string format { get; set; }
public Items items { get; set; }
public string collectionFormat { get; set; }
public dynamic @default { get; set; }
public JsonElement @default { get; set; }
public double? maximum { get; set; }
public bool? exclusiveMaximum { get; set; }
public double? minimum { get; set; }
Expand All @@ -32,7 +32,7 @@ public List<string> GetKeywords()
if (!string.IsNullOrEmpty(this.collectionFormat))
keywords.Add($"collectionFormat : {this.collectionFormat}");

if (this.@default != null)
if (@default.ValueKind == JsonValueKind.String)
keywords.Add($"default : {this.@default.ToString()}");

if (this.maximum != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Schema : Items, ITokenSerializable
public new Schema items { get; set; } // Should this be an array?
public List<Schema> allOf { get; set; }
public Dictionary<string, Schema> properties { get; set; }
public dynamic additionalProperties { get; set; }
public JsonElement additionalProperties { get; set; }
public string discriminator { get; set; }
public bool readOnly { get; set; }
public XML xml { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;

namespace SwaggerApiParser.Specs
{
Expand Down Expand Up @@ -244,6 +245,20 @@ public Schema GetResolvedSchema(Schema root, string currentSwaggerFilePath, Link
Utils.AddSchemaToRootDefinition(items, definitions);
}

if (root.additionalProperties.ValueKind == JsonValueKind.Object)
{
var additionalProperties = JsonSerializer.Deserialize<Dictionary<string, string>>(root.additionalProperties);
if (additionalProperties.ContainsKey("$ref"))
{
var schema = new Schema();
schema.@ref = additionalProperties["$ref"].ToString();
var refKey = GetRefKey(schema.@ref);
schema = GetResolvedSchema(schema, currentSwaggerFilePath, refChain);
root.properties[refKey] = schema;
Utils.AddSchemaToRootDefinition(schema, definitions);
}
}

if (root.properties != null)
{
foreach (var rootProperty in root.properties)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SwaggerApiParser.Specs;

namespace SwaggerApiParser.SwaggerApiView
Expand Down Expand Up @@ -146,7 +147,7 @@ public CodeFileToken[] TokenSerialize(SerializeContext context)
private CodeFileToken[] TokenSerializeTableRows(SerializeContext context)
{
List<CodeFileToken> ret = new List<CodeFileToken>();
foreach (var parameter in this)
foreach (var parameter in this.OrderBy(x => x.name))
{
ret.AddRange(TokenSerializer.TableCell(new[] { new CodeFileToken(parameter.name, CodeFileTokenKind.MemberName) }));
var parameterType = parameter.GetTypeFormat();
Expand Down

0 comments on commit 0223a23

Please sign in to comment.