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
c992191f
Commit
c992191f
authored
3 years ago
by
Benedikt Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
Docs + small cleanup
parent
e567d4b5
No related branches found
No related tags found
1 merge request
!1
New: Create a Api Client Script
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+16
-1
16 additions, 1 deletion
README.md
src/CodeGen/CodeGenerator/CodeGenerator.cs
+14
-8
14 additions, 8 deletions
src/CodeGen/CodeGenerator/CodeGenerator.cs
src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs
+6
-1
6 additions, 1 deletion
src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs
with
36 additions
and
10 deletions
README.md
+
16
−
1
View file @
c992191f
# CodeGen
# CodeGen
This project aims to be able to generate Code from our Swagger / OpenAPI definitions.
This project aims to be able to generate Code from our Swagger / OpenAPI definitions.
## Build
*
.NET 5 SDK has to be installed
*
`dotnet build src`
## Usage
*
Execute the built CodeGen executable
*
You should find the output client definitions in the specified output folder (default.
`Output`
)
## Implementation
An abstract
`CodeGenerator`
has been implemented fully as a
`CoscineCodeGenerator`
.
The idea is that with this abstraction someone can easily adapt and generate the code they want to produce.
This diff is collapsed.
Click to expand it.
src/CodeGen/CodeGenerator/CodeGenerator.cs
+
14
−
8
View file @
c992191f
...
@@ -10,6 +10,7 @@ namespace Coscine.CodeGen.CodeGenerator
...
@@ -10,6 +10,7 @@ namespace Coscine.CodeGen.CodeGenerator
{
{
public
abstract
class
CodeGenerator
public
abstract
class
CodeGenerator
{
{
#
region
Functionality
public
async
Task
GenerateCode
()
public
async
Task
GenerateCode
()
{
{
var
jarFileName
=
await
GetClientGenerator
();
var
jarFileName
=
await
GetClientGenerator
();
...
@@ -36,9 +37,9 @@ namespace Coscine.CodeGen.CodeGenerator
...
@@ -36,9 +37,9 @@ namespace Coscine.CodeGen.CodeGenerator
foreach
(
var
key
in
keys
)
foreach
(
var
key
in
keys
)
{
{
Console
.
WriteLine
(
key
);
Console
.
WriteLine
(
key
);
string
swaggerUrl
=
await
GetSwaggerUrl
(
domainName
,
hostName
,
key
);
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"
;
var
swaggerUrl
=
await
GetSwaggerUrl
(
domainName
,
hostName
,
key
);
var
command
=
GetGenerationCommand
(
outputPath
,
jarFileName
,
key
,
swaggerUrl
);
await
ExecuteCommand
(
command
);
await
ExecuteCommand
(
command
);
}
}
...
@@ -159,17 +160,22 @@ const apis = implementations(instance);
...
@@ -159,17 +160,22 @@ const apis = implementations(instance);
return
process
.
WaitForExitAsync
();
return
process
.
WaitForExitAsync
();
}
}
}
}
#
endregion
internal
abstract
Task
<
string
>
GetSwaggerUrl
(
string
domainName
,
string
hostName
,
string
key
);
#
region
Abstract
Methods
public
abstract
Task
<
string
>
GetClientGenerator
();
internal
abstract
Task
<
string
>
GetCustomBasePath
(
string
directoryName
);
internal
abstract
Task
<
string
>
GetCustomCodeForCombinationFi
le
(
string
combinationFileText
);
public
abstract
Task
<
IEnumerab
le
<
string
>>
GetApiNames
(
);
internal
abstract
Task
<
string
>
GetOutputPath
();
internal
abstract
Task
<
string
>
GetOutputPath
();
public
abstract
Task
<
string
>
Get
ClientGenerator
(
);
internal
abstract
Task
<
string
>
Get
SwaggerUrl
(
string
domainName
,
string
hostName
,
string
key
);
public
abstract
Task
<
IEnumerable
<
string
>>
GetApiNames
();
internal
abstract
string
GetGenerationCommand
(
string
outputPath
,
string
jarFileName
,
string
key
,
string
swaggerUrl
);
internal
abstract
Task
<
string
>
GetCustomBasePath
(
string
directoryName
);
internal
abstract
Task
<
string
>
GetCustomCodeForCombinationFile
(
string
combinationFileText
);
#
endregion
}
}
}
}
This diff is collapsed.
Click to expand it.
src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs
+
6
−
1
View file @
c992191f
...
@@ -19,7 +19,6 @@ namespace Coscine.CodeGen.CodeGenerator
...
@@ -19,7 +19,6 @@ namespace Coscine.CodeGen.CodeGenerator
public
async
override
Task
<
string
>
GetClientGenerator
()
public
async
override
Task
<
string
>
GetClientGenerator
()
{
{
var
jarDownloadLink
=
await
_configuration
.
GetStringAsync
(
"coscine/local/codegen/jarlink"
,
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"
"https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.2.1/openapi-generator-cli-5.2.1.jar"
);
);
...
@@ -43,11 +42,17 @@ namespace Coscine.CodeGen.CodeGenerator
...
@@ -43,11 +42,17 @@ namespace Coscine.CodeGen.CodeGenerator
{
{
return
await
_configuration
.
GetStringAsync
(
"coscine/local/codegen/outputpath"
,
"Output"
);
return
await
_configuration
.
GetStringAsync
(
"coscine/local/codegen/outputpath"
,
"Output"
);
}
}
internal
override
Task
<
string
>
GetSwaggerUrl
(
string
domainName
,
string
hostName
,
string
key
)
internal
override
Task
<
string
>
GetSwaggerUrl
(
string
domainName
,
string
hostName
,
string
key
)
{
{
return
Task
.
FromResult
(
$"https://
{
hostName
}
.
{
domainName
}
/coscine/api/
{
key
}
/swagger/v1/swagger.json"
);
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
)
internal
override
Task
<
string
>
GetCustomBasePath
(
string
directoryName
)
{
{
return
Task
.
FromResult
(
$"https://' + getHostName() + '/coscine/api/
{
directoryName
}
"
);
return
Task
.
FromResult
(
$"https://' + getHostName() + '/coscine/api/
{
directoryName
}
"
);
...
...
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