Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swagger skeleton and an example #35

Merged
merged 2 commits into from
Dec 5, 2023
Merged

Add Swagger skeleton and an example #35

merged 2 commits into from
Dec 5, 2023

Conversation

yunkon-kim
Copy link
Member

@yunkon-kim yunkon-kim commented Nov 30, 2023

Swagger 스켈레톤과 예시를 추가하는 PR 입니다.

  1. Swagger annotation을 추가하였습니다.
  • server.go 상단 참고
  • Handler 상단 참고
  1. swag init시 이슈가 있어 해결 하였습니다. (참고: cannot find type definition: multipart.FileHeader swaggo/swag#802)

에러 메시지:

Error parsing type definition 'controllers.GenDataParams': gcpCredential: cannot find type definition: multipart.FileHeader

해결 방법:

  • Missing json 또는 form 태그 보완
  • GCPCredential *multipart.FileHeader에 swaggerignore:"true" 태그 추가
  • Handler annotation에 // @Param CredentialGCP formData file true "Parameters required to generate test data"추가
  1. 편의를 위해 Makefile 추가하였습니다.

결과 - Swagger UI

image

@@ -12,11 +12,11 @@ import (

type GenDataParams struct {
Region string `json:"region" form:"region"`
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
AccessKey string `json:"accessKey" form:"accessKey"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
by the way, what is the objective of the form tag. application/x-www-form-urlencoded ? I am not familiar with it.

https://github.com/golang/go/wiki/Well-known-struct-tags#list-of-well-known-struct-tags

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(do we get any problem if we remove it?)

Copy link
Member Author

@yunkon-kim yunkon-kim Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zcon-cychoi / @jjang-go 께서 form tag가 기존 코드에 영향을 주거나 관련된 부분이 있는지 파악해 보신 후, 의견 남겨주시면 좋을 것 같습니다 ^^

Copy link
Contributor

@jjang-go jjang-go Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경된 form tag로 기존 코드에 영향을 주는지 테스트는 해보았으나 데이터 생성 시 별 다른 오류 없이 실행은 잘 됩니다. 세부 기술적인 부분은 담당자이신 @zcon-cychoi 께서 한번 확인 해주셔야 할 거 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjang-go 넵 감사합니다!

Copy link
Member Author

@yunkon-kim yunkon-kim Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zcon-cychoi, @jjang-go 제가 모호하게 말씀드렸나봅니다 ^^;;

form 태그를 모두 삭제해도 프로그램 실행 및 기능 동작에 영향을 주지 않는지 확인 드렸던 부분입니다.

조사해보니 form tag는 Web Framework에서 활용되고 있었습니다.

간단히 코드상으로 확인해 봤더니 gendata.gofrom:"checkSQL"gen-data.htmlfor="checkSQL", id="checkSQL", name="checkSQL" 와 연관이 있을 것 같습니다. (한 가지 예시입니다.)

gendata.go

type GenDataParams struct {
  ...
  CheckSQL        string `json:"checkSQL" form:"checkSQL"`
  ...

gen-data.html

    <label for="checkSQL" class="form-label">정형 데이터</label>
    <div class="input-group mb-3">
        <div class="form-check form-check-inline">
            <input class="form-check-input" type="checkbox" id="checkSQL" name="checkSQL">

아무래도 form tag 삭제 시 GUI 상에 이슈가 있겠죠? ^^ 확인을 부탁드립니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별개로, REST API를 제공하는 파트와 HTML Page 를 제공하는 파트의 구분해 주시면 좋을 것 같습니다.

REST API 제공 파트에만 Swagger documentation을 적용하기 위해서 입니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunkon-kim form tag 제거 시 GCP 데이터 생성에서 작동하지 않습니다. Crendential 파일 업로드 부분 때문에 form-data 으로 받게 해놨습니다. GCP 를 제외한 나머지 데이터 생성 부분은 json 으로 처리되어 혼용해서 쓰게 되었습니다.
마이그레이션 기능들은 전부 form 을 사용합니다.

파트 구분은 별개의 go 파일로 나누면 되는건가요? 아니면 모듈 단위로 구분이 되어야 하는건가요?

Copy link
Member Author

@yunkon-kim yunkon-kim Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zcon-cychoi 넵 설명 감사드립니다. 자세히 설명해 주셔서 바로바로 이해가 잘 되네요 😃

Migration 이외의 파트를 제가 구분하여 PR 올리도록 하겠습니다.

Migration 관련 파트는 Credential 관련 부분을 분리해야할 필요가 있고요.
아래 두 가지 안 정도를 생각해 볼 수 있을 것 같습니다.
1안) cm-data-mold binary와 같은 디렉토리에 credential을 사전 세팅
2안) Credential을 최초 한번 업로드하고, 이후 Migration시 file의 ID 또는 path를 활용하는 방안

관련하여 수정 가능여부, 공수, 이슈 등을 먼저 파악해 보려고 합니다. 확인해 보시고 공유해주시기 바랍니다.
(코드 개선은 이후에 진행하도록 하겠습니다.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우선 이번 PR 과 별도로 논의하면 되는 사항으로 보여, 별도의 Issue를 열어 놓았습니다.

다음 이슈에 편하게 코멘트 남겨주시기 바랍니다, #36.

- These are related to generating data.
- Fill in empty tags in GenDataParam
- Display Data Mold Web UI URL when running
@yunkon-kim yunkon-kim merged commit 4fa0451 into cloud-barista:main Dec 5, 2023
2 checks passed
@yunkon-kim yunkon-kim deleted the add-Swagger branch December 19, 2023 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants