Skip to content

openapiベースに変更(v3)#1221

Merged
kaitoyama merged 571 commits intomainfrom
fix/openapi
Apr 13, 2026
Merged

openapiベースに変更(v3)#1221
kaitoyama merged 571 commits intomainfrom
fix/openapi

Conversation

@kaitoyama
Copy link
Copy Markdown
Contributor

@kaitoyama kaitoyama commented May 5, 2024

Summary by CodeRabbit

  • 新機能

    • アンケートに匿名化・公開・重複回答防止オプションを追加
    • 管理者/ターゲットのグループ管理とグループ向けターゲティングを実装
    • 回答の下書き(is_draft)作成・編集と編集APIを追加
    • TraQ 関連の公開API(ユーザー/自分/グループ/スタンプ/チャンネル)を追加
    • 期限前に送るインプロセスのリマインダーを導入
  • 更新

    • OpenAPI 仕様と型定義を拡張してAPI表現を更新
    • README にて X-Forwarded-User ヘッダ利用の注意を追記

@kaitoyama kaitoyama self-assigned this May 5, 2024
@kaitoyama kaitoyama added the v3 label May 5, 2024
@ras0q
Copy link
Copy Markdown

ras0q commented May 5, 2024

共有: oapi-codegenのサーバー生成で使われるUUIDはgoogle/uuidだったはずなのでgofrs/uuidを使うときは注意する必要がありそうです
https://q.trap.jp/messages/1ef04e26-5a2d-4274-b706-547f0ed6aafb

@codecov
Copy link
Copy Markdown

codecov bot commented May 19, 2025

Codecov Report

❌ Patch coverage is 59.44351% with 962 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.81%. Comparing base (251a85c) to head (c7b8fba).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
controller/questionnaire.go 61.84% 254 Missing and 123 partials ⚠️
model/respondents_impl.go 15.88% 168 Missing and 12 partials ⚠️
controller/response.go 64.09% 56 Missing and 23 partials ⚠️
controller/adapter.go 80.99% 37 Missing and 32 partials ⚠️
model/questionnaires_impl.go 62.23% 41 Missing and 13 partials ⚠️
model/reminder_targets.go 0.00% 53 Missing ⚠️
controller/reminder.go 64.08% 47 Missing and 4 partials ⚠️
controller/middleware.go 57.57% 21 Missing and 7 partials ⚠️
model/db.go 39.39% 10 Missing and 10 partials ⚠️
controller/utils.go 55.88% 13 Missing and 2 partials ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1221      +/-   ##
==========================================
- Coverage   63.88%   63.81%   -0.07%     
==========================================
  Files          27       26       -1     
  Lines        4004     4024      +20     
==========================================
+ Hits         2558     2568      +10     
- Misses       1062     1070       +8     
- Partials      384      386       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Eraxyso and others added 15 commits July 29, 2025 08:11
…reInfo to follow the order of their top response under the current sort parameter
一時保存されたアンケートのバリデーションを緩める
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
選択式問題の答えを、controller層で選択肢番号から内容に変換
…tools_update

oapi-codegenのファイルをgo generateで自動生成可能に&tools.goからgo get -toolへの移行
@Eraxyso Eraxyso marked this pull request as ready for review December 4, 2025 11:18
@Eraxyso Eraxyso requested a review from Copilot December 11, 2025 07:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR represents a major architectural shift from a custom router implementation to an OpenAPI-based approach. The changes involve removing the existing router handlers and test files while introducing auto-generated OpenAPI types and specifications. Several model files have been updated to support the new architecture, with adjustments to function signatures and interface definitions.

Reviewed changes

Copilot reviewed 79 out of 91 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
router/results.go Removed entire file containing result handler implementation
router/responses_test.go Removed comprehensive test suite for response handlers
router/responses.go Removed response-related HTTP handlers and validation logic
router/questions_test.go Removed extensive test coverage for question validation and handling
router/questions.go Removed question editing and deletion handlers
router/questionnaires_test.go Removed detailed test suite for questionnaire operations
router/questionnaires.go Removed all questionnaire CRUD handlers and helper functions
router/api_test.go Removed test utilities and helper functions
router/api.go Removed API struct and constructor
router.go Removed main routing configuration
openapi/types.go Added auto-generated OpenAPI type definitions (1846 lines)
openapi/spec.go Added auto-generated OpenAPI specification loader
openapi/generate.go Added code generation directives for OpenAPI
model/validations_test.go Updated function calls to match new signature with additional parameters
model/validations_impl.go Refactored variable declarations for better code quality
model/transaction_mock.go Updated mock to remove unused sql.TxOptions parameter
model/transaction.go Added mockgen directive for code generation
model/targets.go Extended interface with three new methods for targeting functionality
.spectral.yaml Added OpenAPI linting configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread model/validations_impl.go
Comment on lines 155 to +157
if MinBound != "" {
min, err := strconv.ParseFloat(MinBound, 64)
minBoundNum = min
minBoundNum, err = strconv.ParseFloat(MinBound, 64)
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

The variable err is declared once and reused for both MinBound and MaxBound parsing. While this works, if the first parsing succeeds and the second fails, the error handling at line 164 may be confusing since the variable name doesn't indicate which bound failed. Consider using distinct variable names or scoping the err variable to each if block for clarity.

Copilot uses AI. Check for mistakes.
Comment thread model/transaction_mock.go
type MockTransaction struct{}

func (m *MockTransaction) Do(ctx context.Context, txOption *sql.TxOptions, f func(ctx context.Context) error) error {
func (m *MockTransaction) Do(ctx context.Context, f func(ctx context.Context) error) error {
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

The removal of the txOption *sql.TxOptions parameter is a breaking change to the ITransaction interface. Ensure that all implementations of this interface have been updated accordingly, and that any code calling this method has been adjusted to match the new signature.

Copilot uses AI. Check for mistakes.
kaitoyama and others added 26 commits April 9, 2026 17:07
When PostMessage was called inside the DB transaction, a failure on the
second or later chunk would roll back the transaction, but any previously
sent chunks already contained a link to a questionnaire that no longer
exists.

By calling PostMessage after the transaction commits, the linked
questionnaire is guaranteed to exist. Send failures are only logged;
the questionnaire creation itself is still treated as successful.

https://claude.ai/code/session_01CgXuuWWwhkMr1fXAR9LGgw
…ai2Y

feat: 対象者が多い場合のtraQメッセージ分割処理
Add an optional isPublished query parameter to GET /questionnaires that
filters questionnaires by their is_published field:
- true: return only published questionnaires
- false: return only unpublished questionnaires
- omitted: return all questionnaires regardless of published state

This replaces the previous hardcoded filter that always restricted results
to published questionnaires only.

https://claude.ai/code/session_015TFFD6ovua8GnmjqbiZtDh
When isPublished is false, additionally require the user to be an
administrator of the questionnaire via EXISTS subquery on the
administrators table. This prevents non-admin users from discovering
unpublished questionnaires.

When isPublished is omitted (nil), restore the previous safe default of
only returning published questionnaires (is_published IS TRUE), reverting
the unintentional security regression from the initial implementation.

Behavior summary:
- isPublished omitted: published only (safe default, same as before)
- isPublished=true: published only
- isPublished=false: unpublished AND user is questionnaire admin

https://claude.ai/code/session_015TFFD6ovua8GnmjqbiZtDh
… questionnaires

Rename the questionnaire filter parameter from isPublished to isDraft to be
consistent with the response-level isDraft convention:
- isDraft=true: show only unpublished (draft) questionnaires
- isDraft=false: show only published questionnaires
- omitted: show only published questionnaires (safe default)

Enforce that isDraft=true implicitly sets onlyAdministratedByMe=true in the
controller, ensuring non-admin users cannot discover unpublished questionnaires.

Also verified that GET /questionnaires/:questionnaireID is already protected:
QuestionnaireReadAuthenticate middleware returns 403 when the questionnaire is
not published and the user is neither a system admin nor a questionnaire admin.

https://claude.ai/code/session_015TFFD6ovua8GnmjqbiZtDh
When isDraft is omitted, show both published questionnaires and unpublished
questionnaires that the user administrates, consistent with the API convention
that omitting a filter means no restriction.

Previously, omitting isDraft incorrectly defaulted to published-only (same as
isDraft=false). Now:
- isDraft omitted: published questionnaires OR drafts the user administrates
- isDraft=true: draft (unpublished) questionnaires only (admin-restricted)
- isDraft=false: published questionnaires only

Update swagger and types.go comments to reflect the corrected behavior.

https://claude.ai/code/session_015TFFD6ovua8GnmjqbiZtDh
…lished-filter-qF4nP

Add isDraft filter to GET /questionnaires endpoint
DeleteResponse was calling DeleteRespondent and DeleteResponse without
a transaction, which could leave data in an inconsistent state if one
operation succeeded and the other failed. Wrap both calls in
ITransaction.Do() to ensure atomicity.

Fixes #1520

https://claude.ai/code/session_01VaoSLHjZqHPryFAE1pF15y
…esponse processing

- Add nil checks for MinLabel/MaxLabel in EditQuestionnaire before
  dereferencing pointers (was already done in PostQuestionnaire)
- Add bounds check for ScaleLabels slice before accessing index 0
  in convertQuestions to prevent index out of range panic
- Return HTTP 500 when scale label is missing from map during
  response validation instead of silently using zero-value bounds
  (ScaleMin=0, ScaleMax=0) which would incorrectly reject valid answers
- Pass a proper error message to echo.NewHTTPError when questionnaire
  deadline has passed, instead of nil err
…port-Ik4nN

fix: scale label nil dereference, out of bounds panic, and error handling bugs
…-remindertargets

fix: move migration of new table ReminderTargets to v3
Wrap response deletion in transaction for data consistency
@kaitoyama
Copy link
Copy Markdown
Contributor Author

それぞれについてレビューしていたので問題なしとする

@kaitoyama kaitoyama merged commit 1455898 into main Apr 13, 2026
14 of 15 checks passed
@kaitoyama kaitoyama deleted the fix/openapi branch April 13, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetResponseの実装 DeleteResponseの実装 GetMyResponsesの実装 GetQuestionnaireResultの実装 PostQuestionnaireResponseの実装

6 participants