Ejemplo n.º 1
0
        public async Task <APITemplate> CreateAPITemplateAsync(CreatorConfig creatorConfig)
        {
            YAMLReader yamlReader = new YAMLReader();
            // create api schema with properties
            APITemplate apiSchema = new APITemplate()
            {
                type       = "Microsoft.ApiManagement/service/apis",
                apiVersion = "2018-06-01-preview",
                properties = new APITemplateProperties()
                {
                    contentFormat = "swagger-json",
                    contentValue  = await yamlReader.RetrieveLocationContents(creatorConfig.api.openApiSpec),
                    // supplied via optional arguments
                    apiVersion             = creatorConfig.api.apiVersion ?? "",
                    apiRevision            = creatorConfig.api.revision ?? "",
                    apiVersionSetId        = creatorConfig.api.versionSetId ?? "",
                    path                   = creatorConfig.api.suffix ?? "",
                    apiRevisionDescription = creatorConfig.api.revisionDescription ?? "",
                    apiVersionDescription  = creatorConfig.api.apiVersionDescription ?? "",
                    apiVersionSet          = creatorConfig.apiVersionSet ?? null,
                    authenticationSettings = creatorConfig.api.authenticationSettings ?? null
                }
            };

            return(apiSchema);
        }
Ejemplo n.º 2
0
        public CreateCommand()
        {
            this.Name        = Constants.CreateName;
            this.Description = Constants.CreateDescription;

            // list command options
            CommandOption configFile = this.Option("--configFile <configFile>", "Config YAML file location", CommandOptionType.SingleValue).IsRequired();

            this.HelpOption();

            this.OnExecute(async() =>
            {
                // convert config file to CreatorConfig class
                YAMLReader yamlReader       = new YAMLReader();
                CreatorConfig creatorConfig = yamlReader.ConvertConfigYAMLToCreatorConfig(configFile.Value());

                // ensure required parameters have been passed in
                if (creatorConfig.outputLocation == null)
                {
                    throw new CommandParsingException(this, "Output location is required");
                }
                else if (creatorConfig.version == null)
                {
                    throw new CommandParsingException(this, "Version is required");
                }
                else if (creatorConfig.api == null)
                {
                    throw new CommandParsingException(this, "API configuration is required");
                }
                else if (creatorConfig.api.openApiSpec == null)
                {
                    throw new CommandParsingException(this, "Open API Spec is required");
                }
                else if (creatorConfig.api.suffix == null)
                {
                    throw new CommandParsingException(this, "API suffix is required");
                }
                else
                {
                    // required parameters have been supplied

                    // initialize helper classes
                    APITemplateCreator apiTemplateCreator = new APITemplateCreator();
                    ARMTemplateWriter armTemplateWriter   = new ARMTemplateWriter();

                    // create templates from provided configuration
                    APITemplate apiTemplate = await apiTemplateCreator.CreateAPITemplateAsync(creatorConfig);

                    // write templates to outputLocation
                    armTemplateWriter.WriteAPITemplateToFile(apiTemplate, creatorConfig.outputLocation);
                    ColoredConsole.WriteLine("Templates written to output location");
                }
                return(0);
            });
        }
 public Exception AttemptAuthenticationSettingsConversion(CLICreatorArguments cliArguments)
 {
     try
     {
         YAMLReader yamlReader = new YAMLReader();
         APITemplateAuthenticationSettings authenticationSettings = yamlReader.ConvertYAMLFileToAuthenticationSettings(cliArguments.authenticationSettingsFile);
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
 public Exception AttemptAPIVersionSetConversion(CLICreatorArguments cliArguments)
 {
     try
     {
         YAMLReader            yamlReader = new YAMLReader();
         APITemplateVersionSet versionSet = yamlReader.ConvertYAMLFileToAPIVersionSet(cliArguments.apiVersionSetFile);
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
        public async Task <APITemplate> CreateAPITemplateAsync(OpenApiDocument doc, CLICreatorArguments cliArguments)
        {
            YAMLReader yamlReader = new YAMLReader();
            // create api schema with properties
            APITemplate apiSchema = new APITemplate()
            {
                name       = doc.Info.Title,
                type       = "Microsoft.ApiManagement/service/apis",
                apiVersion = "2018-06-01-preview",
                properties = new APITemplateProperties()
                {
                    contentFormat                 = "swagger-json",
                    contentValue                  = await CreateOpenAPISpecContentsAsync(cliArguments),
                    subscriptionRequired          = IsSubscriptionRequired(doc),
                    protocols                     = CreateProtocols(doc),
                    serviceUrl                    = doc.Servers[0].Url,
                    subscriptionKeyParameterNames = CreateSubscriptionKeyParameterNames(doc),
                    description                   = doc.Info.Description,
                    displayName                   = doc.Info.Title,
                    apiVersion                    = cliArguments.apiVersion ?? doc.Info.Version,
                    apiRevision                   = cliArguments.apiRevision ?? "",
                    apiVersionSetId               = cliArguments.apiVersionSetId ?? "",
                    path = cliArguments.path ?? "",
                    apiRevisionDescription = cliArguments.apiRevisionDescription ?? "",
                    apiVersionDescription  = cliArguments.apiVersionDescription ?? "",
                    apiVersionSet          = cliArguments.apiVersionSetFile != null?yamlReader.ConvertYAMLFileToAPIVersionSet(cliArguments.apiVersionSetFile) : null,
                                                 authenticationSettings = cliArguments.authenticationSettingsFile != null?yamlReader.ConvertYAMLFileToAuthenticationSettings(cliArguments.authenticationSettingsFile) : null,
                                                                              // assumptions
                                                                              type         = "http",
                                                                              apiType      = "http",
                                                                              wsdlSelector = null
                }
            };

            // create resources
            List <APITemplateResource> resources          = new List <APITemplateResource>();
            SchemaTemplateCreator      schemaCreator      = new SchemaTemplateCreator();
            List <SchemaTemplate>      schemaTemplates    = schemaCreator.CreateSchemaTemplates(doc);
            OperationTemplateCreator   operationCreator   = new OperationTemplateCreator();
            List <OperationTemplate>   operationTemplates = operationCreator.CreateOperationTemplates(doc);

            resources.AddRange(schemaTemplates);
            resources.AddRange(operationTemplates);
            apiSchema.resources = resources.ToArray();

            return(apiSchema);
        }