Skip to content

Generating OpenAPI enums from Model properties #2911

@jasonvasquez

Description

@jasonvasquez

Description

I have models in my application which have properties of various enum types, or arrays of enums. Is there a way in lb4 to generate OpenAPI enum types from those?

For instance:

enum Direction {
  North = "north",
  South = "south",
}

@model()
class Foo extends Model {
  ...
  @property.array(Direction, {required: true})
  directions: Direction[];
}

I would have hoped to be able to provide additional metadata to @property, along the lines of:

@property.array(Direction, {required: true, itemType: { enum: ["north", "south"]}})

For now, I've only had success describing them as numbers or strings. I've attempted to provide a Type<> object around these, but with no luck. If i'm understanding this comment correctly, it appears this may not be possible, but I would like to confirm: https://github.com/strongloop/loopback-next/blob/eeab36c352301d68a5f277907a072427d71a02b3/packages/repository-json-schema/src/build-schema.ts#L146-L147

If that's the case, are there plans to support types like this? In my specific case, I don't have need for any interpreted ORM behavior, as I'm not using the lb4 ORM in this scenario, simply describing API types for my application.

Current Behavior

Only primitives are generated for enums.

Expected Behavior

Enum types can be generated, given openapi metadata descriptions for possible values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions