本文へスキップ
Skillpedia
APIとサーバー(バックエンド)8.1k · #12598

webiny-api-cms-content-models

できること

このスキルは、Webinyプロジェクトで、コードを通じてCMSのコンテンツモデルを作成または変更するとき、AIを導きます。データ構造をバージョン管理されたコードで定義したい開発者向けです。

使う場面

  • ✓製品やブログ記事などのコンテンツモデルを、コードで作成したいとき。
  • ✓フィールドに検証や他のモデルへの参照が必要なとき。
  • ✓フィールドの種類に合った管理画面の表示を選ぶ必要があるとき。

スキルのリンク

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/content-models/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/webiny/webiny-js/blob/next/skills/user-skills/content-models/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“名前、価格、カテゴリーモデルへの参照を持つ、製品のコンテンツモデルをコードで作ってください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

スキルは、流れるようなビルダーを使ってフィールド、レイアウト、タイトルのフィールド、APIの名前を宣言するモデルのクラスを示します。モデルは、プロジェクトの設定ファイルに登録されます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Creating Content Models via Code

TL;DR

Content models are created using the ModelFactory pattern. You define a class implementing ModelFactory.Interface, use the fluent ModelFactory.Builder API to declare fields, validators, layout, and API names, then export with ModelFactory.createImplementation(). Register in webiny.config.tsx as <Api.Extension>.

The ModelFactory Pattern

Every code-based content model follows the same structure:

import { ModelFactory } from "webiny/api/cms/model";

class MyModelImpl implements ModelFactory.Interface {
  async execute(builder: ModelFactory.Builder) {
    return [
      builder
        .public({ modelId: "myModel", name: "My Model", group: "ungrouped" })
        .description("Description of the model")
        .fields(fields => ({
          // field definitions here
        }))
        .layout([/* row definitions */])
        .titleFieldId("fieldId")
        .singularApiName("MyModel")
        .pluralApiName("MyModels")
    ];
  }
}

export default ModelFactory.createImplementation({
  implementation: MyModelImpl,
  dependencies: []
});

Register in webiny.config.tsx:

<Api.Extension src={"/extensions/MyModel.ts"} />

YOU MUST include the full file path with the .ts extension in the src prop. For example, use src={"/extensions/MyModel.ts"}, NOT src={"/extensions/MyModel"}. Omitting the file extension will cause a build failure.

YOU MUST use export default for the createImplementation() call when the file is targeted directly by an Extension src prop. Using a named export (export const MyModel = ...) will cause a build failure. Named exports are only valid inside files registered via createFeature.

Model Configuration Methods

Method Purpose
.public({ modelId, name, group }) Creates a public model (accessible via Read API). modelId is the internal DB identifier. group organizes it in the Admin sidebar.
.description("...") Model description shown in Admin UI
.fields(fields => ({ ... })) Define all fields using the fluent field builder
.layout([["field1", "field2"], ["field3"]]) Arrange fields in rows in the Admin editor. Each inner array is one row.
.titleFieldId("name") Which field to use as the entry's display title
.descriptionFieldId("message") Which field to use as the entry's description
.singularApiName("Product") Singular name for GraphQL queries (e.g., getProduct)
.pluralApiName("Products") Plural name for GraphQL queries (e.g., listProducts)
.singleEntry() Makes the model a singleton (only one entry can exist). Automatically adds
よくある質問

モデルはどのように登録されますか?

webiny設定ファイルのAPI拡張として、.tsの拡張子を含む完全なファイルパスを使って登録されます。

フィールドは入れ子にできますか?

はい。スキルは、objectとdynamic zoneのフィールドの中の、入れ子のレイアウトを扱います。

フィールドの表示の種類の選択も扱いますか?

はい。フィールドの種類ごとに、どの管理画面の表示を使うかを説明します。

詳細

作者による元の説明

Creating Headless CMS content models via code using the ModelFactory pattern. Use this skill when the developer wants to create, modify, or understand content model definitions, define fields and validators, set up reference fields between models, configure field layouts (including nested layouts inside object or dynamicZone fields), pick the correct Admin UI renderer for a field type (textInput/textInputs, lexicalEditor/lexicalEditors, file/files, objectAccordionSingle/objectAccordionMultiple, etc.), or work with the ModelFactory builder API. Also covers field types (text, longText, number, b

repo: webiny/webiny-js

人気

GitHubのスター
8.1k
ランキング
#12598
ライセンス
—
更新日
2026/11/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル