Ejemplo n.º 1
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);
    }