Skip to content

Commit

Permalink
Fix swagger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Jun 17, 2023
1 parent 119b0e3 commit 35d1e03
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 215 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SwaggerApiParser.SwaggerApiView;

namespace SwaggerApiParser.Specs
{
public class Header : Items
{
public string description { get; set; }

public new CodeFileToken[] TokenSerialize(SerializeContext context)
{
List<CodeFileToken> ret = new List<CodeFileToken>();
ret.AddRange(TokenSerializer.KeyValueTokens("type", type, true, context.IteratorPath.CurrentNextPath("type")));

if (description != null)
ret.AddRange(TokenSerializer.KeyValueTokens("description", description, true, context.IteratorPath.CurrentNextPath("description")));

return ret.ToArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using SwaggerApiParser.SwaggerApiView;

namespace SwaggerApiParser.Specs
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ private CodeFileToken[] TokenSerializeInternal(SerializeContext context, Schema
}

// Now recurse into nested model definitions so all properties are grouped with their models.
while (this.propertyQueue.TryDequeue(out var property))
{
var (item, childContext) = property;
ret.AddRange(item.TokenSerializeInternal(childContext, item, flattenedTableItems, serializeRef));
}
//while (this.propertyQueue.TryDequeue(out var property))
//{
// var (item, childContext) = property;
// ret.AddRange(item.TokenSerializeInternal(childContext, item, flattenedTableItems, serializeRef));
//}

return ret.ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ public Schema GetResolvedSchema(Schema root, string currentSwaggerFilePath, Link
var schema = this.GetSchemaFromCache(root.@ref, currentSwaggerFilePath);
var ret = this.GetResolvedSchema(schema, Utils.GetReferencedSwaggerFile(root.@ref, currentSwaggerFilePath), refChain);
// write back resolved cache
this.ResolvedCache.TryAdd(GetResolvedCacheRefKey(root.@ref, currentSwaggerFilePath), schema);
if (root.@ref != null)
{
this.ResolvedCache.TryAdd(GetResolvedCacheRefKey(root.@ref, currentSwaggerFilePath), schema);
}

refChain.RemoveLast();

if (ret == null)
Expand All @@ -222,7 +226,8 @@ public Schema GetResolvedSchema(Schema root, string currentSwaggerFilePath, Link
{
foreach (var allOfItem in root.allOf)
{
var resolvedChild = this.GetResolvedSchema(allOfItem, currentSwaggerFilePath, refChain);
var @ref = root.@ref ?? root.originalRef;
var resolvedChild = this.GetResolvedSchema(allOfItem, Utils.GetReferencedSwaggerFile(@ref, currentSwaggerFilePath), refChain);
if (resolvedChild == null)
{
continue;
Expand All @@ -247,15 +252,13 @@ public Schema GetResolvedSchema(Schema root, string currentSwaggerFilePath, Link

if (root.additionalProperties.ValueKind == JsonValueKind.Object)
{
var additionalProperties = JsonSerializer.Deserialize<Dictionary<string, string>>(root.additionalProperties);
var additionalProperties = JsonSerializer.Deserialize<Dictionary<string, object>>(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);
}
}

Expand All @@ -268,9 +271,10 @@ public Schema GetResolvedSchema(Schema root, string currentSwaggerFilePath, Link
continue;
}

if (!refChain.Contains(rootProperty.Value.@ref) && !refChain.Contains(rootProperty.Value.@ref) && !refChain.Contains(rootProperty.Value.items?.@ref))
if (!refChain.Contains(rootProperty.Value.@ref) && !refChain.Contains(rootProperty.Value.items?.@ref))
{
var property = this.GetResolvedSchema(rootProperty.Value, currentSwaggerFilePath, refChain);
var @ref = root.@ref ?? root.originalRef;
var property = this.GetResolvedSchema(rootProperty.Value, Utils.GetReferencedSwaggerFile(@ref, currentSwaggerFilePath), refChain);
root.properties[rootProperty.Key] = property;
Utils.AddSchemaToRootDefinition(property, definitions);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using SwaggerApiParser.Converters;

namespace SwaggerApiParser.Specs
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public static async Task<SwaggerApiViewSpec> GenerateSwaggerApiView(Swagger swag
}
while (param != null && param.IsRefObject());
}

referenceSwaggerFilePath = Utils.GetReferencedSwaggerFile(parameter.@ref, referenceSwaggerFilePath);
}

var swaggerApiViewOperationParameter = new SwaggerApiViewParameter
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<ItemGroup>
<PackageReference Include="Markdig.Signed" Version="0.30.2" />
<PackageReference Include="NuGet.CommandLine" Version="6.2.2">
<PackageReference Include="NuGet.CommandLine" Version="6.2.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public CodeFileToken[] TokenSerialize(SerializeContext context)
ret.Add(TokenSerializer.NewLine());
foreach (var header in headers)
{
ret.AddRange(TokenSerializer.KeyValueTokens(header.Key, ""));
ret.Add(new CodeFileToken(header.Key, CodeFileTokenKind.FoldableSectionHeading));
ret.Add(TokenSerializer.Colon());
ret.Add(TokenSerializer.NewLine());
ret.Add(TokenSerializer.FoldableContentStart());
ret.AddRange(header.Value.TokenSerialize(context));
ret.Add(TokenSerializer.FoldableContentEnd());
}
ret.Add(TokenSerializer.NewLine());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ public static void SerializePatternedObjects(IDictionary<string, JsonElement> pa

public static void AddSchemaToRootDefinition(Schema schema, Dictionary<string, Definition> definitions)
{
if (schema == null)
{
return;
}

if (!String.IsNullOrEmpty(schema.originalRef))
{
var schemaKey = Utils.GetDefinitionType(schema.originalRef);
Expand Down

Large diffs are not rendered by default.

0 comments on commit 35d1e03

Please sign in to comment.