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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing default value in avro scheam #465

Closed
sahellebusch opened this issue Aug 27, 2024 · 2 comments
Closed

Missing default value in avro scheam #465

sahellebusch opened this issue Aug 27, 2024 · 2 comments

Comments

@sahellebusch
Copy link

I expect the following code to print the schema w/ a default value per the avro spec.

const userAvroSchema = Type.forSchema({
  type: 'record',
  name: 'User',
  fields: [
    { name: 'id', type: 'int' },
    { name: 'name', type: 'string' },
    { name: 'email', type: 'string' },
    { name: 'newValue', type: 'string', default: 'somevalue' },
    {
      name: 'registeredAt',
      type: { type: 'long', logicalType: 'timestamp-millis' },
    },
  ],
});

console.log(JSON.stringify(userAvroSchema.schema()));

Prints:

{"name":"User","type":"record","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"email","type":"string"},{"name":"newValue","type":"string"},{"name":"registeredAt","type":"long"}]}

Is this something I'm doing wrong or is this a bug in the library?

@jonashellstrom
Copy link

Passing {exportAttrs: true} will include the defaults.
Found a reference to it here: https://github.com/mtth/avsc/blob/master/etc/scripts/infer#L72

@mtth
Copy link
Owner

mtth commented Sep 8, 2024

schema without any arguments returns the type's canonical schema, which doesn't include defaults.

@mtth mtth closed this as completed Sep 8, 2024
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

3 participants