Skip to content

Default is set to {} for UUID default value #89

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

Open
vhonchar opened this issue Apr 2, 2024 · 0 comments
Open

Default is set to {} for UUID default value #89

vhonchar opened this issue Apr 2, 2024 · 0 comments

Comments

@vhonchar
Copy link

vhonchar commented Apr 2, 2024

Steps

  • create a model like
const Model = sequelize.define('model', {
    someField: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
    },
});
  • generate OpenApi3Strategy schema for this model
const schemaManager = new JsonSchemaManager();
const schema = schemaManager.generate(Model, new OpenApi3Strategy(), {
    associations: false,
});

Actual model definition

{
  "title": "model",
  "type": "object",
  "properties": {
    "fileName": {
      "type": "string",
      "format": "uuid",
      "default": {
       }
    },
}

The issue is in the default value. UUID is a simple string with UUID format for swagger, and setting default to {} is creating confusion from user's perspective and messes with tools which are using swagger schema (e.g validation based on the schema).

Proposed model definition
Since UUID as default is a function, rather than a static value, a proposal is to omit default value at all

{
  "title": "model",
  "type": "object",
  "properties": {
    "fileName": {
      "type": "string",
      "format": "uuid",
    },
}

Workaround
Currently, I'm using jsonSchema on a field to create own definition for a field without default parameter

const Model = sequelize.define('model', {
    someField: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        jsonSchema: {
            schema: {
                type: 'string',
                format: 'uuid',
                default: undefined,
            },
        },
    },
});
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