Пример #1
0
    protected override async Task <bool> ProcessInternal()
    {
        var files = await ListInputs();

        if (files.Length != 1)
        {
            return(false);
        }

        var content = await ReadFile(files[0]);

        var fs = new MemoryFileSystem();

        fs.WriteAllText(files[0], content);

        var serviceDefinition = SwaggerParser.Load(files[0], fs);
        var validator         = new RecursiveObjectValidator(PropertyNameResolver.JsonName);

        foreach (ValidationMessage validationEx in validator.GetValidationExceptions(new Uri(files[0], UriKind.RelativeOrAbsolute), serviceDefinition))
        {
            LogValidationMessage(validationEx);
        }

        return(true);
    }
Пример #2
0
    protected override async Task <bool> ProcessInternal()
    {
        new Settings
        {
            Namespace = await GetValue("namespace")
        };

        var files = await ListInputs();

        if (files.Length != 1)
        {
            return(false);
        }

        var content = await ReadFile(files[0]);

        var fs = new MemoryFileSystem();

        fs.WriteAllText(files[0], content);

        var serviceDefinition = SwaggerParser.Load(files[0], fs);
        var modeler           = new SwaggerModeler();
        var codeModel         = modeler.Build(serviceDefinition);

        var genericSerializer = new ModelSerializer <CodeModel>();
        var modelAsJson       = genericSerializer.ToJson(codeModel);

        WriteFile("codeMode.yaml", modelAsJson, null);

        return(true);
    }
Пример #3
0
    public async Task <bool> Process()
    {
        try
        {
            using (Start)
            {
                AddMessageListener();

                var files = await ListInputs();

                if (files.Length != 1)
                {
                    return(false);
                }

                var content = await ReadFile(files[0]);

                var fs = new MemoryFileSystem();
                fs.VirtualStore.Add(files[0], new StringBuilder(content));

                var serviceDefinition = SwaggerParser.Load(files[0], fs);
                var validator         = new RecursiveObjectValidator(PropertyNameResolver.JsonName);
                foreach (var validationEx in validator.GetValidationExceptions(new Uri(files[0], UriKind.RelativeOrAbsolute), serviceDefinition))
                {
                    Logger.Instance.Log(validationEx);
                }
            }
        }
        catch
        {
            return(false); // replace by more verbose feedback
        }

        return(true);
    }
Пример #4
0
        public ParseMultiFileSwaggerTests()
        {
            var resourceRoot = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent;
            var filePath     = Path.Combine(resourceRoot.FullName, Path.Combine("Resource", "arm-network", "2017-03-01", "swagger", "routeTable.json"));

            _serviceDefinition = SwaggerParser.Load(filePath, new FileSystem());
        }
Пример #5
0
        public ParseSwaggerWithBlacklistedEndpointTests()
        {
            var resourceRoot     = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent;
            var fileRelativePath = Path.Combine("Resource", "arm-web", "2016-03-01", "swagger", "DeletedWebApps.json");
            var filePath         = Path.Combine(resourceRoot.FullName, fileRelativePath);

            _serviceDefinition = SwaggerParser.Load(filePath, new FileSystem());
        }
        public ParseSingleFileSwaggerTests()
        {
            var resourceRoot     = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent;
            var fileRelativePath = Path.Combine("Resource", "arm-storage", "2017-06-01", "swagger", "storage.json");
            var filePath         = Path.Combine(resourceRoot.FullName, fileRelativePath);

            _serviceDefinition = SwaggerParser.Load(filePath, new FileSystem());
        }
Пример #7
0
    protected override async Task <bool> ProcessInternal()
    {
        var docStateInput = await GetValue <string>("merge-state");

        ServiceDefinitionDocumentState docState;

        if (!Enum.TryParse <ServiceDefinitionDocumentState>(docStateInput, true, out docState))
        {
            throw new Exception("Invalid Input for merge-state: " + docStateInput + ". Valid values are 'individual' and 'composed'.");
        }

        if ((await GetValue <bool>("azure-arm-validator.debugger")) ||
            (docState == ServiceDefinitionDocumentState.Composed && await GetValue <bool>("azure-arm-validator.composed-debugger")) ||
            (docState == ServiceDefinitionDocumentState.Individual && await GetValue <bool>("azure-arm-validator.individual-debugger")))
        {
            Debugger.Await();
        }

        var files = await ListInputs();

        foreach (var file in files)
        {
            var content = await ReadFile(file);

            var fs = new MemoryFileSystem();
            fs.WriteAllText(file, content);

            var serviceDefinition = SwaggerParser.Load(file, fs);
            var validator         = new RecursiveObjectValidator(PropertyNameResolver.JsonName);
            var docTypeInput      = (await GetValue <string>("openapi-type"));

            ServiceDefinitionDocumentType docType;
            // Convert data-plane to dataplane
            if (!Enum.TryParse <ServiceDefinitionDocumentType>(docTypeInput.Replace("-", ""), true, out docType))
            {
                throw new Exception("Invalid Input for openapi-type: " + docTypeInput + ". Valid values are 'arm', 'data-plane' or 'default'.");
            }

            var metadata = new ServiceDefinitionMetadata
            {
                ServiceDefinitionDocumentType = docType,
                MergeState = docState
            };

            foreach (ValidationMessage validationEx in validator.GetValidationExceptions(new Uri(file, UriKind.RelativeOrAbsolute), serviceDefinition, metadata))
            {
                LogValidationMessage(validationEx);
            }
        }
        return(true);
    }
        public void IdentifyDuplicatePaths()
        {
            // these swagger operations have more than 1 version of it. ( usually because they come from different providers)
            // client will pick the last swagger definition it sees and use that.
            var knownDuplicates = new HashSet <string>();

            knownDuplicates.Add(
                "https://management.azure.com/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/operations");
            knownDuplicates.Add(
                "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/moveResources");

            var root             = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent.Parent;
            var fileRelative     = Path.Combine("App_Data", "SwaggerSpecs");
            var swaggerDirectory = Path.Combine(root.FullName, fileRelative);
            var metadataObjects  = new List <MetadataObject>();

            foreach (var directory in Directory.GetDirectories(swaggerDirectory))
            {
                foreach (var swaggerFile in Directory.GetFiles(directory))
                {
                    var serviceDefinition = SwaggerParser.Load(swaggerFile, new FileSystem());
                    var builder           = new MetaDataObjectBuilder(serviceDefinition);
                    metadataObjects.AddRange(builder.GetMetaDataObjects());
                }
            }

            Assert.NotEmpty(metadataObjects);
            var speclessMetadataObjects = HyakUtils.GetSpeclessCsmOperations().ToList();

            Assert.NotEmpty(speclessMetadataObjects);
            metadataObjects.AddRange(speclessMetadataObjects);

            var operationsCount = new Dictionary <UniqueOperation, HashSet <string> >();

            foreach (var metadataObject in metadataObjects)
            {
                var uniqueOperation = new UniqueOperation(metadataObject.Url, metadataObject.HttpMethod);
                if (!operationsCount.ContainsKey(uniqueOperation))
                {
                    operationsCount[uniqueOperation] = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                }
                operationsCount[uniqueOperation].Add(metadataObject.ApiVersion);
            }
            foreach (var oCount in operationsCount)
            {
                if (oCount.Value.Count > 1)
                {
                    Assert.True(knownDuplicates.Contains(oCount.Key.Url));
                }
            }
        }
Пример #9
0
        public void ApiVersionInPathOverridesApiVersionInSwaggerRoot()
        {
            var resourceRoot      = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent;
            var filePath          = Path.Combine(resourceRoot.FullName, Path.Combine("Resource", "arm-network", "2017-03-01", "swagger", "vmssNetworkInterface.json"));
            var serviceDefinition = SwaggerParser.Load(filePath, new FileSystem());

            Assert.Equal("2017-03-01", serviceDefinition.Info.Version);

            var builder         = new MetaDataObjectBuilder(serviceDefinition);
            var metaDataObjects = builder.GetMetaDataObjects();

            Assert.Equal(3, metaDataObjects.Count());
            foreach (var metaDataObject in metaDataObjects)
            {
                Assert.Equal("2016-09-01", metaDataObject.ApiVersion);
            }
        }