-
Notifications
You must be signed in to change notification settings - Fork 36
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
Move parameters schema keywords location #108
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1348638
fix: move parameter schema keywords location
nxht dfb41bd
feat: add schema examples
nxht c6727c7
refactor: rename schemaProperties to schemaKeywords
nxht 4ae9829
test: add schemaKeyword tests
nxht 3e26524
style: remove unnecessary console.log
nxht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Elysia, t } from 'elysia' | |
import SwaggerParser from '@apidevtools/swagger-parser' | ||
import { swagger } from '../src' | ||
|
||
import { describe, expect, it } from 'bun:test' | ||
import { it } from 'bun:test' | ||
import { fail } from 'assert' | ||
|
||
const req = (path: string) => new Request(`http://localhost${path}`) | ||
|
@@ -27,17 +27,30 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => { | |
) | ||
.post( | ||
'/json/:id', | ||
({ body, params: { id }, query: { name } }) => ({ | ||
({ body, params: { id }, query: { name, email, birthday } }) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome! more tests :) |
||
...body, | ||
id, | ||
name | ||
name, | ||
email, | ||
birthday | ||
}), | ||
{ | ||
params: t.Object({ | ||
id: t.String() | ||
}), | ||
query: t.Object({ | ||
name: t.String() | ||
name: t.String(), | ||
email: t.String({ | ||
description: 'sample email description', | ||
format: 'email' | ||
}), | ||
birthday: t.String({ | ||
description: 'sample birthday description', | ||
pattern: '\\d{4}-\\d{2}-\\d{2}', | ||
minLength: 10, | ||
maxLength: 10 | ||
}), | ||
|
||
}), | ||
body: t.Object({ | ||
username: t.String(), | ||
|
@@ -48,7 +61,17 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => { | |
username: t.String(), | ||
password: t.String(), | ||
id: t.String(), | ||
name: t.String() | ||
name: t.String(), | ||
email: t.String({ | ||
description: 'sample email description', | ||
format: 'email' | ||
}), | ||
birthday: t.String({ | ||
description: 'sample birthday description', | ||
pattern: '\\d{4}-\\d{2}-\\d{2}', | ||
minLength: 10, | ||
maxLength: 10 | ||
}), | ||
}, | ||
{ description: 'sample description 3' } | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to keep this spread of rest at the root of the return and not in
schema
?i'll be pulling and testing out tonight but wanted to give a review before that and ask ahead :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marclave
Had a thought of it and I think it makes more sense to be under
schema
.Most JSON schema keywords goes under
schema
except fordescription
,required
,examples
. So there's lesser keywords to defineAlso when we choose to define some keywords and send others to spread, it makes more sense to me to define generic keywords explicitly and send type-specific keywords like
minLength
, which belongs toschema
, to the rest