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

Support descriptions for docs on object fields of a model #200

Closed
Tracked by #142
minox86 opened this issue Dec 11, 2023 · 1 comment
Closed
Tracked by #142

Support descriptions for docs on object fields of a model #200

minox86 opened this issue Dec 11, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@minox86
Copy link
Contributor

minox86 commented Dec 11, 2023

We need a way to specify a description of every field of an object in order to enrich its formal specifications (OpenAPI, GraphQL, etc.).

We can already do it for primitive types as following:

const User = () => model.entity({
   id: model.string({ description: "The ID must be a valid GUID." }),
})

but we can't do it for referenced types:

const User = model.entity({ ... })
const Post = () => model.entity({
      author: User, // ???
 })

A suggested syntax to keep the locality of the description to the field and considering technical concerns is the following:

const User = model.entity({ ... })
const Post = () => model.entity({
      author: model.asField(User, { description: "The user who wrote the post." }),
 })
@minox86 minox86 added the enhancement New feature or request label Dec 11, 2023
@edobrb edobrb mentioned this issue Dec 27, 2023
20 tasks
@edobrb
Copy link
Member

edobrb commented Jan 2, 2024

Final syntax:

export const User = () =>
  model.entity(
    {
      id: idType,
      firstName: model.string(),
      lastName: model.string(),
      email: model.email(),
      posts: model.array(Post),
      givenLikes: model.array(Like),
      followers: model.describe(model.array(User), 'Users that follows me'),
      followeds: model.describe(model.array(User), 'Users followed by me'),
      registeredAt: model.datetime(),
      loginAt: model.datetime(),
    },
    { description: 'User of the system' },
  )

@edobrb edobrb closed this as completed in 87cc019 Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants