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.

Unable to setting query parameters to be required

See original GitHub issue

I’m trying to set query parameter on a HttpGet to be required but am unable to do so. Even integers will not be required by default when the swagger.json is created.

[HttpGet]
[Produces("application/json", Type = typeof(IEnumerable<string>))]
[SwaggerOperation(operationId: "ListStuff")]
[ProducesResponseType(typeof(string), (int)HttpStatusCode.BadRequest)]
public IActionResult ListStuff(int id, [Required]string auditId)
{
    ...
}

In the above scenario, both id and auditId will be flagged as not required:

"parameters": [{
	"name": "id",
	"in": "query",
	"required": false,
	"type": "integer"
},
{
	"name": "auditId",
	"in": "query",
	"required": false,
	"type": "string"
}]

Not sure if this is a bug (swear I read somewhere that required is the default), or if I’m doing something wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ThisNoNamecommented, Nov 8, 2017

Same here. [Required] on primitive parameter not show up. [Required] on object parameter works fine.

1reaction
edjacob25commented, Oct 26, 2017

+1 I got something like

/// <summary>
/// Returns all items in the FV Inventory
/// </summary>
[HttpGet]
public IEnumerable<FvInventory> Get([FromQuery][Required] int projectId, [FromQuery]int? moduleId, [FromQuery] int? fvType, [FromQuery] int? statusId)

And I got something like

"parameters": [{
                "name": "projectId",
                "in": "query",
                "required": false,
                "type": "integer",
                "format": "int32"
            }, {
                "name": "moduleId",
                "in": "query",
                "required": false,
                "type": "integer",
                "format": "int32"
            }, {
                "name": "fvType",
                "in": "query",
                "required": false,
                "type": "integer",
                "format": "int32"
            }, {
                "name": "statusId",
                "in": "query",
                "required": false,
                "type": "integer",
                "format": "int32"
            }]
Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the problem with required query parameters?
When reviewing API designs, I often encounter operations such as GET /resources?queryParameter=value where the query parameter is required.
Read more >
Unable to set query parameters manually for a rest api ...
The problem is that r.URL.Query() parses the url, creates the map of parameters and returns it. This is done with every .Query() call....
Read more >
unable to pass query string parameter id from test class
Hi SFDC Coder, First you need to create a pagereference, then set the parameters and then you set the currentpage: PageReference pRef =...
Read more >
APIM returning 404 when mandatory query parameter is ...
I have an APIM instance with an OpenAPI spec imported. One of the endpoints has a mandatory query parameter, with application-level ...
Read more >
Error "Invalid value for query parameter" and failed to send ...
Learn how to send a proper request with array query parameters with APIKit when invalid query parameter error occurs.
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