Skip to content

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

Open
@vhonchar

Description

@vhonchar

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,
            },
        },
    },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions