domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.23k stars 1.31k forks source link

$ref siblings #2158

Open questionablequestion opened 3 years ago

questionablequestion commented 3 years ago

When adding custom properties/description/example to property which has reference, Swashbuckle doesn't generate those extra properties in original property but in the reference.

It generates like this:

"put": {
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "GenderType": {
                    "$ref": "#/components/schemas/GenderType"
                  },
...
"GenderType": {
        "enum": [
          1,
          2,
          3
        ],
        "type": "integer",
        "format": "int32",
        "description": "Testing",
        "x-enum-varnames": [
          "Unspecified",
          "Male",
          "Female"
        ]
      },

It should (?) generate like this:

        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "GenderType": {
                    "$ref": "#/components/schemas/GenderType",
                    "description": "Testing",
                  },

OpenAPI 3.1 claims to be able to have siblings with $ref. Main problem I'm trying to solve with this is when using openapi-generator it requires to have some additional properties alongside $ref to generate correct services.

Thanks

domaindrivendev commented 3 years ago

It’s always been my understanding that $ref, being a “reference” rather than a concrete schema, cannot have siblings. I’m surprised to hear OAI 3.1 allows it - can you point me to the part of the spec where this nuance is described?

questionablequestion commented 3 years ago

Hey @domaindrivendev , If I understand correctly, it's now possible. https://github.com/OAI/OpenAPI-Specification/releases/tag/3.1.0-rc0

And also there's test where there's description being used with ref https://github.com/OAI/OpenAPI-Specification/blob/main/tests/v3.1/pass/mega.yaml

To me as well, I see $ref being a reference rather than a concrete schema, like you said. I'm just looking for a way to add additional property for openapi-generator to be able to generate correct services. Is it possible now at all to add something like in my example? I tried using SchemaFilter but that's just changing reference object, not the one with $ref property.

questionablequestion commented 3 years ago

Is there any way of adding manually format and type to the request body properties under paths?