Beispiel #1
0
        private static string GetVersion(RootNode rootNode)
        {
            var versionNode = rootNode.Find(new JsonPointer("/openapi"));

            if (versionNode != null)
            {
                return(versionNode.GetScalarValue());
            }

            versionNode = rootNode.Find(new JsonPointer("/swagger"));
            if (versionNode != null)
            {
                return(versionNode.GetScalarValue());
            }
            return(null);
        }
Beispiel #2
0
        public static IReference LoadReference(OpenApiReference reference, RootNode rootNode)
        {
            IReference referencedObject = null;
            ParseNode  node             = rootNode.Find(GetPointer(reference));

            if (node == null && reference.ReferenceType != ReferenceType.Tags)
            {
                return(null);
            }
            switch (reference.ReferenceType)
            {
            case ReferenceType.Schema:
                referencedObject = OpenApiV2Reader.LoadSchema(node);
                break;

            case ReferenceType.Parameter:
                referencedObject = OpenApiV2Reader.LoadParameter(node);
                break;

            case ReferenceType.SecurityScheme:
                referencedObject = OpenApiV2Reader.LoadSecurityScheme(node);
                break;

            case ReferenceType.Tags:
                ListNode list = (ListNode)node;
                if (list != null)
                {
                    foreach (var item in list)
                    {
                        var tag = OpenApiV2Reader.LoadTag(item);

                        if (tag.Name == reference.TypeName)
                        {
                            return(tag);
                        }
                    }
                }
                else
                {
                    return(new Tag()
                    {
                        Name = reference.TypeName
                    });
                }
                break;

            default:
                throw new DomainParseException($"Unknown $ref {reference.ReferenceType} at {reference.ToString()}");
            }

            return(referencedObject);
        }
        public static IReference LoadReference(OpenApiReference pointer, RootNode rootNode)
        {
            IReference referencedObject = null;

            var node = rootNode.Find(pointer.GetLocalPointer());

            if (node == null && pointer.ReferenceType != ReferenceType.Tags)
            {
                return(null);
            }

            switch (pointer.ReferenceType)
            {
            case ReferenceType.Schema:
                referencedObject = OpenApiV3.LoadSchema(node);
                break;

            case ReferenceType.Parameter:

                referencedObject = OpenApiV3.LoadParameter(node);
                break;

            case ReferenceType.Callback:
                referencedObject = OpenApiV3.LoadCallback(node);
                break;

            case ReferenceType.SecurityScheme:
                referencedObject = OpenApiV3.LoadSecurityScheme(node);
                break;

            case ReferenceType.Link:
                referencedObject = OpenApiV3.LoadLink(node);
                break;

            case ReferenceType.Example:
                referencedObject = OpenApiV3.LoadExample(node);
                break;

            case ReferenceType.Tags:
                ListNode list = (ListNode)node;
                if (list != null)
                {
                    foreach (var item in list)
                    {
                        var tag = OpenApiV3.LoadTag(item);

                        if (tag.Name == pointer.TypeName)
                        {
                            return(tag);
                        }
                    }
                }
                else
                {
                    return(new Tag()
                    {
                        Name = pointer.TypeName
                    });
                }

                break;

            default:
                throw new DomainParseException($"Unknown type of $ref {pointer.ReferenceType} at {pointer.ToString()}");
            }
            return(referencedObject);
        }