Skip to content

Commit

Permalink
Creating the ContentHandler class that validates content based on the…
Browse files Browse the repository at this point in the history
… ContentType.
  • Loading branch information
khalidx committed Jul 25, 2017
1 parent 15689a6 commit 604d5fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/content/handler/index.ts
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!')
}
}
}
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import * as provider from './provider/aws'

export enum ContentType {
SwaggerVersion2 = 'swagger.yaml;version=2',
JsonSchemaVersion4 = 'jsonschema;version=4'
}
import { ContentType } from './content/handler'

export enum ResourceType {
schemas,
Expand Down

0 comments on commit 604d5fd

Please sign in to comment.