-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(open-api): resolve type safety issues and create util file f…
…or OpenAPI type guards INT-407
- Loading branch information
Showing
5 changed files
with
51 additions
and
35 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 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,22 @@ | ||
import {type OpenAPIV3_1 as OpenApiType} from 'openapi-types'; | ||
|
||
export function isParameterType( | ||
parameter: OpenApiType.ParameterObject | OpenApiType.ReferenceObject, | ||
): parameter is OpenApiType.ParameterObject { | ||
return 'in' in parameter && 'schema' in parameter; | ||
} | ||
|
||
// Guard to check if the schema is an OpenApiType.SchemaObject. | ||
export const isSchemaObject = (schema: object): schema is OpenApiType.SchemaObject => { | ||
return typeof schema === 'object'; | ||
}; | ||
|
||
// Guard to check if the schema is an OpenApiType.ArraySchemaObject. | ||
export const isArraySchemaObject = (schema: object): schema is OpenApiType.ArraySchemaObject => { | ||
return typeof schema === 'object' && 'items' in schema; | ||
}; | ||
|
||
// Guard to check if the response is an OpenApiType.ResponseObject. | ||
export const isReponseObject = (response: object): response is OpenApiType.ResponseObject => { | ||
return typeof response === 'object'; | ||
}; |