Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeGen
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Coscine
backend
scripts
CodeGen
Commits
b6550fc6
Commit
b6550fc6
authored
Aug 31, 2021
by
Benedikt Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
Generate correct axios api clients
parent
13ee686f
No related branches found
No related tags found
1 merge request
!1
New: Create a Api Client Script
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/CodeGen/Program.cs
+35
-18
35 additions, 18 deletions
src/CodeGen/Program.cs
with
35 additions
and
18 deletions
src/CodeGen/Program.cs
+
35
−
18
View file @
b6550fc6
...
@@ -20,7 +20,10 @@ namespace Coscine.CodeGen
...
@@ -20,7 +20,10 @@ namespace Coscine.CodeGen
{
{
var
configuration
=
new
ConsulConfiguration
();
var
configuration
=
new
ConsulConfiguration
();
var
jarDownloadLink
=
await
configuration
.
GetStringAsync
(
"coscine/local/codegen/jarlink"
,
"https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.27/swagger-codegen-cli-3.0.27.jar"
);
var
jarDownloadLink
=
await
configuration
.
GetStringAsync
(
"coscine/local/codegen/jarlink"
,
//"https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.27/swagger-codegen-cli-3.0.27.jar"
"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
webClient
=
new
WebClient
();
...
@@ -48,7 +51,7 @@ namespace Coscine.CodeGen
...
@@ -48,7 +51,7 @@ namespace Coscine.CodeGen
var
swaggerUrl
=
$"https://
{
hostName
}
.
{
domainName
}
/coscine/api/
{
key
}
/swagger/v1/swagger.json"
;
var
swaggerUrl
=
$"https://
{
hostName
}
.
{
domainName
}
/coscine/api/
{
key
}
/swagger/v1/swagger.json"
;
var
command
=
$"java -jar \"
{
jarFileName
}
\" generate -i \"
{
swaggerUrl
}
\" -
l
typescript-
fetch
-o \"
{
outputPath
}
/
{
key
}
\" -
Dio.swagger.parser.util.RemoteUrl.trustAll=true -Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true
"
;
var
command
=
$"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
"
;
await
ExecuteCommand
(
command
);
await
ExecuteCommand
(
command
);
}
}
...
@@ -58,6 +61,8 @@ namespace Coscine.CodeGen
...
@@ -58,6 +61,8 @@ namespace Coscine.CodeGen
var
combinationFileImports
=
new
List
<
string
>();
var
combinationFileImports
=
new
List
<
string
>();
var
combinationFileExports
=
new
List
<
string
>();
var
combinationFileExports
=
new
List
<
string
>();
var
first
=
true
;
foreach
(
var
directory
in
Directory
.
GetDirectories
(
outputPath
))
foreach
(
var
directory
in
Directory
.
GetDirectories
(
outputPath
))
{
{
var
apiName
=
directory
[(
directory
.
LastIndexOf
(
"."
)
+
1
)..];
var
apiName
=
directory
[(
directory
.
LastIndexOf
(
"."
)
+
1
)..];
...
@@ -67,19 +72,27 @@ namespace Coscine.CodeGen
...
@@ -67,19 +72,27 @@ namespace Coscine.CodeGen
apiName
=
apiName
.
Replace
(
"Notices"
,
"Notice"
);
apiName
=
apiName
.
Replace
(
"Notices"
,
"Notice"
);
combinationFileImports
.
Add
(
$"import
{{
{
apiName
}
ApiFactory
}}
from './
{
directoryName
}
/api';"
);
combinationFileImports
.
Add
(
$"import
{{
{
apiName
}
ApiFactory
}}
from './
{
directoryName
}
/api';"
);
combinationFileExports
.
Add
(
$"
{
apiName
}
Api:
{
apiName
}
ApiFactory(
{{
'
accessToken
'
:
accessToken
}}
, isomorphicFetch, 'https://' + getHostName() + '/coscine/api/
{
directoryName
}
')"
);
if
(
first
)
{
first
=
false
;
combinationFileImports
.
Add
(
$"import
{{
Configuration
}}
from './
{
directoryName
}
/configuration';"
);
}
combinationFileExports
.
Add
(
$"
{
apiName
}
Api:
{
apiName
}
ApiFactory(new Configuration(
{{
'
accessToken
'
:
accessToken
}}
), 'https://' + getHostName() + '/coscine/api/
{
directoryName
}
', axios)"
);
}
}
var
combinationFileText
=
"import * as isomorphicFetch from 'isomorphic-fetch';\n\n"
;
var
combinationFileText
=
"import { AxiosInstance } from 'axios';\n\n"
;
combinationFileText
+=
string
.
Join
(
'\n'
,
combinationFileImports
);
combinationFileText
+=
string
.
Join
(
'\n'
,
combinationFileImports
);
combinationFileText
+=
"\n\n"
;
combinationFileText
+=
"\n\n"
;
combinationFileText
+=
"declare var coscine: { authorization: { bearer: string }};\n"
;
combinationFileText
+=
"let accessToken = '';"
;
combinationFileText
+=
"const accessToken = coscine.authorization.bearer;\n"
;
combinationFileText
+=
@"
if (typeof coscine !== 'undefined') {
accessToken = coscine.authorization.bearer;
}
combinationFileText
+=
@"
const getHostName = () => {
const getHostName = () => {
let hostName =
window.location.hostname
;
let hostName =
typeof window !== 'undefined' ? window.location.hostname : 'coscine.rwth-aachen.de'
;
if (hostName.indexOf(':') !== -1) {
if (hostName.indexOf(':') !== -1) {
if (hostName.indexOf('https://') !== -1) {
if (hostName.indexOf('https://') !== -1) {
hostName = hostName.replace('https://', '');
hostName = hostName.replace('https://', '');
...
@@ -93,12 +106,13 @@ namespace Coscine.CodeGen
...
@@ -93,12 +106,13 @@ namespace Coscine.CodeGen
combinationFileText
+=
"export default {\n "
;
combinationFileText
+=
@"function implementations(axios?: AxiosInstance) {
return {
"
;
combinationFileText
+=
string
.
Join
(
",\n "
,
combinationFileExports
);
combinationFileText
+=
string
.
Join
(
",\n "
,
combinationFileExports
);
combinationFileText
+=
"\n
}
;\n"
;
combinationFileText
+=
"\n
};\n};\n\nexport default implementations
;\n"
;
await
File
.
WriteAllTextAsync
(
combinationFile
,
combinationFileText
);
await
File
.
WriteAllTextAsync
(
combinationFile
,
combinationFileText
);
}
}
private
static
Task
ExecuteCommand
(
string
command
)
private
static
Task
ExecuteCommand
(
string
command
)
...
@@ -119,15 +133,18 @@ namespace Coscine.CodeGen
...
@@ -119,15 +133,18 @@ namespace Coscine.CodeGen
{
{
process
.
Start
();
process
.
Start
();
string
output
=
process
.
StandardOutput
.
ReadToEnd
();
var
outputTask
=
process
.
StandardOutput
.
ReadToEndAsync
();
Console
.
WriteLine
(
output
);
var
errorTask
=
process
.
StandardError
.
ReadToEndAsync
();
Task
.
WaitAll
(
outputTask
,
errorTask
);
Console
.
WriteLine
(
outputTask
.
Result
);
Console
.
WriteLine
(
errorTask
.
Result
);
string
errors
=
process
.
StandardError
.
ReadToEnd
();
Console
.
WriteLine
(
errors
);
return
process
.
WaitForExitAsync
();
return
process
.
WaitForExitAsync
();
}
}
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment