Is there a way to expand references in Swashbuckle to provide inline schemas?

Viewed 80

Is there a mechanism in Swashbuckle that can prevent definitions from being created with referencing to them in parameters/responses/etc.?

By default, you might get a path that looks like this:

"/profile": {
  "get": {
    "summary": "Get my profile details.",
    "produces": [
      "application/json",
    ],
    "parameters": [],
    "responses": {
      "200": {
        "description": "Success",
        "schema": {
          "$ref": "#/definitions/ProfileModel"
        }
      }
    }
  }
}

But what I'd like is for it to expand the schema inline like this:

"/profile": {
  "get": {
    "summary": "Get my profile details.",
    "produces": [
      "application/json",
    ],
    "parameters": [],
    "responses": {
      "200": {
        "description": "Success",
        "schema": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "description": "id"
            },
            "firstName": {
              "type": "string",
              "description": "firstName"
            },
            "surname": {
              "type": "string",
              "description": "surname"
            },
            "emailAddress": {
              "type": "string",
              "description": "emailAddress"
            }
          }
        }
      }
    }
  }
}

I reviewed this StackOverflow question and I don't think it's what I'm looking for (or maybe misinterpreted).

Taken a look through the Swashbuckle README to understand its capabilities but coming up short. Any help here would be most appreciated.

For additional context, looking at the Swashbuckle PDF documentation in section 1.7, I essentially want to bypass or revert the action they describe as

automatically generating a corresponding schema for user-defined reference types and reference the definition via the $ref keyword.

1 Answers

Digging into the codebase a little, it looks like it's not possible at the moment.

However, you can create a custom ISchemaGenerator from the one in source and alter the GenerateConcreteSchema method under the DataType.Object case to not return as reference and this solves the issue.

Related