Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.
Open
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
10 changes: 10 additions & 0 deletions docs/describing-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ Assuming `offset` defaults to 0 and `limit` defaults to 20, you would define the
*/
```

### Example parameter values
Append `e.g. value` to the end of the description to define an example value for the parameter.
This is useful for required parameters that you want to provide an example value.

```js
/**
* @queryParam {integer} id - The user id to search for. e.g. 20
*/
```

### Enum parameters
You can restrict a parameter to a fixed set of values by adding the `enum` to the `schema`.
The enum values must be of the same type as the parameter data type.
Expand Down
13 changes: 11 additions & 2 deletions src/util/commentsToOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,29 @@ function parseDescription(tag: any) {
items: {
...rootType,
},
example: undefined
};
} else {
schema = {
...rootType,
example: undefined
};
}

if (parsedType === undefined) {
schema = undefined;
}

// Get the example value from end of the description
const desc = tag.description.trim().split('e.g.')
if (desc[1] && schema) {
schema.example = desc[1].trim()
}


// remove the optional dash from the description.
let description = tag.description.trim().replace(/^- /, '');
if (description === '') {
let description = desc[0].trim().replace(/^- /, '');
if (description === '' || description === '-') {
description = undefined;
}

Expand Down