Skip to content
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

support length limits #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/__snapshots__/length.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`length renders correct length limits 1`] = `
"<div class="openapi">

# length

## Request

<div class="openapi__request__wrapper">

<div class="openapi__request" style="--method: var(--dc-openapi-methods-post)">

POST {.openapi__method}


\`\`\`
http://localhost:8080/test
\`\`\`


</div>

</div>

Generated server url{.openapi__request__description}

## Responses

<div class="openapi__response__code__200">

## 200 OK

### Body

{% cut "application/json" %}


\`\`\`json
{
"pet": {
"name": "string",
"foo": "string"
},
"petWithoutDescription": {
"name": "string",
"foo": "string"
},
"refToSchemaWithDescription": {
"name": "string",
"bar": "string"
}
}
\`\`\`


{% endcut %}


#||| **Name** | **Type** | **Description** ||

|| pet | [Cat](#cat) | From response ||

|| petWithoutDescription | [Cat](#cat) | Cat class ||

|| refToSchemaWithDescription | [Dog](#dog) | Dog class |||#

### Cat

Cat class

#||| **Name** | **Type** | **Description** ||

|| name | string | ||

|| foo | string | <span style="color:gray;">Min length</span>: \`3\` |||#

### Dog

Dog class

#||| **Name** | **Type** | **Description** ||

|| name | string | Pet name<br><span style="color:gray;">Max length</span>: \`100\` ||

|| bar | string | <span style="color:gray;">Min length</span>: \`1\`<br><span style="color:gray;">Max length</span>: \`99\` |||#

</div>
<!-- markdownlint-disable-file -->

</div>"
`;
63 changes: 63 additions & 0 deletions src/__tests__/length.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {DocumentBuilder, run} from './__helpers__/run';

const name = 'length';
describe('length', () => {
it('renders correct length limits', async () => {
const spec = new DocumentBuilder(name)
.component('Pet', {
allOf: [DocumentBuilder.ref('Cat', 'From allOf in Pet')],
description: 'From pet',
})
.component('Cat', {
type: 'object',
properties: {
name: {
type: 'string',
},
foo: {
type: 'string',
minLength: 3,
},
},
description: 'Cat class',
})
.component('Dog', {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Pet name',
maxLength: 100,
},
bar: {
type: 'string',
minLength: 1,
maxLength: 99,
},
},
description: 'Dog class',
})
.response(200, {
schema: {
properties: {
pet: {
allOf: [DocumentBuilder.ref('Pet', 'From response')],
},
petWithoutDescription: {
allOf: [DocumentBuilder.ref('Cat')],
},
refToSchemaWithDescription: {
allOf: [DocumentBuilder.ref('Dog')],
},
},
},
})
.build();

const fs = await run(spec);

const page = fs.match(name);

expect(page).toMatchSnapshot();
});
});
13 changes: 13 additions & 0 deletions src/includer/traverse/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ function prepareComplexDescription(baseDescription: string, value: OpenJSONSchem
);
}

if (typeof value.minLength !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Min length</span>: \`${value.minLength}\``,
);
}
if (typeof value.maxLength !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Max length</span>: \`${value.maxLength}\``,
);
}

return description;
}

Expand Down
Loading