Skip to content

Commit 9fb165c

Browse files
fix: issues in openapi cli in dockerfile and github actions
fix: errors reported by deepsource
1 parent daf601b commit 9fb165c

File tree

8 files changed

+159
-15
lines changed

8 files changed

+159
-15
lines changed

.github/workflows/core-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ jobs:
4444
- name: Test
4545
run: |
4646
cd core
47+
# install openapi-generator-cli
48+
mkdir -p $HOME/ogc
49+
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > $HOME/ogc/openapi-generator-cli && chmod a+x $HOME/ogc/openapi-generator-cli
4750
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
4851
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
4952
export GOPATH=$HOME/go
5053
export GOBIN=$GOPATH/bin
51-
export PATH=$PATH:$GOPATH:$GOBIN
54+
export PATH=$PATH:$GOPATH:$GOBIN:$HOME/ogc
5255
go test -v ./... -race -coverprofile=coverage.out -coverpkg=./... -covermode=atomic
5356
cd ..
5457
- name: Upload coverage to Codecov

app/src/routes/projects-operations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const addToGithub = (projectEntity: ProjectEntity, response: Response) => {
9292
base64Json,
9393
'first commit',
9494
sha).then(resp => {
95+
Logger.debug(`commitCompageJson Response: ${JSON.stringify(resp.data)}`);
9596
const message = `The .compage/config.json in Repository for '${projectEntity.displayName}' is committed, ${projectEntity.displayName}[${projectEntity.id}] project is created successfully.`;
9697
Logger.info(message);
9798
return response.status(200).json(getCreateProjectResponse(projectEntity, message));
@@ -168,6 +169,7 @@ const createOnGithub = (projectEntity: ProjectEntity, response: Response) => {
168169
// TODO change description
169170
return createRepository(projectEntity.user.name, projectEntity.repository.name, projectEntity.repository.name, projectEntity.repository.isPublic)
170171
.then(resp => {
172+
Logger.debug(`createRepository Response: ${JSON.stringify(resp.data)}`);
171173
// create .compage/config.json file in GitHub repo
172174
return addToGithub(projectEntity, response);
173175
}).catch(error => {

app/src/util/github-client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const USER_REPO_URL = `https://api.github.com/user/repos`;
66
const REPO_URL = `https://api.github.com/repos`;
77

88
export const createRepository = async (userName: string, repositoryName: string, description: string, isPublic: boolean) => {
9-
console.log("isPublic : ", isPublic);
109
return axios({
1110
headers: {
1211
Accept: ACCEPT,

core/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Build stage will be used:
33
# - for building the application for production
44
# - as target for development (see devspace.yaml)
5-
FROM golang:1.20.2-alpine3.17 as builder
5+
FROM golang:1.20.5-alpine3.18 as builder
66

77
# Create project directory (workdir)
88
WORKDIR /app
@@ -25,13 +25,12 @@ WORKDIR /app
2525
RUN apk update && apk add protoc && apk add openjdk8 && apk add make && apk add bash && apk add curl && apk add jq && apk add --update go \
2626
&& curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh \
2727
> /app/openapi-generator-cli \
28-
&& chmod u+x /app/openapi-generator-cli \
29-
&& export PATH=$PATH:/app/
28+
&& chmod a+x /app/openapi-generator-cli
3029

3130
# Downloading and installing Maven
32-
ARG MAVEN_VERSION=3.9.2
31+
ARG MAVEN_VERSION=3.9.3
3332
ARG USER_HOME_DIR="/root"
34-
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
33+
ARG BASE_URL=https://dlcdn.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries
3534
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
3635
&& echo "Downloading maven" \
3736
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
@@ -44,7 +43,7 @@ RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
4443
ENV MAVEN_HOME /usr/share/maven
4544
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
4645

47-
ENV PATH="/usr/local/go/bin:$PATH"
46+
ENV PATH="/usr/local/go/bin:$PATH:/app/"
4847
ENV GOPATH /go
4948
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
5049
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

core/internal/languages/golang/frameworks/go-grpc-server/copier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (c Copier) addResourceSpecificTemplateData(resource *corenode.Resource) err
293293
var fieldNames []string
294294
for key, value := range resource.Fields {
295295
key = cases.Title(language.Und, cases.NoLower).String(key)
296-
fields[key] = value
296+
fields[key] = commonUtils.GetFieldsDataTypeForProtobuf(value)
297297
protoFields[key] = commonUtils.GetProtoBufDataType(value)
298298
fieldNames = append(fieldNames, key)
299299
}

core/internal/languages/utils/common.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

3-
func GetProtoBufDataType(value string) string {
3+
// GetFieldsDataTypeForProtobuf returns the protobuf data type for the given data type, Used in go struct
4+
func GetFieldsDataTypeForProtobuf(value string) string {
45
switch value {
56
case "rune":
67
fallthrough
@@ -15,6 +16,8 @@ func GetProtoBufDataType(value string) string {
1516
case "int32":
1617
return "int32"
1718
case "int64":
19+
fallthrough
20+
case "uint64":
1821
return "int64"
1922
case "uint":
2023
fallthrough
@@ -24,8 +27,42 @@ func GetProtoBufDataType(value string) string {
2427
fallthrough
2528
case "uint32":
2629
return "uint32"
30+
case "bool":
31+
return "bool"
32+
case "string":
33+
return "string"
34+
default:
35+
return value
36+
}
37+
}
38+
39+
// GetProtoBufDataType returns the protobuf data type for the given data type, Used in proto file
40+
func GetProtoBufDataType(value string) string {
41+
switch value {
42+
case "rune":
43+
fallthrough
44+
case "byte":
45+
fallthrough
46+
case "uintptr":
47+
fallthrough
48+
case "int":
49+
fallthrough
50+
case "int16":
51+
fallthrough
52+
case "int32":
53+
return "int32"
54+
case "int64":
55+
fallthrough
2756
case "uint64":
2857
return "int64"
58+
case "uint":
59+
fallthrough
60+
case "uint8":
61+
fallthrough
62+
case "uint16":
63+
fallthrough
64+
case "uint32":
65+
return "uint32"
2966
case "bool":
3067
return "bool"
3168
case "float32":
@@ -34,14 +71,14 @@ func GetProtoBufDataType(value string) string {
3471
fallthrough
3572
case "complex128":
3673
fallthrough
37-
case "float64 ":
74+
case "float64":
3875
return "double"
3976
case "[]byte":
4077
return "bytes"
4178
case "string":
4279
return "string"
4380
default:
44-
return "string"
81+
return value
4582
}
4683
}
4784

core/test/generator_test.go

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ func TestRestServerGenerator(t *testing.T) {
399399
input := project.GenerateCodeRequest{
400400
UserName: "mahendraintelops",
401401
RepositoryName: "first-project-github",
402-
ProjectName: "first-rest-project",
402+
ProjectName: "first-rest-server-project",
403403
Json: restServerConfigJSON,
404404
}
405405
defer func() {
406-
_ = os.RemoveAll("/tmp/first-rest-project")
406+
_ = os.RemoveAll("/tmp/first-rest-server-project")
407407
}()
408408

409409
// retrieve project struct
@@ -470,3 +470,107 @@ func TestGrpcServerGenerator(t *testing.T) {
470470
t.Errorf("handlers.Handle failed %s", err0.Error())
471471
}
472472
}
473+
474+
func TestRestServerWithOpenApiGenerator(t *testing.T) {
475+
restServerWithOpenAPIConfigJSON := `{
476+
"edges": {},
477+
"nodes": {
478+
"node-02": {
479+
"id": "node-02",
480+
"typeId": "node-type-circle",
481+
"consumerData": {
482+
"nodeType": "node-type-circle",
483+
"name": "sample-service",
484+
"language": "go",
485+
"restConfig": {
486+
"server": {
487+
"sqlDb": "",
488+
"port": "8080",
489+
"resources": [],
490+
"openApiFileYamlContent": "swagger: \"2.0\"\ninfo:\n version: 1.0.0\n title: Swagger Petstore\n license:\n name: MIT\nhost: petstore.swagger.io\nbasePath: /v1\nschemes:\n - http\nconsumes:\n - application/json\nproduces:\n - application/json\npaths:\n /pets:\n get:\n summary: List all pets\n operationId: listPets\n tags:\n - pets\n parameters:\n - name: limit\n in: query\n description: How many items to return at one time (max 100)\n required: false\n type: integer\n format: int32\n responses:\n \"200\":\n description: A paged array of pets\n headers:\n x-next:\n type: string\n description: A link to the next page of responses\n schema:\n $ref: '#/definitions/Pets'\n default:\n description: unexpected error\n schema:\n $ref: '#/definitions/Error'\n post:\n summary: Create a pet\n operationId: createPets\n tags:\n - pets\n responses:\n \"201\":\n description: Null response\n default:\n description: unexpected error\n schema:\n $ref: '#/definitions/Error'\n /pets/{petId}:\n get:\n summary: Info for a specific pet\n operationId: showPetById\n tags:\n - pets\n parameters:\n - name: petId\n in: path\n required: true\n description: The id of the pet to retrieve\n type: string\n responses:\n \"200\":\n description: Expected response to a valid request\n schema:\n $ref: '#/definitions/Pets'\n default:\n description: unexpected error\n schema:\n $ref: '#/definitions/Error'\ndefinitions:\n Pet:\n type: \"object\"\n required:\n - id\n - name\n properties:\n id:\n type: integer\n format: int64\n name:\n type: string\n tag:\n type: string\n Pets:\n type: array\n items:\n $ref: '#/definitions/Pet'\n Error:\n type: \"object\"\n required:\n - code\n - message\n properties:\n code:\n type: integer\n format: int32\n message:\n type: string\n"
491+
},
492+
"template": "openAPI",
493+
"framework": "go-gin-server"
494+
}
495+
}
496+
}
497+
}
498+
}`
499+
input := project.GenerateCodeRequest{
500+
UserName: "mahendraintelops",
501+
RepositoryName: "first-project-github",
502+
ProjectName: "first-rest-server-with-openapi-project",
503+
Json: restServerWithOpenAPIConfigJSON,
504+
}
505+
defer func() {
506+
_ = os.RemoveAll("/tmp/first-rest-server-with-openapi-project")
507+
}()
508+
509+
// retrieve project struct
510+
getProject, err := grpc.GetProject(&input)
511+
if err != nil {
512+
t.Errorf("grpc.GetProject conversion failed = %v", getProject)
513+
}
514+
// trigger project generation
515+
if err0 := handlers.Handle(getProject); err0 != nil {
516+
t.Errorf("handlers.Handle failed %s", err0.Error())
517+
}
518+
}
519+
520+
func TestWsServerGenerator(t *testing.T) {
521+
wsServerConfigJSON := `{
522+
"edges": {},
523+
"nodes": {
524+
"node-b0": {
525+
"id": "node-b0",
526+
"typeId": "node-type-circle",
527+
"consumerData": {
528+
"nodeType": "circle",
529+
"name": "student-service",
530+
"language": "go",
531+
"wsConfig": {
532+
"server": {
533+
"sqlDb": "SQLite",
534+
"port": "50052",
535+
"resources": [
536+
{
537+
"fields": {
538+
"Name": "string",
539+
"RollNumber": "int32",
540+
"College": "string"
541+
},
542+
"name": "StudentModel"
543+
}
544+
]
545+
},
546+
"framework": "go-ws-server",
547+
"template": "compage"
548+
}
549+
}
550+
}
551+
}
552+
}`
553+
input := project.GenerateCodeRequest{
554+
UserName: "mahendraintelops",
555+
RepositoryName: "first-project-github",
556+
ProjectName: "first-ws-server-project",
557+
Json: wsServerConfigJSON,
558+
}
559+
defer func() {
560+
_ = os.RemoveAll("/tmp/first-ws-server-project")
561+
}()
562+
563+
// retrieve project struct
564+
getProject, err := grpc.GetProject(&input)
565+
if err != nil {
566+
t.Errorf("grpc.GetProject conversion failed = %v", getProject)
567+
}
568+
// trigger project generation
569+
if err0 := handlers.Handle(getProject); err0 != nil {
570+
if err0.Error() == "unsupported protocol ws for language go" {
571+
// TODO implementation is yet to be done
572+
} else {
573+
t.Errorf("handlers.Handle failed %s", err0.Error())
574+
}
575+
}
576+
}

0 commit comments

Comments
 (0)