Skip to content

Conversation

@mallachari
Copy link

@mallachari mallachari commented Aug 13, 2021

Addresses: https://github.com/stoplightio/platform-internal/issues/7377

Quotes were added to distinguish the type of validation.
This PR makes enum, examples and default not show quotes regardless of type.

@mallachari mallachari requested review from a team and mpodlasin August 13, 2021 10:24
@mallachari mallachari force-pushed the feat/string-validations-no-wrap branch from 18cceea to 833151a Compare August 13, 2021 10:29
@mallachari mallachari self-assigned this Aug 13, 2021
const validationFormatters: Record<string, (value: unknown) => ValidationFormat | null> = {
enum: createValidationsFormatter('Allowed'),
examples: createValidationsFormatter('Example'),
enum: createValidationsFormatter('Allowed', { nowrap: true }),
Copy link
Contributor

@P0lip P0lip Aug 13, 2021

Choose a reason for hiding this comment

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

Hmm, and how will one recognize such an enum?

enum: [1, "1"]

I don't think it's a good decision to remove quotes. These are strings, so let them be.

Copy link
Author

Choose a reason for hiding this comment

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

We can't in such a case. That's why I added it in the first place.
@mnaumanali94 is it really needed to remove those quotes? We're losing a type then.

Copy link
Contributor

@billiegoose billiegoose Aug 16, 2021

Choose a reason for hiding this comment

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

Hmm, and how will one recognize such an enum?

enum: [1, "1"]

This is a terrible enum! If someone is mixing stringified numbers and numberified numbers in an enum, their API is beyond our help. :trollface:

Copy link
Contributor

Choose a reason for hiding this comment

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

I know it is, but it's just to show the example.
The below cases are valid tho:

enum: ["1", "2", "3"]
enum: [1, 2, 3]

If we render them the same way, how will one be able to tell the difference?

Copy link
Contributor

Choose a reason for hiding this comment

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

@P0lip are enums the only potential problem? Or can you think about more examples where this change would cause confusion? 🤔

What if we made the enums an exception here? @mnaumanali94 is a strong proponent of that change. 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends on the scenario.
Consider the below:

{ 
  "enum": ["0", 1, "2"]
}

or

{
  "type": ["string", "number"],
  "enum": ["0", 1, "2"]
}

One won't be able to tell the difference once we apply the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Have you ever seen an enum like this though? 🤦🏼

Copy link
Contributor

Choose a reason for hiding this comment

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

Should

type: string,
enum: [asc, desc]

In our docs, these values should appear as "asc", "desc" is what you're suggesting?

Copy link
Contributor

Choose a reason for hiding this comment

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

The first example is quite common actually.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking this is not a common use case. The concern is primarily folks thinking "" are part of the value which would be wrong. Lets get this in, and see if there's a reaction from our consumers. If so, we can use colours to denote string vs integer values.

@mnaumanali94 mnaumanali94 requested review from a team and mnaumanali94 August 20, 2021 00:02
@mallachari mallachari requested a review from billiegoose August 23, 2021 17:36
@mallachari mallachari merged commit d3b7fa6 into master Aug 24, 2021
@mallachari mallachari deleted the feat/string-validations-no-wrap branch August 24, 2021 09:06
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants