-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use x-navtitle
and x-slug
extensions for tags. Close #50
#52
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`tags rendering renders tag and toc: basic 1`] = ` | ||
"# basic | ||
|
||
basic tag | ||
|
||
## Endpoints | ||
|
||
- [tags](tags.md) | ||
|
||
<!-- markdownlint-disable-file -->" | ||
`; | ||
|
||
exports[`tags rendering renders tag and toc: toc 1`] = ` | ||
"name: openapi | ||
items: | ||
- name: Overview | ||
href: index.md | ||
- name: basic | ||
items: | ||
- name: Overview | ||
href: basic/index.md | ||
- href: basic/tags.md | ||
name: tags | ||
- name: Alternate title | ||
items: | ||
- name: Overview | ||
href: navtitle/index.md | ||
- href: navtitle/tags.md | ||
name: tags | ||
- name: Normal title | ||
items: | ||
- name: Overview | ||
href: normal/index.md | ||
- href: normal/tags.md | ||
name: tags | ||
- href: test-parameters.md | ||
name: parameters test | ||
" | ||
`; | ||
|
||
exports[`tags rendering renders tag and toc: weird 1`] = ` | ||
"# Normal title | ||
|
||
weird tag with normal slug | ||
|
||
## Endpoints | ||
|
||
- [tags](tags.md) | ||
|
||
<!-- markdownlint-disable-file -->" | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {DocumentBuilder, run} from './__helpers__/run'; | ||
|
||
const name = 'tags'; | ||
describe('tags rendering', () => { | ||
it('renders tag and toc', async () => { | ||
const spec = new DocumentBuilder(name) | ||
.response(200, { | ||
description: 'Base 200 response', | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
type: { | ||
type: 'string', | ||
}, | ||
foo: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}) | ||
.tag({ | ||
name: 'basic', | ||
description: 'basic tag', | ||
}) | ||
.tag({ | ||
name: 'navtitle', | ||
'x-navtitle': 'Alternate title', | ||
}) | ||
.tag({ | ||
name: 'weird', | ||
description: 'weird tag with normal slug', | ||
'x-slug': 'normal', | ||
'x-navtitle': 'Normal title', | ||
}) | ||
.build(); | ||
|
||
const fs = await run(spec); | ||
|
||
const toc = fs.match('toc.yaml'); | ||
|
||
expect(toc).toMatchSnapshot('toc'); | ||
|
||
const tag = fs.match('basic/index.md'); | ||
|
||
expect(tag).toMatchSnapshot('basic'); | ||
|
||
const tag2 = fs.match('normal/index.md'); | ||
|
||
expect(tag2).toMatchSnapshot('weird'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,15 @@ function tagsFromSpec(spec: OpenAPISpec): Map<string, Tag> { | |
} | ||
} | ||
|
||
parsed.forEach((tag: Tag) => { | ||
if (tag['x-navtitle']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is supposed to make prior There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It overrides But I'm trying to keep backward compatibility. |
||
tag.name = tag['x-navtitle']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have my reservations about the fact that we have zero distinction between a |
||
} | ||
if (tag['x-slug']) { | ||
tag.id = tag['x-slug']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're now modifying From my point of view, this fact makes using a map obsolete, and we should probably collect the tags in a list instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I had to modify But we could see this as |
||
} | ||
}); | ||
|
||
return parsed; | ||
} | ||
const opid = (path: string, method: string, id?: string) => slugify(id ?? [path, method].join('-')); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these test names poorly reflect on what's actually being tested. This PR is implementing a mechanism to override page headings and URLs when specific vendor extensions are used. I could suggest naming the test suite something along the lines of
Identity of pages derived from spec tags
with cases named likecan be overriden using x-slug to define a custom URL
. Anyway, I'm open to suggestions here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think it's not a bad idea to split this test case, since this looks to me like three independent test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've split test cases