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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/AnnotationsReader/ExtendedAnnotationsReader.ts
Expand Up @@ -101,8 +101,12 @@

if (examples.length === 0) {
return undefined;
}

Check failure on line 104 in src/AnnotationsReader/ExtendedAnnotationsReader.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Delete `⏎⏎·······`

Check failure on line 104 in src/AnnotationsReader/ExtendedAnnotationsReader.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Delete `⏎⏎·······`

else if (examples.length === 1) {
cedvdb marked this conversation as resolved.
Show resolved Hide resolved
return { example: examples[0] };
}

return { examples };
}
}
10 changes: 4 additions & 6 deletions test/valid-data/annotation-example/schema.json
Expand Up @@ -7,11 +7,9 @@
},
"MyObject": {
"additionalProperties": false,
"examples": [
{
"nested": "hello"
}
],
"example": {
"nested": "hello"
},
Comment on lines +10 to +12
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?

"properties": {
"nested": {
"$ref": "#/definitions/MyNestedObject",
Expand All @@ -27,4 +25,4 @@
"type": "object"
}
}
}
}