Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJV format support ? #89

Closed
olivierto opened this issue Aug 29, 2022 · 1 comment
Closed

AJV format support ? #89

olivierto opened this issue Aug 29, 2022 · 1 comment

Comments

@olivierto
Copy link

Hey there!
First of all Whow 馃く So great utility plugin ! really powerfull and easy to use! you are typescript ninjas !
Great job !

Here is my issue.
I'm using AJV format like this

import addFormat from 'ajv-formats'
import {FromSchema} from 'json-schema-to-ts';

export const validateParameters = (
  parametersData: any,
  schema: any
) => {
  const ajv = new Ajv({
    allErrors: true,
    removeAdditional: 'all',
    coerceTypes: true,
    unicodeRegExp: false,
  });
  addFormat(ajv);
  ...

Here is my schema code:

{
  type: 'object',
  properties: {
 supplierInvoiceFile: {
      type: 'object',
      properties: {
        type: {type: 'string'},
        filename: {type: 'string'},
        contentType: {type: 'string'},
        content: {type: 'binary', contentMediaType: 'application/pdf'},
      },
    },
}
}

and here is the calling code :

const body = parse(event, true) as FromSchema<typeof schema>;  //error 
/**
* Type '{ readonly type: "object"; readonly properties: { readonly isTest: { readonly type: "boolean"; readonly default: false; }; 
*  readonly supplierInvoiceFile: { readonly type: "object"; readonly properties: { readonly type: { readonly type: "string"; }; readonly 
*  filename: { ...; }; readonly contentType: { ...; }; readonly...' does not satisfy the constraint 'JSONSchema'.ts(2344)
**/

As soon as the property content is equal to "binary" it seems that the FromSchema is broken.

Is this a normal behavior as the support for binary type is not provided ? Or am I doing something wrong ?

Thanks for your answer !

@olivierto
Copy link
Author

Sorry for the timeloss...
I figured out by re reading the json schema docs
The proper syntax is :

supplierInvoiceFile: {
      type: 'object',
      properties: {
        type: {type: 'string'},
        filename: {type: 'string'},
        contentType: {type: 'string'},
        content: {type: 'string', contentEncoding:'binary', contentMediaType: 'application/pdf'},
      },
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant