typeconv icon indicating copy to clipboard operation
typeconv copied to clipboard

JSON schema keywords getting lost

Open Schereo opened this issue 4 years ago • 0 comments

I'm trying to convert JSON schema to Open Api. During the conversion keywords like minLenght, maxLength and format are getting lost and are not present in my final Open Api conversion. Here is my testcode:

const test = {
    "type": "object",
    "properties": {
        "name": { "minLength": 5, "maxLength": 10, "type": "string" },
        "creationDate": { "format": "date-time", "type": "string" }
    },
    "required": ["name", "creationDate"]
}

const schemas = {
    "definitions": {
        "testType": test
    }
};


const converter = async () => {
    const reader = getJsonSchemaReader();
    const writer = getOpenApiWriter({ format: 'yaml', title: 'Testconverter', version: 'v1', schemaVersion: '3.0.0' });
    const { convert } = makeConverter(reader, writer);
    await convert({ 'data': JSON.stringify(schemas) }, { filename: 'test.yaml' })
}

converter()

which produces this open api yaml:

openapi: 3.0.0
info:
  title: Testconverter
  version: v1
paths: {}
$id: test.yaml
$comment: >-
  Generated by core-types-json-schema
  (https://github.com/grantila/core-types-json-schema) on behalf of typeconv
  (https://github.com/grantila/typeconv)
components:
  schemas:
    testType:
      properties:
        name:
          type: string
        creationDate:
          type: string
      required:
        - name
        - creationDate
      type: object

which is missing the previous mentioned keyword. The correct (shortend) schme should look like this:

testType:
      properties:
        name:
          type: string
          minLength: 5
          maxLength: 10
        creationDate:
          type: string
          format: date-time
      required:
        - name
        - creationDate
      type: object

Schereo avatar Jul 05 '21 07:07 Schereo