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

docs: add descriptions and examples to tag schemas #4194

Merged
merged 7 commits into from
Jul 11, 2023

Conversation

gastonfournier
Copy link
Contributor

@gastonfournier gastonfournier commented Jul 10, 2023

About the changes

  • Adding descriptions and examples to tag and tag types schemas
  • Adding standard errors, summaries, and descriptions to tag and tag types endpoints
  • Some improvements on compilation errors

@vercel
Copy link

vercel bot commented Jul 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Jul 10, 2023 1:45pm
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Jul 10, 2023 1:45pm

@@ -68,9 +68,11 @@ export default class TagTypeService {
return Promise.resolve(true);
}

async validate(tagType: ITagType): Promise<void> {
async validate(tagType: Partial<ITagType> | undefined): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solving a compilation problem

@@ -58,7 +58,7 @@ export default class TagTypeService {
return data;
}

async validateUnique({ name }: Pick<ITagType, 'name'>): Promise<boolean> {
async validateUnique(name: string): Promise<boolean> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves a compilation problem

Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Most comments are non-blocking suggestions, but I have a few questions I'd like to get an answer to before accepting the change.

},
icon: {
type: 'string',
nullable: true,
description: 'The icon of the tag type.',
example: 'not-really-used',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is a little confusing. Are you saying we don't use the icons provided? If they provide icons, what format should it be in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're definitely not using them in the admin UI

https://sandbox.getunleash.io/enterprise/tag-types/create
image

https://sandbox.getunleash.io/enterprise/tag-types/edit/group
image

But icons do exist in our database and in our API. So I think this could be just an idea that never got implemented.

Maybe @chriswk who worked on this 2 years ago might remember something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Gaston said, it was meant to be an extra feature so you could paste an URL to a valid icon, so that :slack: / :jira: had a more obvious illustration than just the first letter of the type capitalised.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it ever got prioritised.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Do we have a format for that in any way?

Based on that, I'd definitely put that in the description and maybe even deprecate the properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it can be anything, it will depend on what we want to do when we finally implement this. It's like predicting the future... we can tell customers to write it as a full-url, but maybe in the future we want to use an enum that is not a URL. So 🤷

Deprecating it also doesn't feel right because it's like some feature that has always been a work in progress. Maybe we can hide it from the documentation, but it was already there... so this is one of those unfortunate cases where we've dropped the ball and we didn't know about it.

We can update the description, but also the example helps documenting that it's not being used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds sensible. I'd add a note to the description that this isn't used yet, but might be in the future, then.

properties: {
version: {
type: 'integer',
description:
'The version of the schema used to model the tag types.',
example: 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many versions do we have? Could we maybe use an enum to show all the versions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 1 AFAIK, and it will probably never change. This is reserved for major changes, but I don't think modeling a version as an enum is a good idea as adding a new version would be a breaking change for older clients (which will not be gracefully handled)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see your reasoning here. However, I feel like giving users a clear description of what values we expect to deliver would be also be good. Maybe an enum and stating explicitly that more versions can be added in the future, but that any breaking changes would go in a major version?

If not, I'm happy to leave it as is too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an enum and stating explicitly that more versions can be added in the future

I think the version being an integer states exactly that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talking about it with @chriswk there might be some benefits of having it as an enum. I did some digging and found this and this, none of those were conclusive. I asked ChatGPT and this is what I got:

Including a version field in the response of an OpenAPI specification can be a good idea in certain situations, especially when dealing with APIs that are subject to frequent updates or have different versions coexisting. However, whether to represent the version field as an enum or a string/integer depends on your specific use case and requirements. Let's discuss the considerations for each option:

  1. Enum:
    Using an enum to represent the version field in the response has some benefits. It provides a predefined set of allowed values, ensuring that the version is always one of the specified options. This can help with consistency, validation, and avoiding potential typos or accidental variations in the version representation.

However, using an enum for versioning can also introduce some challenges. Enums are typically used for representing a finite set of known values, assuming that the set won't change frequently. If your API has a dynamic versioning system with a large number of potential versions, it may be impractical to maintain an enum that includes all possible values. Additionally, if the versioning system allows for arbitrary or user-defined values, an enum may not be suitable.

  1. String or Integer:
    Representing the version field as a string or an integer provides more flexibility compared to an enum. It allows for arbitrary version values, including custom or vendor-specific formats. This flexibility can be advantageous when dealing with complex versioning schemes or when the API consumers need to parse and interpret the version information in a specific way.

Using a string or integer for the version field also makes it easier to add new versions without modifying the API specification. You can simply introduce a new value without needing to update the enum definition or regenerate client code.

Ultimately, the decision between using an enum, string, or integer for the version field depends on the specific requirements of your API and how you want to manage versioning. Consider factors such as the expected number of versions, whether the set of versions is known and stable, and how the version information will be used by API consumers.

Overall, this doesn't seem like a decision to take on lightly in this particular API. I think this is worth some general alignment and changing this across the board.

Most of our versions are numbers, a few are enums and there's no consistency on how we define versions. I think this should be our focus, but for now, I'd like to keep it as an integer which is what majority of our APIs are using

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. Thanks for flagging that and having the discussion! Let's figure it out later 😄

properties: {
version: {
type: 'integer',
description: 'The version of the schema used to model the tag.',
example: 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Can we and do we want to use enums here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to model auto-incremental values with enums

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up considering the option of modeling versions with enums as potentially good: #4194 (comment) but I think we should be consistent with the rest of our schemas, and if we want to pursue this change we should do it on all schemas. So I'm keeping this for this PR but I'm open to follow up on this topic and changing it later if we deem it valuable

},
icon: {
type: 'string',
description: 'The icon of the tag type.',
example: 'not-really-used',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous question regarding tag types.

@@ -69,8 +77,11 @@ class TagTypeController extends Controller {
openApiService.validPath({
tags: ['Tags'],
operationId: 'createTagType',
summary: 'Create a tag type',
description: 'Create a new tag type.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a tag type with the same name already exists? Is that a 409? We should communicate that to the end user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a 409, I missed adding it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here: bf74c88

src/lib/routes/admin-api/tag-type.ts Outdated Show resolved Hide resolved
src/lib/routes/admin-api/tag-type.ts Outdated Show resolved Hide resolved
responses: {
200: emptyResponse,
...getStandardResponses(401, 403),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you get a 404 if the tag doesn't exist or just a 200?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always 200 when the tag doesn't exist

src/lib/routes/admin-api/tag.ts Outdated Show resolved Hide resolved
src/lib/routes/admin-api/tag.ts Outdated Show resolved Hide resolved
gastonfournier and others added 3 commits July 10, 2023 15:27
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go in now 😄 I'd like some clarification on the icon property for tag types, but that can always be added later 💁🏼

@gastonfournier gastonfournier merged commit 58151d8 into main Jul 11, 2023
10 checks passed
@gastonfournier gastonfournier deleted the docs/openapi-tag-and-tag-types branch July 11, 2023 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants