question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can we set parameter `description` and `example`?

See original GitHub issue

Is it currently not possible to set the parameter description and example?

From what I can tell the parameter fields supported are:

  • in
  • name
  • required
  • schema

I’d be interested in contributing if you have an idea in mind how we can support setting a default description and example.

https://swagger.io/specification/#parameterObject

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lokesh1197commented, Nov 26, 2020

There’s no place to define description and example out of the box, that’s correct. Couple of ways around this come to mind:

using QueryParams/Params etc instead of QueryParam/Param:

class MyQueryParams {
  @JSONSchema({ description: 'my ID query parameter' })
  @IsString()
  id: string
}

someHandler(@QueryParams() queryParams: MyQueryParams) {
    // ...
}

my ID query parameter description then ends up in the parameters[0].schema object. We’re missing handling for @Params right now so that would need to be added.

adding another decorator , something along the lines of:

function OpenAPIParam(name: string, props: Partial<ParameterObject>) {
  return OpenAPI(schema => {
    const index = schema.parameters.findIndex(
      p => 'name' in p && p.name === name
    )
    if (index > -1) {
      schema.parameters[index] = {
        ...schema.parameters[index],
        ...props
      }
    }
    return schema
  })
}

@OpenAPIParam('id', { description: 'My ID path parameter', example: 1234 })
someHandler(@Param('id') id: number) {
  // ...
}

Now description ends up in parameters[0] - not inside schema like above.

The second example if very helpful and I think most users might need it. Wouldn’t it be great to add it to the package?

1reaction
epiphonecommented, Mar 14, 2019

There’s no place to define description and example out of the box, that’s correct. Couple of ways around this come to mind:

using QueryParams/Params etc instead of QueryParam/Param:

class MyQueryParams {
  @JSONSchema({ description: 'my ID query parameter' })
  @IsString()
  id: string
}

someHandler(@QueryParams() queryParams: MyQueryParams) {
    // ...
}

my ID query parameter description then ends up in the parameters[0].schema object. We’re missing handling for @Params right now so that would need to be added.

adding another decorator , something along the lines of:

function OpenAPIParam(name: string, props: Partial<ParameterObject>) {
  return OpenAPI(schema => {
    const index = schema.parameters.findIndex(
      p => 'name' in p && p.name === name
    )
    if (index > -1) {
      schema.parameters[index] = {
        ...schema.parameters[index],
        ...props
      }
    }
    return schema
  })
}

@OpenAPIParam('id', { description: 'My ID path parameter', example: 1234 })
someHandler(@Param('id') id: number) {
  // ...
}

Now description ends up in parameters[0] - not inside schema like above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Describing Parameters - Swagger
In Swagger, API operation parameters are defined under the parameters section in the operation definition. Each parameter has name , value type (for...
Read more >
Parameter - Overview, Examples, and Uses in Statistics
A parameter is used to describe the entire population being studied. For example, we want to know the average length of a butterfly....
Read more >
Swashbuckle parameter descriptions - Stack Overflow
Parameters should be explicitly decorated with either [FromRoute] , [FromQuery] , [FromBody] etc. The same for the method type (get/post/put etc.), which should ......
Read more >
Step 3: Parameters (API reference tutorial) | Documenting APIs
In this example, the parameters are grouped by type: path parameters, query parameters, and body parameters. The endpoint also sets off the ...
Read more >
Create a parameter query (Power Query) - Microsoft Support
Use a parameter to change a data source · To set the folder name as a parameter, in Query Settings, under Query Steps,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found