Skip to content

Commit 66a033c

Browse files
committed
Code cleanup
1 parent 6cd1db6 commit 66a033c

File tree

6 files changed

+70
-398
lines changed

6 files changed

+70
-398
lines changed

src/Microsoft.OpenApi/Helpers/SchemaSerializerHelper.cs

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

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,72 @@ internal void SerializeAsV2WithoutReference(
624624
writer.WriteEndObject();
625625
}
626626

627+
internal void WriteAsItemsProperties(IOpenApiWriter writer)
628+
{
629+
// type
630+
writer.WriteProperty(OpenApiConstants.Type, (string)Type);
631+
632+
// format
633+
if (string.IsNullOrEmpty(Format))
634+
{
635+
Format = AllOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
636+
AnyOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
637+
OneOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format;
638+
}
639+
640+
writer.WriteProperty(OpenApiConstants.Format, Format);
641+
642+
// items
643+
writer.WriteOptionalObject(OpenApiConstants.Items, Items, (w, s) => s.SerializeAsV2(w));
644+
645+
// collectionFormat
646+
// We need information from style in parameter to populate this.
647+
// The best effort we can make is to pull this information from the first parameter
648+
// that leverages this schema. However, that in itself may not be as simple
649+
// as the schema directly under parameter might be referencing one in the Components,
650+
// so we will need to do a full scan of the object before we can write the value for
651+
// this property. This is not supported yet, so we will skip this property at the moment.
652+
653+
// default
654+
writer.WriteOptionalObject(OpenApiConstants.Default, Default, (w, d) => w.WriteAny(d));
655+
656+
// maximum
657+
writer.WriteProperty(OpenApiConstants.Maximum, Maximum);
658+
659+
// exclusiveMaximum
660+
writer.WriteProperty(OpenApiConstants.ExclusiveMaximum, ExclusiveMaximum);
661+
662+
// minimum
663+
writer.WriteProperty(OpenApiConstants.Minimum, Minimum);
664+
665+
// exclusiveMinimum
666+
writer.WriteProperty(OpenApiConstants.ExclusiveMinimum, ExclusiveMinimum);
667+
668+
// maxLength
669+
writer.WriteProperty(OpenApiConstants.MaxLength, MaxLength);
670+
671+
// minLength
672+
writer.WriteProperty(OpenApiConstants.MinLength, MinLength);
673+
674+
// pattern
675+
writer.WriteProperty(OpenApiConstants.Pattern, Pattern);
676+
677+
// maxItems
678+
writer.WriteProperty(OpenApiConstants.MaxItems, MaxItems);
679+
680+
// minItems
681+
writer.WriteProperty(OpenApiConstants.MinItems, MinItems);
682+
683+
// enum
684+
writer.WriteOptionalCollection(OpenApiConstants.Enum, Enum, (w, s) => w.WriteAny(new OpenApiAny(s)));
685+
686+
// multipleOf
687+
writer.WriteProperty(OpenApiConstants.MultipleOf, MultipleOf);
688+
689+
// extensions
690+
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0);
691+
}
692+
627693
internal void WriteAsSchemaProperties(
628694
IOpenApiWriter writer,
629695
ISet<string> parentRequiredProperties,

src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7-
using Json.Schema;
87
using Microsoft.OpenApi.Interfaces;
98
using Microsoft.OpenApi.Models;
109

@@ -17,7 +16,6 @@ public class OpenApiWorkspace
1716
{
1817
private readonly Dictionary<string, Uri> _documentsIdRegistry = new();
1918
private readonly Dictionary<Uri, Stream> _artifactsRegistry = new();
20-
private readonly Dictionary<Uri, IBaseDocument> _jsonSchemaRegistry = new();
2119
private readonly Dictionary<Uri, IOpenApiReferenceable> _IOpenApiReferenceableRegistry = new();
2220

2321
/// <summary>
@@ -53,7 +51,7 @@ public OpenApiWorkspace(OpenApiWorkspace workspace) { }
5351
/// <returns></returns>
5452
public int ComponentsCount()
5553
{
56-
return _IOpenApiReferenceableRegistry.Count + _jsonSchemaRegistry.Count + _artifactsRegistry.Count;
54+
return _IOpenApiReferenceableRegistry.Count + _artifactsRegistry.Count;
5755
}
5856

5957
/// <summary>
@@ -65,15 +63,7 @@ public int ComponentsCount()
6563
public bool RegisterComponent<T>(string location, T component)
6664
{
6765
var uri = ToLocationUrl(location);
68-
if (component is JsonSchema schema)
69-
{
70-
if (!_jsonSchemaRegistry.ContainsKey(uri))
71-
{
72-
_jsonSchemaRegistry[uri] = schema;
73-
return true;
74-
}
75-
}
76-
else if (component is IOpenApiReferenceable referenceable)
66+
if (component is IOpenApiReferenceable referenceable)
7767
{
7868
if (!_IOpenApiReferenceableRegistry.ContainsKey(uri))
7969
{
@@ -128,7 +118,7 @@ public Uri GetDocumentId(string key)
128118
public bool Contains(string location)
129119
{
130120
var key = ToLocationUrl(location);
131-
return _IOpenApiReferenceableRegistry.ContainsKey(key) || _jsonSchemaRegistry.ContainsKey(key) || _artifactsRegistry.ContainsKey(key);
121+
return _IOpenApiReferenceableRegistry.ContainsKey(key) || _artifactsRegistry.ContainsKey(key);
132122
}
133123

134124
/// <summary>
@@ -146,10 +136,6 @@ public T ResolveReference<T>(string location)
146136
{
147137
return (T)referenceableValue;
148138
}
149-
else if (_jsonSchemaRegistry.TryGetValue(uri, out var schemaValue))
150-
{
151-
return (T)schemaValue;
152-
}
153139
else if (_artifactsRegistry.TryGetValue(uri, out var artifact))
154140
{
155141
return (T)(object)artifact;
@@ -162,10 +148,5 @@ private Uri ToLocationUrl(string location)
162148
{
163149
return new(BaseUrl, location);
164150
}
165-
166-
internal Dictionary<Uri, IBaseDocument> GetSchemaRegistry()
167-
{
168-
return _jsonSchemaRegistry;
169-
}
170151
}
171152
}

src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using Json.Schema;
7-
using Microsoft.OpenApi.Models;
8-
94
namespace Microsoft.OpenApi.Writers
105
{
116
/// <summary>
@@ -73,32 +68,9 @@ public interface IOpenApiWriter
7368
/// </summary>
7469
void WriteValue(object value);
7570

76-
/// <summary>
77-
/// Write the JsonSchema object
78-
/// </summary>
79-
/// <param name="schema"></param>
80-
/// <param name="version"></param>
81-
void WriteJsonSchema(JsonSchema schema, OpenApiSpecVersion version);
82-
83-
/// <summary>
84-
/// Write the JsonSchema object
85-
/// </summary>
86-
/// <param name="writer">The IOpenApiWriter object</param>
87-
/// <param name="schema">The JsonSchema object</param>
88-
/// <param name="version"></param>
89-
void WriteJsonSchemaWithoutReference(IOpenApiWriter writer, JsonSchema schema, OpenApiSpecVersion version);
90-
9171
/// <summary>
9272
/// Flush the writer.
9373
/// </summary>
9474
void Flush();
95-
96-
/// <summary>
97-
/// Writes a reference to a JsonSchema object.
98-
/// </summary>
99-
/// <param name="writer"></param>
100-
/// <param name="reference"></param>
101-
/// <param name="version"></param>
102-
void WriteJsonSchemaReference(IOpenApiWriter writer, Uri reference, OpenApiSpecVersion version);
10375
}
10476
}

0 commit comments

Comments
 (0)