Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix broken OpenAPI spec (#1846)
* Wip: fix openapi spec * Feat: add openapi enforcer for enforcing the generated schema * Chore: Allow the example keyword in params * Feat: add validator tests and fix some errors * Use @apidevtools/swagger-parser for schema validation * Wip: refactor tests for updated schema name * Feat: update request params creation method * Feat: add query params to state * Refactor: move mapping test into separate function * Refactor: rename request-parameters -> query-parameters * Refactor: expose only finished query parameters * Wip: fixup param types * Refactor: remove unused types * Chore: rename and cleanup * Chore: cleanup * Fix: Update snapshot * Fix: use ?? Instead of paramToBool to get defaults * Wip: generate query param object type from openapi params list * Wip: use generated types for export query params * Revert "Fix: use ?? Instead of paramToBool to get defaults" This reverts commit 8425675. Because we accept bools, strings, and numbers, this is the only way to do it. * Chore: update and pin json-schema-to-ts * Fix: use `&` to merge types * Update snapshot * Chore: rename export-parameters-schema -> export-query-parameters When it ends in `schema`, the tests expect it to be included in the openapi index file.
- Loading branch information
1 parent
f6192b5
commit 6afc0a6
Showing
15 changed files
with
407 additions
and
139 deletions.
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { FromQueryParams } from '../util/from-query-params'; | ||
|
||
export const exportQueryParameters = [ | ||
{ | ||
name: 'format', | ||
schema: { | ||
type: 'string', | ||
enum: ['json', 'yaml'], | ||
default: 'json', | ||
}, | ||
description: 'Desired export format. Must be either `json` or `yaml`.', | ||
in: 'query', | ||
}, | ||
{ | ||
name: 'download', | ||
schema: { | ||
default: false, | ||
anyOf: [ | ||
{ | ||
type: 'boolean', | ||
}, | ||
{ | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
}, | ||
description: 'Whether exported data should be downloaded as a file.', | ||
in: 'query', | ||
}, | ||
{ | ||
name: 'strategies', | ||
schema: { | ||
default: true, | ||
anyOf: [ | ||
{ | ||
type: 'boolean', | ||
}, | ||
{ | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
}, | ||
description: | ||
'Whether strategies should be included in the exported data.', | ||
in: 'query', | ||
}, | ||
{ | ||
name: 'featureToggles', | ||
schema: { | ||
anyOf: [ | ||
{ | ||
type: 'boolean', | ||
}, | ||
{ | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
default: true, | ||
}, | ||
description: | ||
'Whether feature toggles should be included in the exported data.', | ||
in: 'query', | ||
}, | ||
{ | ||
name: 'projects', | ||
schema: { | ||
anyOf: [ | ||
{ | ||
type: 'boolean', | ||
}, | ||
{ | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
default: true, | ||
}, | ||
description: | ||
'Whether projects should be included in the exported data.', | ||
in: 'query', | ||
}, | ||
{ | ||
name: 'tags', | ||
schema: { | ||
anyOf: [ | ||
{ | ||
type: 'boolean', | ||
}, | ||
{ | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
default: true, | ||
}, | ||
description: | ||
'Whether tag types, tags, and feature_tags should be included in the exported data.', | ||
in: 'query', | ||
}, | ||
{ | ||
name: 'environments', | ||
schema: { | ||
anyOf: [ | ||
{ | ||
type: 'boolean', | ||
}, | ||
{ | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
default: true, | ||
}, | ||
description: | ||
'Whether environments should be included in the exported data.', | ||
in: 'query', | ||
}, | ||
] as const; | ||
|
||
export type ExportQueryParameters = FromQueryParams< | ||
typeof exportQueryParameters | ||
>; |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// module to create typescript types from query param lists. Based on | ||
// input in this GitHub issue: | ||
// https://github.com/ThomasAribart/json-schema-to-ts/issues/82 | ||
import { FromSchema, JSONSchema } from 'json-schema-to-ts'; | ||
|
||
import { O, L, A } from 'ts-toolbelt'; | ||
|
||
type OpenApiParam = { | ||
readonly name: string; | ||
readonly schema: JSONSchema; | ||
// Parameter types: | ||
// https://swagger.io/docs/specification/describing-parameters/#types | ||
readonly in: 'query' | 'path' | 'header' | 'cookie'; | ||
}; | ||
|
||
type RecurseOnParams< | ||
P extends readonly OpenApiParam[], | ||
R extends O.Object = {}, | ||
> = { | ||
continue: RecurseOnParams< | ||
L.Tail<P>, | ||
L.Head<P>['in'] extends 'query' | ||
? R & { | ||
[key in L.Head<P>['name']]: FromSchema<L.Head<P>['schema']>; | ||
} | ||
: R | ||
>; | ||
stop: A.Compute<R>; | ||
}[P extends readonly [OpenApiParam, ...OpenApiParam[]] ? 'continue' : 'stop']; | ||
|
||
export type FromQueryParams<P extends readonly OpenApiParam[]> = | ||
RecurseOnParams<P>; |
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
Oops, something went wrong.