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

feat: allow for single example #1705

Open
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

cedvdb
Copy link

@cedvdb cedvdb commented Jun 21, 2023

resolves #1619

Allows for a single @example in comment tags.

Previously the parser assumes that there might be multiple such tag in comments and add it to an array of example, transforming the original @example into example. If there is only one of such tag, this make it so it return example instead.

This is important because examples is not valid in openapi for example.

@domoritz domoritz changed the title Allow for single example feat: allow for single example Jun 21, 2023
@cedvdb
Copy link
Author

cedvdb commented Jun 21, 2023

@domoritz tests have been changed,

I modified the current test as there is already one for multiple examples under it. I think now it covers both scenarios.

Current next branch (without these changes) has tests failing.

Comment on lines +10 to +12
"example": {
"nested": "hello"
},
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually better? The old format is more predictable and easier to process since it's consistent.

Can you send a link to json schema spec about this tag?

Copy link
Author

@cedvdb cedvdb Jun 22, 2023

Choose a reason for hiding this comment

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

Not sure, Examples does not pass validation under openapi spec, while example does.

Here is the spec on examples: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-examples it says nothing about example

There are instances of example being used in open api specs https://swagger.io/specification/ which is not a 1:1 with json schema.

There is a flag: discriminatorType: 'open-api' in the config that could be used ?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, then I would say this is an issue to raise with openapi and swagger. I don't really want to diverge from JSON schema.

I was somewhat reluctant to add the discriminatorType flag and would not like to support too many flags.

Copy link
Author

@cedvdb cedvdb Jun 22, 2023

Choose a reason for hiding this comment

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

Makes sense.

would not like to support too many flags.

the open api flag seems to be already there

You might close this PR if you wish, I don't think there is anymore to be done here.

Copy link
Member

Choose a reason for hiding this comment

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

How about we add one flag for openapi support and use that for all openapi related features?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jsdoc @example & @examples are both output into "examples" field
2 participants