辞書、HashMap、連想配列
辞書(マップ、HashMap、または連想配列とも呼ばれます)は、キーと値のペアのセットです。OpenAPIでは、キーが文字列である辞書を定義できます。辞書を定義するには、type: object
を使用し、additionalProperties
キーワードを使用してキーと値のペアの値を指定します。たとえば、次のような文字列-文字列辞書は
1{ "en": "English", "fr": "French" }
以下のスキーマを使用して定義されます
1type: object2additionalProperties:3 type: string
値の型
additionalProperties
キーワードは、辞書内の値の型を指定します。値はプリミティブ(文字列、数値、ブール値)、配列、またはオブジェクトにすることができます。たとえば、文字列-オブジェクト辞書は次のように定義できます
1type: object2additionalProperties:3 type: object4 properties:5 code:6 type: integer7 text:8 type: string
インラインスキーマを使用する代わりに、additionalProperties
は別のスキーマを$ref
できます
1components:2 schemas:3 Messages: # <---- dictionary4 type: object5 additionalProperties:6 $ref: "#/components/schemas/Message"7
8 Message:9 type: object10 properties:11 code:12 type: integer13 text:14 type: string
自由形式オブジェクト
辞書の値が任意の型(自由形式オブジェクトとも呼ばれます)である場合は、additionalProperties: true
を使用します
1type: object2additionalProperties: true
これは次と同等です
1type: object2additionalProperties: {}
固定キー
辞書にいくつかの固定キーがある場合、それらをオブジェクトプロパティとして明示的に定義し、必須としてマークすることができます
1type: object2properties:3 default:4 type: string5required:6 - default7additionalProperties:8 type: string
辞書の内容例
example
キーワードを使用して、辞書の内容のサンプルを指定できます
1type: object2additionalProperties:3 type: string4example:5 en: Hello!6 fr: Bonjour!
お探しのものが見つかりませんでしたか? コミュニティに質問する
間違いを見つけましたか? お知らせください