Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • gitkeep
  • dev protected
  • Sprint/2022-01
  • Sprint/2021-2022
  • Issue/1742-FixesForExternalUserInvitation
  • Sprint/2021-23
  • Sprint/2021-12
  • Product/1548-projectInviteMngmnt
  • Topic/1531-UseMangmntTableView
  • Sprint/2021-10
  • Topic/1530-invitationUserManagement
  • Topic/1302-testsForUserManagementApp
  • Product/1182-testsForUserManagementApp
  • Product/1442-projectInviteMngmnt
  • Product/1107-frontendPerformance
  • Topic/1227-frontendPerformance
  • Product/1215-gitlabCleanUp
  • Hotfix/1185-deleteButton
  • Sprint/2020-19
  • v1.11.1
  • v1.11.0
  • v1.10.1
  • v1.10.0
  • v1.9.0
  • v1.8.0
  • v1.7.5
  • v1.7.4
  • v1.7.3
  • v1.7.2
  • v1.7.1
  • v1.7.0
  • v1.6.1
  • v1.6.0
  • v1.5.1
  • v1.5.0
  • v1.4.1
  • v1.4.0
  • v1.3.0
  • v1.2.1
40 results

main.ts

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CoscineCodeGenerator.cs 3.04 KiB
    using Coscine.Configuration;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Threading.Tasks;
    
    namespace Coscine.CodeGen.CodeGenerator
    {
        public class CoscineCodeGenerator : CodeGenerator
        {
            private readonly IConfiguration _configuration;
    
            public CoscineCodeGenerator(IConfiguration configuration)
            {
                this._configuration = configuration;
            }
    
            public async override Task<string> GetClientGenerator()
            {
                var jarDownloadLink = await _configuration.GetStringAsync("coscine/local/codegen/jarlink",
                                "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.2.1/openapi-generator-cli-5.2.1.jar"
                            );
    
                var webClient = new WebClient();
    
                var jarFileName = await _configuration.GetStringAsync("coscine/local/codegen/jarpath", "codegen.jar");
    
                await webClient.DownloadFileTaskAsync(new Uri(jarDownloadLink), jarFileName);
                return jarFileName;
            }
    
            public async override Task<IEnumerable<string>> GetApiNames()
            {
                var apiPrefix = "coscine/apis/";
    
                var keys = await _configuration.KeysAsync(apiPrefix);
                return keys.Select((entry) => entry.Split('/')[2]).Distinct();
            }
    
            internal async override Task<string> GetOutputPath()
            {
                return await _configuration.GetStringAsync("coscine/local/codegen/outputpath", "Output");
            }
    
            internal override Task<string> GetSwaggerUrl(string domainName, string hostName, string key)
            {
                return Task.FromResult($"https://{hostName}.{domainName}/coscine/api/{key}/swagger/v1/swagger.json");
            }
    
            internal override string GetGenerationCommand(string outputPath, string jarFileName, string key, string swaggerUrl)
            {
                return $"java \"-Dio.swagger.parser.util.RemoteUrl.trustAll=true\" \"-Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true\" -jar \"{jarFileName}\" generate -i \"{swaggerUrl}\" -g typescript-axios -o \"{outputPath}/{key}\" --skip-validate-spec";
            }
    
            internal override Task<string> GetCustomBasePath(string directoryName)
            {
                return Task.FromResult($"https://' + getHostName() + '/coscine/api/{directoryName}");
            }
    
            internal override Task<string> GetCustomCodeForCombinationFile(string combinationFileText)
            {
                combinationFileText += "let accessToken = '';";
    
                combinationFileText += @"
    if (typeof coscine !== 'undefined') {
      accessToken = coscine.authorization.bearer;
    }
    
    const getHostName = () => {
      let hostName = typeof window !== 'undefined' ? window.location.hostname : 'coscine.rwth-aachen.de';
      if (hostName.indexOf(':') !== -1) {
        if (hostName.indexOf('https://') !== -1) {
          hostName = hostName.replace('https://', '');
        }
        hostName = hostName.substr(0, hostName.indexOf(':'));
      }
      return hostName;
    };
    
    ";
                return Task.FromResult(combinationFileText);
            }
        }
    }