# Umbraco Swagger schema can it auto-generate?

**URL:** <https://forum.umbraco.com/t/umbraco-swagger-schema-can-it-auto-generate/4774>\
**Category:** Questions\
**Tags:** extending, headless\
**Created:** [July 31, 2025, 10:25am UTC](https://forum.umbraco.com/t/umbraco-swagger-schema-can-it-auto-generate/4774 "2025-07-31T10:25:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastiaan](https://forum.umbraco.com/user_avatar/forum.umbraco.com/sebastiaan/32/279_2.png) [@sebastiaan](https://forum.umbraco.com/u/sebastiaan)\
**Post date:** [July 31, 2025, 10:25am UTC](https://forum.umbraco.com/t/umbraco-swagger-schema-can-it-auto-generate/4774/1 "2025-07-31T10:25:39Z")

</div>

I’m trying to get Umbraco to always generate the swagger schema when publishing the site for deployment. Has anyone else done this before? The idea is that this site is open and anyone can consume the schema to learn how to talk to the Umbraco instance.

I’ve managed to “hack” it together with an update to my `.csproj`, I added the `SwashBuckle.AspNetCode` NuGet package and added a target:

```xml
  <Target Name="GenerateSwagger" BeforeTargets="Publish">
    <!-- Generate swagger before publish to avoid file locking issues -->
    <PropertyGroup>
      <SwaggerOutputFile>wwwroot\swagger\delivery-swagger.json</SwaggerOutputFile>
    </PropertyGroup>

    <!-- Make sure the output directory exists -->
    <MakeDir Directories="wwwroot\swagger" />

    <!-- Run Swashbuckle CLI to generate swagger.json from built assembly -->
    <Exec Command="dotnet tool restore" />
    <Exec Command="dotnet swagger tofile --output &quot;$(SwaggerOutputFile)&quot; &quot;$(TargetDir)$(ProjectName).dll&quot; delivery" />

  </Target>

```

I don’t like it very much though, the `Exec Command` is annoying and feels unsustainable.

Is there a better way, without just enabling Swagger on production?

---

<div class="post-metadata">

**Author:** ![mistyn8](https://forum.umbraco.com/user_avatar/forum.umbraco.com/mistyn8/32/671_2.png) [@mistyn8](https://forum.umbraco.com/u/mistyn8)\
**Post date:** [August 5, 2025, 9:42pm UTC](https://forum.umbraco.com/t/umbraco-swagger-schema-can-it-auto-generate/4774/2 "2025-08-05T21:42:11Z")

</div>

> <https://stackoverflow.com/questions/73655243/how-to-generate-swagger-json-file-on-build-in-net-6-0/79652397#79652397>

Not sure if I’m reading this correct.. or it’s what you want.. but this suggests `swashbuckle` can/is using `Microsoft.Extensions.ApiDescription.Server`  
So you can just directly `OpenApiGenerateDocuments` might be a little less annoying than exec command?
