Skip to content

Instantly share code, notes, and snippets.

@Magnuti
Created November 12, 2024 09:48
Show Gist options
  • Save Magnuti/adf008e3b69a97d483db79eb09c5057b to your computer and use it in GitHub Desktop.
Save Magnuti/adf008e3b69a97d483db79eb09c5057b to your computer and use it in GitHub Desktop.
C# client generation from Swagger specification with NSwag on Docker

C# client generation from Swagger specification with NSwag on Docker

FROM mcr.microsoft.com/dotnet/sdk:8.0

# Install Node.js
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl
# We use Node.js 20 here, pick another version if you like that
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -yq nodejs build-essential

WORKDIR /app

# RUN npm init -y
RUN npm install -g nswag
docker build -t <your tag> .
docker run --volume "${PWD}:/app" generator npx nswag openapi2csclient /input:https://<base_url>/swagger/v1/swagger.json  /classname:GeneratedClient /namespace:Namespace /output:GeneratedClient.cs

After running the docker run command above you should now see a new file called GeneratedClient.cs.

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