[]
        
(Showing Draft Content)

SpreadJS에서의 JSON 스키마

공개 스키마는 SpreadJS의 JSON 데이터 형식을 설명하며, SpreadJS JSON 데이터를 사람과 기계가 읽기 쉬운 문서 형식으로 명확하게 만들고, 코드 기반 생성, 자동 테스트 및 JSON 데이터의 유효성 검사에 유용한 구조적 검증을 제공합니다. 현재 및 전체 스키마 목록은 SpreadJS 스프레드 스키마 문서를 참조하세요.

JSON Schema에 대한 자세한 내용은 json-schema.org 웹사이트를 참고하시기 바랍니다. JSON Schema 문서는 JSON 데이터의 유효성을 검사하는 데 사용할 수 있으며, JSON Schema를 기반으로 유효한 JSON 데이터를 생성할 수도 있습니다.

다음은 JSON Schema의 기본 예제입니다:

{
    "title": "LineBorder",
        "description": "Indicates the color of the border line. Use a known color name or HEX style color value. The default value is black.",
            "type": "object",
                "properties": {
        "color": {
            "type": "string",
                "default": "black"
        },
        "style": {
            "$ref": "#/definitions/LineStyle",
                "default": 0
        }
    }
}

테마를 사용하여 유효성 검사기를 만드는 방법에 대한 자세한 내용은 JSON Schema페이지를 참조하시기 바랍니다.

SpreadJS JSON 데이터를 유효성 검사하려면 SpreadJS JSON Schema 문서를 사용할 수 있습니다.

다음은 json-schema-validator를 사용해 SpreadJS JSON 데이터를 검증하는 단계입니다.

  1. 데이터의 일부를 유효성 검사하기

    • 예를 들어, "NameInfo"라는 JSON 데이터 두 개가 있다고 가정하고, 두 데이터가 유효한지 확인하고자 합니다.

      {
          "name":"name1",
          "row":4,
          "column":3,
          "formula":"=SUM(A1,A3)"
      }
      {
      "name":"name1",
          "row":"4",
          "column":3,
          "formula":"=SUM(A1,A3)"
      }

      아래는 "NameInfo"에 대한 JSON Schema입니다:

      {
            "title": "NameInfo",
            "description": "Represents a custom named expression that can be used by formulas.",
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "row": {
                "type": "integer",
                "minimum": 0
              },
              "col": {
                "type": "integer",
                "minimum": 0
              },
              "formula": {
                "type": "string"
              },
              "comment": {
                "type": "string"
              }
            }
          }

      이 JSON Schema로 JSON 데이터를 유효성 검사한 결과, 두 번째 JSON 데이터(jsonData2)는 유효하지 않습니다. 그 이유는 "row" 속성의 값이 "string" 타입이지만, "integer" 타입이어야 하기 때문입니다.

    • JSON 스키마가 다른 JSON 스키마를 참조하는 경우.

      예를 들어 아래의 JSON Schema는 "LineStyle"이라는 다른 JSON 스키마를 참조하고 있습니다.

      {
          "title" : "LineBorder",
          "description" : "Indicates the color of the border line. Use a known color name or HEX style color value. The default value is black.",
          "type" : "object",
          "properties" : {
              "color" : {
                  "type" : "string",
                  "default" : "black"
              },
              "style" : {
                  "$ref" : "#/definitions/LineStyle",
                  "default" : "LineStyle.empty"
              }
          }
      }

      만약 "LineBorder" JSON 데이터를 유효성 검사하려면, 아래와 같이 "LineStyle"까지 정의한 완전한 LineBorder JSON Schema가 필요합니다.

       {
          "title" : "LineBorder",
          "description" : "Indicates the color of the border line. Use a known color name or HEX style color value. The default value is black.",
          "type" : "object",
          "properties" : {
              "color" : {
                  "type" : "string",
                  "default" : "black"
              },
              "style" : {
                  "$ref" : "#/definitions/LineStyle",
                  "default" : "LineStyle.empty"
              }
          },
          "definitions":{
              "LineStyle":{
                 "title":"LineStyle",
                 "description":"Specifies the line drawing style for the border. empty:0,thin:1,medium:2,dashed:3,dotted:4,thick:5,double:6,hair:7,mediumDashed:8,dashDot:9,mediumDashDot:10,dashDotDot:11,mediumDashDotDot:12,slantedDashDot:13.",
                 "enum":[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
              }
          }
      }
  2. 전체 SpreadJS JSON 데이터 유효성 검사

    SpreadJS 전체 JSON 데이터를 유효성 검사하려면, 위와 같이 참조 스키마가 모두 포함된 전체 버전 JSON Schema를 사용하면 됩니다.