-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating the ContentHandler class that validates content based on the…
… ContentType.
- Loading branch information
Showing
2 changed files
with
32 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as Swagger2 from './swagger/2' | ||
import * as JsonSchemaDraft4 from './jsonschema/draft-04' | ||
import * as JsonSchemaDraft6 from './jsonschema/draft-06' | ||
|
||
export enum ContentType { | ||
SwaggerYaml2 = 'swagger.yaml;version=2', | ||
SwaggerJson2 = 'swagger.json;version=2', | ||
JsonSchemaDraft4 = 'jsonschema;version=draft-04', | ||
JsonSchemaDraft6 = 'jsonschema;version=draft-06' | ||
} | ||
|
||
export class ContentHandler { | ||
type: ContentType | ||
constructor (type: ContentType) { | ||
this.type = type | ||
} | ||
validate (content: string): Promise<void> { | ||
switch (this.type) { | ||
case ContentType.SwaggerYaml2: | ||
return Swagger2.validateYaml(content) | ||
case ContentType.SwaggerJson2: | ||
return Swagger2.validateJson(content) | ||
case ContentType.JsonSchemaDraft4: | ||
return JsonSchemaDraft4.validate(content) | ||
case ContentType.JsonSchemaDraft6: | ||
return JsonSchemaDraft6.validate(content) | ||
default: | ||
throw new Error('Handler detected unsupported content type!') | ||
} | ||
} | ||
} |
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