Skip to content

Add xp schema command#4

Merged
buty4649 merged 5 commits intomainfrom
add-schema-command
Apr 17, 2026
Merged

Add xp schema command#4
buty4649 merged 5 commits intomainfrom
add-schema-command

Conversation

@buty4649
Copy link
Copy Markdown
Contributor

Summary

  • xp schema <service.resource.method> で X-point API の OpenAPI オペレーション定義を出力
  • 既存コマンドに対応する3つのエイリアスを用意:
    • form.listGET /api/v1/forms
    • approval.listGET /api/v1/approvals
    • document.searchPOST /api/v1/search/documents
  • OpenAPI 3.0.3 の spec (`internal/xpoint/openapi.yaml`) を `go:embed` でバイナリに埋め込み
  • `--resolve-refs` でローカル `$ref` をインライン展開、`--jq` で gojq フィルタ適用可
  • 引数なしで実行するとエイリアス一覧を表示

使用例

```console
$ xp schema
Supported aliases:
approval.list
document.search
form.list

$ xp schema form.list --jq '{summary, _method, _path}'
{
"_method": "GET",
"_path": "/api/v1/forms",
"summary": "利用可能フォーム一覧取得"
}

$ xp schema form.list --resolve-refs

$ref がすべて展開された JSON

```

Test plan

  • `go test ./...` が通る
  • `golangci-lint run ./...` が通る (0 issues)
  • 3エイリアスそれぞれで出力を確認
  • `--resolve-refs` で `$ref` が展開されることを確認
  • 未知のエイリアスはエラー

🤖 Generated with Claude Code

@buty4649 buty4649 self-assigned this Apr 17, 2026
buty4649 and others added 2 commits April 17, 2026 13:05
Print the OpenAPI operation object for an X-point endpoint, mirroring
`gws schema`. The X-point OpenAPI 3.0.3 spec is embedded in the binary
via go:embed. Supported aliases map to the CLI's existing commands:

  form.list         GET  /api/v1/forms
  approval.list     GET  /api/v1/approvals
  document.search   POST /api/v1/search/documents

Flags:
  --resolve-refs   inline local $ref pointers into the output
  --jq             apply a gojq filter to the schema

Running `xp schema` without arguments lists the supported aliases.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The upstream X-point OpenAPI spec has schema/example inconsistencies
(notably `form[].id` typed as string while the API actually returns
integer). Since the API response is the source of truth, drop the
embedded openapi.yaml in favor of a hand-maintained schema.yaml that
covers only the operations this CLI supports and reflects the real
response shapes.

- Remove internal/xpoint/openapi.yaml (~9.5k lines)
- Add internal/xpoint/schema.yaml describing form.list /
  approval.list / document.search with correct types
- Simplify schema.go: drop $ref resolution, just lookup by alias
- Drop --resolve-refs flag (no refs to resolve anymore)
- Update tests and output field names (method/path instead of
  _method/_path)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@buty4649 buty4649 force-pushed the add-schema-command branch from ec2a6a7 to f98d517 Compare April 17, 2026 04:06
buty4649 and others added 3 commits April 17, 2026 13:07
jq-style filtering belongs on runtime API responses where users
care about trimming payloads, not on the static schema output.
If users want to grep parts of the schema, piping through jq
externally is simpler.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Embed schema.json instead of schema.yaml so we can use encoding/json
from the stdlib and drop the gopkg.in/yaml.v3 dependency (and its
map[any]any -> map[string]any normalizer).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Each operation now lives in its own file (form.list.json,
approval.list.json, document.search.json) inside the new
internal/schema package. Adding or editing an endpoint no longer
requires touching a monolithic schema.json.

The loader uses embed.FS with `//go:embed *.json` and derives the
alias name from the filename (minus the .json suffix), so new
operations can be added just by dropping a JSON file.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@buty4649 buty4649 merged commit ff00706 into main Apr 17, 2026
2 checks passed
@buty4649 buty4649 deleted the add-schema-command branch April 17, 2026 04:10
This was referenced Apr 17, 2026
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.

1 participant