oneOf, anyOf, allOf๋ ๋ณตํฉ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋ ๋ฐ ์ฌ์ฉ๋๋ JSON Schema ์ฌ์์ ํค์๋์
๋๋ค. ๋ณธ์ง์ ์ผ๋ก ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ์ ์ ์ฉ๋๋ ๋
ผ๋ฆฌ ์ฐ์ฐ์์
๋๋ค. Apidog๋ ์ด๋ฌํ JSON Schema ๊ธฐ๋ฅ์ ์๋ฒฝํ๊ฒ ์ง์ํ์ฌ ๋ ์ ํํ API ๋ฌธ์์ ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ ๊ท์น์ ๊ตฌ์ถํ ์ ์๋๋ก ๋์๋๋ฆฝ๋๋ค.| ํค์๋ | ๋ ผ๋ฆฌ ์ฐ์ฐ | ์กฐ๊ฑด ์๊ตฌ ์ฌํญ | ์ผ๋ฐ์ ์ธ ์ฌ์ฉ ์ฌ๋ก |
|---|---|---|---|
allOf | AND | ๋ชจ๋ ์กฐ๊ฑด์ ๋์์ ์ถฉ์กฑํด์ผ ํจ | ์์, ํ์ฅ |
anyOf | OR | ํ๋ ์ด์์ ์กฐ๊ฑด์ ์ถฉ์กฑํด์ผ ํจ | ์ ํ์ ์กฐํฉ |
oneOf | XOR | ์ ํํ ํ๋์ ์กฐ๊ฑด๋ง ์ถฉ์กฑํด์ผ ํจ | ์ํธ ๋ฐฐํ์ ์ ํ |
oneOf, anyOf ๋๋ allOf๋ฅผ ์ ํํฉ๋๋ค. ๊ฐ ํ์ ์คํค๋ง์ ๋ํ ๊ตฌ์ฒด์ ์ธ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ฅผ ์ ์ํฉ๋๋ค.allOf๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ ๋ฐ์ดํฐ ์คํค๋ง๋ฅผ ํจ๊ป ๊ฒฐํฉํ์ฌ ๋ฐ์ดํฐ๊ฐ ๋ชจ๋ ์กฐ๊ฑด์ ๋์์ ์ถฉ์กฑํ๋๋ก ์๊ตฌํ ์ ์์ต๋๋ค. ์ด๋ "์ฌ์ฉ์ ์ ๋ณด์๋ ๊ธฐ๋ณธ ์ ๋ณด๊ฐ ํฌํจ๋์ด์ผ ํจ AND ์ฐ๋ฝ์ฒ ์ ๋ณด๊ฐ ํฌํจ๋์ด์ผ ํจ"์ด๋ผ๊ณ ๋งํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.{
"allOf": [
{
"description": "Basic user information",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
},
"required": ["id", "name"]
},
{
"description": "Contact information",
"type": "object",
"properties": {
"email": { "type": "string", "format": "email" },
"phone": { "type": "string" }
},
"required": ["email"]
}
]
}anyOf๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ ์ ํ์ ์ ํจ์ฑ ๊ฒ์ฌ ๊ฒฝ๋ก๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค. ์ฌ์ฉ์๋ ํ๋ ๋๋ ์ฌ๋ฌ ๋ฐฉ๋ฒ์ ์ ํํ ์ ์์ต๋๋ค. ์ด๋ "์ฌ์ฉ์๋ ์ฌ์ฉ์ ์ด๋ฆ/๋น๋ฐ๋ฒํธ๋ก ๋ก๊ทธ์ธํ ์ ์์ OR ์ด๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ก ๋ก๊ทธ์ธํ ์ ์์ OR ์ ํ๋ฒํธ/์ธ์ฆ ์ฝ๋๋ก ๋ก๊ทธ์ธํ ์ ์์"์ด๋ผ๊ณ ๋งํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.{
"type": "object",
"properties": {
"login": {
"anyOf": [
{
"description": "Username/password login",
"properties": {
"username": { "type": "string" },
"password": { "type": "string" }
},
"required": ["username", "password"]
},
{
"description": "Email/password login",
"properties": {
"email": { "type": "string", "format": "email" },
"password": { "type": "string" }
},
"required": ["email", "password"]
},
{
"description": "Phone/verification code login",
"properties": {
"phone": { "type": "string" },
"verifyCode": { "type": "string" }
},
"required": ["phone", "verifyCode"]
}
]
}
}
}oneOf๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ์ฉ์๊ฐ ๊ฒฐ์ ๋ฐฉ๋ฒ์ ํ๋๋ง ์ ํํ ์ ์์ผ๋ฉฐ ์ฌ๋ฌ ๋ฐฉ๋ฒ์ ๋์์ ์ ๊ณตํ ์ ์๋๋ก ๋ณด์ฅํ ์ ์์ต๋๋ค. ์ด๋ "๊ฒฐ์ ๋ฐฉ๋ฒ์ ์ ์ฉ์นด๋์ฌ์ผ ํจ XOR PayPal XOR ์ํ ์ก๊ธ - ์ด ์ต์
์ค ์ ํํ ํ๋"๋ผ๊ณ ๋งํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.{
"type": "object",
"properties": {
"payment": {
"oneOf": [
{
"description": "Credit card payment",
"type": "object",
"properties": {
"type": { "const": "credit_card" },
"cardNumber": { "type": "string" },
"expiryDate": { "type": "string" }
},
"required": ["type", "cardNumber", "expiryDate"],
"additionalProperties": false
},
{
"description": "PayPal payment",
"type": "object",
"properties": {
"type": { "const": "paypal" },
"email": { "type": "string", "format": "email" }
},
"required": ["type", "email"],
"additionalProperties": false
},
{
"description": "Bank transfer",
"type": "object",
"properties": {
"type": { "const": "bank_transfer" },
"accountNumber": { "type": "string" },
"routingNumber": { "type": "string" }
},
"required": ["type", "accountNumber", "routingNumber"],
"additionalProperties": false
}
]
}
}
}allOf ์ฌ์ฉ(AND ์ฐ์ฐ)anyOf ์ฌ์ฉ(OR ์ฐ์ฐ)oneOf ์ฌ์ฉ(XOR ์ฐ์ฐ)