버전 관리 JSON Schema

7121 단어 JSONjsonschematech
JSON Schema에 대한 버전 관리를 하고 싶은 일이 있어 미리 필기를 해뒀다.

이미지 사용


1행은 schemaVersion을 쓰고 발리 모드의 버전을 전환합니다.
나는 파리에 가고 싶다.yml
schemaVersion: 1.0.1
hogehoge: fugafuga
...以下略

디렉토리 구조


root
├── meta.yml
└── schemas
    ├── v1.0.0
    │   └── config.yml
    ├── v1.0.1
    │   └── config.yml
    └── v1.1.0
        └── config.yml
의 인상.

meta.yml


모든 버전의 schema를 이 파일에 결합합니다. (이것은prmd로 표시된 원본 파일입니다.)
meta.yml
---
$schema: http://json-schema.org/draft-07/schema#
title: meta schema
description: バージョン管理するためのスキーマの枠
id: meta
allOf:
  - if:
      properties:
        schemaVersion:
          const: 1.0.0
    then:
      allOf:
        - $ref: "#/definitions/v1.0.0"
  - if:
      properties:
        schemaVersion:
          const: 1.0.1
    then:
      allOf:
        - $ref: "#/definitions/v1.0.1"
  - if:
      properties:
        schemaVersion:
          const: 1.1.0
    then:
      allOf:
        - $ref: "#/definitions/v1.1.0"
required:
  - schemaVersion
properties:
  schemaVersion:
    type: string
    enum:
      - 1.0.0
      - 1.0.1
      - 1.1.0
    description: スキーマのバージョン

allOf 등을 사용하여 결합 후 버전을 지정할 때 이 버전의 모델을 강제한다.
또한 버전 번호1.0 등으로 사용하면 부동 소수점 수치로 간주되기 때문에 "1.0"로 기록해야 한다.

config.yml


위에 있는 meta.yml에 연결합니다.
파일 이름은 용도에 맞게 하십시오.아무거나 괜찮아요.
v1.0.0/config.yml
id: v1.0.0
title: ...
definitions:
  foo: ...
  bar:
    type: object
    properties:
      foo:
        $ref: "#/v1.0.0/definitions/foo" # バージョンをベタ書きする必要がある。改良したい
required: ...
additionalProperties: false
type: object
properties:
  schemaVersion: # ここでも定義しないとエラーが出る。JSON Schemaの限界
    type: string
  ...

생성 명령


JSON Schema 결합 등에 쓰이는gem, prmd(Rubby 필요).더 나은 CLI를 개발할 수 있습니다.
prmd combine -m meta.yml schemas/ -o combined.json
이로써 combined.json에서 버전을 관리할 수 있는 JSON Schema를 결합하여 생성한다.

좋은 웹페이지 즐겨찾기