Skip to content

"required": true for a property. Does the codgen support it? #322

@TemRhythm

Description

@TemRhythm

I have a Schema Object

{
  "Obj": {
    "description": "Obj",
    "required": [
      "id",
      "foo"
    ],
    "properties": {
      "id": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      },
      "foo": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      },
      "bar": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      }
    }
  }
}

With this ShemaObject, a type generates perfectly fine.

/**
 * Obj
 */
export type Obj = {
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  id: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  foo: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  bar?: string;
};

But if I move/distribute required to properties like this

{
  "Obj": {
    "description": "Obj",
    "properties": {
      "id": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$",
        "required": true
      },
      "foo": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$",
        "required": true
      },
      "bar": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      }
    }
  }
}

It generates this:

/**
 * Obj
 */
export type Obj = {
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  id?: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  foo?: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  bar?: string;
};

Conclusion:
It ignores this approach of requiring fields if the required is set at the property level. Is it a bug? Is it possible to set up this approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions