GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - MTSWebServices/ApiCodeGenerator: Generate code from Swagger, OpenApi or AsyncApi documents.

BranchesTags
Open more actions menu

Latest commit

 

History

65 Commits
65 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.vscode
.vscode
 
 
schemas
schemas
 
 
src
src
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
ApiCodeGenerator.ruleset
ApiCodeGenerator.ruleset
 
 
ApiCodeGenerator.sln
ApiCodeGenerator.sln
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Directory.Build.props
Directory.Build.props
 
 
Directory.Build.targets
Directory.Build.targets
 
 
GitVersion.yml
GitVersion.yml
 
 
LICENSE
LICENSE
 
 
README.MD
README.MD
 
 
README_RU.MD
README_RU.MD
 
 

Repository files navigation

Read in Russian

NuGet Version GitHub License Codacy Badge

How to install

  1. Add the ApiCodeGenerator.MSBuild package in your project.
  2. Add a file describing the API in formats like: Swagger 2.0, OpenApi 3.0, JsonSchema, AsyncApi 2.0 to your project.
  3. Add a file with the same name but with the .nswag extension to your project and fill it out.
  4. Rebuild the project.

NSwag File Format

To use hints while editing the file, set schema https://raw.githubusercontent.com/MobileTeleSystems/ApiCodeGenerator/refs/heads/dev/schemas/nswag.json .

The NSwag format consists of files that store settings for the NSwagStudio application, which can be used to configure standard NSwag generators. The file has the following structure:

{
  "documentGenerator": {
    "fromDocument": {
      "json": "$(InputJson)",
      "url": "http://basketService/swagger/v1/swagger.json"
    }
  },
  "codeGenerators": {
    "openApiToCSharpClient": {}
  }
}

Since the settings for various APIs mostly overlap, to reduce duplication, you can move the settings for preprocessors and generators to a base.nswag file (the file name can be changed via settings). The file has the same structure, and the codeGenerators block can specify several generators (the settings for the selected generator will be applied to the target file). The file is searched in all higher-level directories starting from the NSwag file being generated.

Document Generation

The documentGenerator block specifies the rules for obtaining the document based on which the code will be generated. For generation from documents in Swagger 2.0, OpenApi 3.0, or AsyncApi 3.0 formats, you need to fill in the fromDocument property. For generation from a JsonSchema document, use the jsonSchemaToOpenApi property.

In fromDocument, the json property specifies the path to the file or a string containing the document itself (the example uses a variable containing the file path). The url property specifies the address from which the file can be downloaded. If the json property is not filled, the document will be downloaded from this address. Both properties can accept paths to YAML files.

If paths are not specified in fromDocument or the block itself is absent, the json property will be set to the path from OpenApiReference.

Additionally, fromDocument can have a preprocessors property to connect handlers that preprocess the document before passing it to the code generator.

Code Generation

The codeGenerators block specifies the generator that will be used to generate the code. The property name is the generator's name, and the value is the settings for the selected generator.

Available generators:

  • asyncApiToCSharpAmqpService - C# client for the RabbitMQ.Client 5 library.
  • openApiToCSharpClient - generates a C# client for accessing the API.
  • openApiToCSharpController - generates a controller and service interface for implementing the controller's logic.
  • openApiToRefitClient - generates an interface for accessing the API using the Refit library. Requires the ApiCodeGenerator.OpenApi.Refit package.

Read about generator options:

  • for all listed generators.
  • for C# code generators
  • for openApiToCSharpClient

Additionally, for all generators, the library adds the replaceNameCollection setting for replacing characters in property names.

"replaceNameCollection": {
  "@": "_" // Replace @ with _ in names
}

About

Generate code from Swagger, OpenApi or AsyncApi documents.

Resources

Readme
Apache-2.0 license

Contributing

Contributing
Activity
Custom properties

Stars

24 stars

Watchers

5 watching

Forks

1 fork
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.