Skip to content

Swagger UI Could not resolve reference: Could not resolve pointer: After upgrading to SwashBuckle 6.3.0 with latest Swagger UI #7911

Open

Description

@PTAdvanced

I am experiencing an issue with the Swagger UI after upgrading from Swashbuckle 6.2.3 to 6.3.0.

After some investigation, the issue appears to be with Swagger UI and not the swagger.json document generated by Swashbuckle, hence my posting here.

When navigating to the Swagger UI, and expanding one of my methods, the "Example Value | Schema" section simply displays

"string"

At the top of the Swagger UI a message appears:

Resolver error at paths./request/requestsingledevicefromsite.post.requestBody.content.application/json.schema.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/Advanced.Cloud.Live.DomainModel.FireSystemDigitalTwin.Sychronisation.OutboundRequest.CQRS.RequestStatusOfSingleDeviceAtSite+Command does not exist in document

I browsed the generated swagger.json document, and looked for the "Advanced.Cloud.Live.DomainModel.FireSystemDigitalTwin.Sychronisation.OutboundRequest.CQRS.RequestStatusOfSingleDeviceAtSite+Command" reference.

I find it within the "paths" object, and see that the "$ref" property is pointing to the "Advanced.Cloud.Live.DomainModel.FireSystemDigitalTwin.Sychronisation.OutboundRequest.CQRS.RequestStatusOfSingleDeviceAtSite+Command" object.

"/request/requestsingledevicefromsite": {
  "post": {
	"tags": [
	  "FireSystemRequest"
	],
	"operationId": "RequestSingleDeviceFromSite",
	"requestBody": {
	  "content": {
		"application/json": {
		  "schema": {
			"$ref": "#/components/schemas/Advanced.Cloud.Live.DomainModel.FireSystemDigitalTwin.Sychronisation.OutboundRequest.CQRS.RequestStatusOfSingleDeviceAtSite+Command"
		  }
		}
	  }
	},
	"responses": {
	  "201": {
		"description": "Created"
	  },
	  "401": {
		"description": "Unauthorized",
		"content": {
		  "application/json": {
			"schema": {
			  "$ref": "#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails"
			}
		  }
		}
	  },
	  "400": {
		"description": "Bad Request",
		"content": {
		  "application/json": {
			"schema": {
			  "$ref": "#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails"
			}
		  }
		}
	  },
	  "403": {
		"description": "Forbidden"
	  }
	}
  }
},

Further down the swagger.json document, the reference is located, within the "components" / "schemas" section:

"Advanced.Cloud.Live.DomainModel.FireSystemDigitalTwin.Sychronisation.OutboundRequest.CQRS.RequestStatusOfSingleDeviceAtSite+Command": {
        "type": "object",
        "properties": {
          "SiteId": {
            "type": "string",
            "format": "uuid"
          },
          "NodeId": {
            "type": "integer",
            "format": "int32"
          },
          "Loop": {
            "type": "integer",
            "format": "int32"
          },
          "Address": {
            "type": "integer",
            "format": "int32"
          },
          "SubAddress": {
            "type": "integer",
            "format": "int32"
          }
        },
        "additionalProperties": false
      },

I downloaded the swagger.json generated by both the v6.2.3 and v6.3.0 Swashbuckle, performing a text diff on the 2 files. They are almost identical, apart from the HTTP 201 responses having a description of "Success" in the v6.2.3 document and "Created" in the v6.3.0 document.

I believe Swashbuckle recently upgraded from Swagger UI 4.1.3 to 4.5.0

Activity

  1. PTAdvanced commented on Mar 15, 2022

    @PTAdvanced
    Author

    The issue seems to be due to the + in the Schema ref name.

    I had configured the SwaggerGen as follows:

    services.AddSwaggerGen(c =>
    {
        c.CustomSchemaIds(s => s.FullName);
        ...
    }
    

    But modifying as:

    services.AddSwaggerGen(c =>
    {
        c.CustomSchemaIds(s => s.FullName.Replace("+", "."));
    }
    

    generates a schema $ref without the +

    Swagger UI did not seem to have an issue with the + in the $ref name previously.

  2. steveblomeley commented on Jul 9, 2022

    @steveblomeley

    Thanks for this, found the same issue in our fairly complex production API and this fixed it. Bizarrely, when I created a new bare bones webapi project, then added an endpoint that uses a nested ".Command" class for the request body, the Swagger page works fine using Swashbuckle 6.3.1, despite the underlying JSON schema specifying the "ParentClass+Command" format. Very odd.

  3. ClassyCircuit commented on Jul 27, 2022

    @ClassyCircuit

    Why isn't this fixed?!

  4. huesla commented on Dec 7, 2022

    @huesla

    Have the same issue with Swashbuckle.AspNetCore 6.4.0

  5. CodyBatt commented on Jan 13, 2023

    @CodyBatt

    Same with 6.5.0

  6. enzoeuler commented on Jan 26, 2023

    @enzoeuler

    Fixed with

    builder.Services.AddSwaggerGen(options => { options.CustomSchemaIds(type => type.ToString()); });

  7. Uleertel commented on Feb 27, 2023

    @Uleertel

    The issue seems to be due to the + in the Schema ref name.

    I had configured the SwaggerGen as follows:

    services.AddSwaggerGen(c =>
    {
        c.CustomSchemaIds(s => s.FullName);
        ...
    }
    

    But modifying as:

    services.AddSwaggerGen(c =>
    {
        c.CustomSchemaIds(s => s.FullName.Replace("+", "."));
    }
    

    generates a schema $ref without the +

    Swagger UI did not seem to have an issue with the + in the $ref name previously.

    We are using Swashbuckle.AspNetCore 6.5.0 on a .NET 7 project and I had to use this solution to avoid errors with Nested types. Is there a better fixe since this message that is one year old? thx.

  8. EhsanRezaei1981 commented on Jul 18, 2023

    @EhsanRezaei1981

    Unfortunately, the new version has an issue with the +
    Thanks for your investigation.

  9. Serotonindude commented on Oct 16, 2024

    @Serotonindude

    PUSH

  10. t-johnson commented on Dec 4, 2024

    @t-johnson

    Anyone know if the accepted workaround of using .Replace("+", ".") has any side effects??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions