예제 #1
0
        public IReference GetReferencedObject(OpenApiReference reference)
        {
            IReference returnValue = null;

            referenceStore.TryGetValue(reference.ToString(), out returnValue);

            if (returnValue == null)
            {
                if (previousPointers.Contains(reference.ToString()))
                {
                    return(null); // Return reference object?
                }
                previousPointers.Push(reference.ToString());
                returnValue = this.referenceService.LoadReference(reference);
                previousPointers.Pop();
                if (returnValue != null)
                {
                    returnValue.Pointer = reference;
                    referenceStore.Add(reference.ToString(), returnValue);
                }
                else
                {
                    ParseErrors.Add(new OpenApiError(this.GetLocation(), $"Cannot resolve $ref {reference.ToString()}"));
                }
            }

            return(returnValue);
        }
예제 #2
0
        public IReference LoadReference(OpenApiReference reference)
        {
            var referenceObject = this.loadReference(reference, this.rootNode);

            if (referenceObject == null)
            {
                throw new DomainParseException($"Cannot locate $ref {reference.ToString()}");
            }
            return(referenceObject);
        }
예제 #3
0
        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);
        }
예제 #4
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);
        }