-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Make species parameter optional. If not specified, return all species breeds * Create type BreedWithSpecies
- Loading branch information
1 parent
af9ed19
commit a6e54b2
Showing
7 changed files
with
122 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import validateAnimalConnection | |
import requests from './utils/requests'; | ||
|
||
|
||
|
||
const animalFields = ` | ||
{ | ||
id | ||
|
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,7 @@ | ||
export default interface BreedWithSpecies { | ||
id: number; | ||
abbreviation: string; | ||
value: string; | ||
speciesId: number; | ||
speciesValue: string; | ||
} |
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,54 @@ | ||
/* tslint:disable */ | ||
// generated by typescript-json-validator | ||
import { inspect } from 'util'; | ||
import BreedWithSpecies from '../interfaces/breedWithSpecies.interface'; | ||
import Ajv = require('ajv'); | ||
|
||
export const ajv = new Ajv({"allErrors":true,"coerceTypes":false,"format":"fast","nullable":true,"unicode":true,"uniqueItems":true,"useDefaults":true}); | ||
|
||
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json')); | ||
|
||
export {BreedWithSpecies}; | ||
export const BreedWithSpeciesSchema = { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"defaultProperties": [ | ||
], | ||
"properties": { | ||
"abbreviation": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "number" | ||
}, | ||
"speciesId": { | ||
"type": "number" | ||
}, | ||
"speciesValue": { | ||
"type": "string" | ||
}, | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"abbreviation", | ||
"id", | ||
"speciesId", | ||
"speciesValue", | ||
"value" | ||
], | ||
"type": "object" | ||
}; | ||
export type ValidateFunction<T> = ((data: unknown) => data is T) & Pick<Ajv.ValidateFunction, 'errors'> | ||
export const isBreedWithSpecies = ajv.compile(BreedWithSpeciesSchema) as ValidateFunction<BreedWithSpecies>; | ||
export default function validate(value: unknown): BreedWithSpecies { | ||
if (isBreedWithSpecies(value)) { | ||
return value; | ||
} else { | ||
throw new Error( | ||
ajv.errorsText(isBreedWithSpecies.errors!.filter((e: any) => e.keyword !== 'if'), {dataVar: 'BreedWithSpecies'}) + | ||
'\n\n' + | ||
inspect(value), | ||
); | ||
} | ||
} |