Skip to content

Commit

Permalink
feat(hariko-parser): support case on document has copy in group section
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmihi committed Sep 9, 2019
1 parent a2de647 commit 394f958
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/dist/hariko-parser/structure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Builder {
this.dispatch(row.content);
return;
}
if (row.element === 'copy') {
return;
}
throw new Error(`hariko-parser unsupported element`);
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/@types/protagonist.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ declare module 'protagonist' {
content: string
}[]
}

export type ProtagonistCopy = {
element: 'copy'
content: string
}
}
13 changes: 11 additions & 2 deletions src/hariko-parser/structure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
ProtagonistParseResult,
ProtagonistResource,
ProtagonistAnnotation,
ProtagonistCategory
ProtagonistCategory,
ProtagonistCopy
} from 'protagonist'
import { ResourcesStructure } from './resources'
import { AnnotationsStructure } from './annotations'
Expand All @@ -22,7 +23,11 @@ class Builder {
}

private dispatch(
rows: (ProtagonistAnnotation | ProtagonistResource | ProtagonistCategory)[]
rows: (
| ProtagonistAnnotation
| ProtagonistResource
| ProtagonistCategory
| ProtagonistCopy)[]
) {
rows.forEach((row) => {
if (row.element === 'annotation') {
Expand All @@ -40,6 +45,10 @@ class Builder {
return
}

if (row.element === 'copy') {
return
}

throw new Error(`hariko-parser unsupported element`)
})
}
Expand Down
13 changes: 13 additions & 0 deletions test/case/have-copy-in-group-section/docs.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Group Have copy in group section

this example have a some copy.

# Case 5 [POST /case/05]

+ Response 200 (application/json)

+ Body

{
message: "case"
}
34 changes: 34 additions & 0 deletions test/case/have-copy-in-group-section/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-env mocha */
import assert = require('assert')
import * as path from 'path'
import * as HarikoParser from '../../../src/hariko-parser'
import { load } from '../../utils/fixture'

describe('case: have a some copy in group section', () => {
it('should be enable parse', () => {
const content = load(path.join(__dirname, './docs.apib'))
const result = HarikoParser.parse(content)
assert.deepEqual(result, {
entries: [
{
request: {
method: 'POST',
uri: {
path: '/case/05',
template: '/case/05',
queries: []
}
},
response: {
statusCode: 200,
headers: [{ name: 'Content-Type', value: 'application/json' }],
body: '{\n message: "case"\n}\n',
data: { message: 'case' }
},
file: 'case/05-POST.json'
}
],
warnings: []
})
})
})

0 comments on commit 394f958

Please sign in to comment.