'swagger.json doesn't update according to code changes on deployment

I have a problem with the Swagger UI (or the swagger.json file specifically) not being updated when I deploy my code to the server. If I go to the Swagger UI page, the server gives me an old version of the docs.

Everything works locally, so the problem must be related to the deployment process or IIS.

Any ideas on what might cause this, and how I can fix it?

I have tried the following:

  • Deleted the XML-comments file generated by Web API and regenerated it
  • Restarted the IIS site on the server
  • Deleted all files in the site and redeployed
  • Numerous redeployments

(using Swashbuckle for .NET Framework, not .NET Core)



Solution 1:[1]

You may need to clear your browser's cache. I just encountered this problem and solved by clear my browser's cache

Solution 2:[2]

In my case, the set attribute was as private, after that updated the swagger without a problem.

Before: public string Street { get; private set; }

After: public string Street { get; set; }

Hope this helps = )

Solution 3:[3]

In my case the issue was 2 models had 2 submodels with same name. And properties of submodels were not getting updated.

public class ModelA {
    public static SubmodelX {
        int i;
    }
    ModelA.SubmodelX x;
}
public class ModelB {
    public static SubmodelX {
        int i;
    }
    ModelB.SubmodelX x;
}

properties inside both SubmodelX do not get updated correctly. Renaming them to the following fixed it.

public class ModelA {
    public static ModelASubmodelX {
        int i;
    }
    ModelA.ModelA SubmodelX x;
}
public class ModelB {
    public static ModelBSubmodelX {
        int i;
    }
    ModelB.ModelBSubmodelX x;
}

Swagger version: 2.9.2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wagner
Solution 2 Milton Quirino
Solution 3 Rakesh Malik