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.

Support OAS 3 - Operation Parameter Serialization for Complex Objects

See original GitHub issue

OpenAPI 3.0 supports arrays and objects in operation parameters (path, query, header, and cookie) and lets you specify how these parameters should be serialized. The serialization method is defined by the style and explode keywords:

  • style defines how multiple values are delimited. Possible styles depend on the parameter location – path, query, header or cookie.
  • explode (true/false) specifies whether arrays and objects should generate separate parameters for each array item or object property.

Details: https://swagger.io/docs/specification/serialization/

NSwag will need to understand when complex objects are in an operation parameter and apply the “Simple” style and set explode to “false” in the resultant spec. There will also need to be some configuration options for users to select different “style” and “explode” defaults.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
more-urgent-jestcommented, Nov 9, 2022

I am trying define a query parameter using a schema like so:

    "/path/to/here": {
      "get": {
        "summary": "get to here",
        "responses": {
          "200": {
            "$ref": "#/components/responses/Response"
          }
        },
        "operationId": "get-to-here",
        "description": "Get to here",
        "parameters": [
          {
            "schema": {
              "$ref": "#/components/schemas/Request"
            },
            "in": "query",
            "name": "Request",
            "description": "Request for here",
            "required": true,
            "explode": true
          }
        ],
        "tags": [
          "Here"
        ]
      }
    }

but when the C# client is built from this via an Open API service reference using the output is:

        public virtual async Task<Response> GetToHereAsync(Request request, CancellationToken cancellationToken)
        {
            if (request == null)
                throw new System.ArgumentNullException("request");

            var urlBuilder_ = new System.Text.StringBuilder();
            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/path/to/here?");
            foreach (var item_ in Request.AdditionalProperties) { urlBuilder_.Append(System.Uri.EscapeDataString(item_.Key) + "=").Append(System.Uri.EscapeDataString(ConvertToString(item_.Value, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); }
            urlBuilder_.Length--;

why is this only exploding the additional properties and doing so on the type rather than the parameter which doesn’t compile since the Request is not a static type?

0reactions
more-urgent-jestcommented, Nov 10, 2022

ah, jeez, changing the name property to “name”: “request” fixes that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameter Serialization
OAS 3 This guide is for OpenAPI 3.0. Parameter Serialization. Serialization means translating data structures or object state into a format that can...
Read more >
OpenAPI Specification - Version 3.0.3
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to HTTP APIs which allows both humans and computers to discover and understand ...
Read more >
OpenAPI Tips - Query Parameters & Serialization
OpenAPI supports serialization of arrays and objects in all operation parameters (path, query, header, cookie). The serialization rules are based on a ...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & ...
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & ...
Describes how a specific property value will be serialized depending on its type. See Parameter Object for details on the style property. The ......
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