livingsocial / swagger_yard

Swagger-UI compliant JSON generated from YARD. For RESTful Rails apps.
MIT License
51 stars 28 forks source link

Parameter serialization options #60

Open bshamblen opened 5 years ago

bshamblen commented 5 years ago

The OpenAPI 3.0 specification provides the ability to specify a parameter serialization style for objects, but I can't find a way to implement the "style": "deepObject" option when defining a parameter that's an object.

For example, the JSON-API specification indicates that sparse fieldset and pagination parameters should be sent in the following format:

/api/v1/examples?page[number]=1&page[size]=25

In order to accomplish this, I would define a parameter like this:

# @parameter page  [object<number:integer,size:integer>] Sets the current page and the page size

When I run that through SwaggerYard, the parameter structure that shows up in the JSON file looks like this:

{
  "name": "page",
  "description": "Sets the current page and the page size",
  "required": false,
  "in": "query",
  "schema": {
    "type": "object",
    "properties": {
      "number": {
        "type": "integer"
      },
      "size": {
        "type": "integer"
      }
    }
  }
}

In order for Swagger UI to serialize the object in the format that's necessary, I need to be able to specify the "style": "deepObject" option for the parameter above, but I don't see anything in the SwaggerYard documentation that would allow me to do it.

Is there a way for me to specify this option? Thanks for your help.

nicksieger commented 5 years ago

Looks like I missed that option when adding OpenAPI 3 support recently. Would you mind submitting a PR? The relevant area would probably be here in the OpenAPI class. Is that an option that needs to have configuration, or can we get by always setting "style": "deepObject" when the schema type for a parameter has properties?

bshamblen commented 5 years ago

It looks like there are 4 possible values for the style option. Can you let me know if there’s a specific way you’d like the options handled. I’ll submit a PR early next week. Thanks.