Giter Site home page Giter Site logo

geeklearningio / gl-swagger-generator Goto Github PK

View Code? Open in Web Editor NEW
6.0 7.0 1.0 615 KB

Jane - An OpenAPI Specification (formerly Swagger) Client Generator

License: MIT License

HTML 43.54% TypeScript 56.42% JavaScript 0.04% Batchfile 0.01%
swagger swagger-generator swagger-codegen nodejs handlebars

gl-swagger-generator's Introduction

Jane - An OpenAPI Specification (formerly Swagger) Client Generator

Jane is an OpenAPI Specification client generator. It uses templates written in Handlebars to generate a client code base in various languages.

The initial release is focused on providing a strong support of C# .NET Standard 1.3 and TypeScript.

Basic usage

To generate the API client, you need to give it two things:

  • The swagger json file of your API, defining all the available methods.
  • A configuration json file, specifying some options for your client generation.

A configuration file looks like this:

{
  "language": "typescript",
  "framework": "angular",
  "version": "1.5",
  "mode": "singleFile",
  "dependencies": {
  },
  "mediaTypesPriorities": {
    "application/json": 1
  },
  "ambientTypes": [
  ],
  "templateOptions": {
    "clientName": "MyAPIClient"
    "scheme": {
      "override": "https"
    },
    "generateInterface": true
  }
}

To generate your API client, just run swaggen with these options:

swaggen --outputPath ./outputpath --options ./swaggen-config.json --schema ./api-swagger.json

Languages available

You can generate the client in 2 languages for the moment. Here are the docs:

Documentation

Documentation is maintained in this repository wiki

Integration

Jane will have a CLI interface but is meant to be integrated in build pipeline such as gulp. A gulp plugin acting as a wrapper for Jane is already available. Please check the wiki for guidance.

Extensibility

One purpose of this generator is to allow you to write or customize templates if needed. Please check the wiki for more information.

The story behind this project

Read the Jane's story

gl-swagger-generator's People

Contributors

asiffermann avatar minuz avatar mvidailhet avatar sandorfr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

minuz

gl-swagger-generator's Issues

Mocks support

Features :

  • Timeout
  • Status and Response provided par swagger
  • Custom status and response

Unable to generate Dictionary property with Angular template

I have the following definition in my Swagger file:

"ClaimsSet": {
    "type": "object",
    "properties": {
        "claims": {
            "type": "object",
            "additionalProperties": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        }
    }
}

With the .NET generator, it is properly mapped to a Dictionary<string, string[]>, but with the Angular one, the type is not resolved.
So the generated TypeScript ends with that (and cannot be compiled):

/*ClaimsSet*/
export interface ClaimsSet  {

    /**/
    claims: ;

}

Is it related to generics' support?

Remove default content/media types

Currently, if not consumes or produces media types are specified, the generator will add "application/json". While this might come handy, it actually makes a wild assumption and hides a incomplete swagger definition.

We did this in the first place because we faced such definitions with some customer's swagger definitions.

This should be removed in favor of a guidance about how to use custom swagger visitor to fix the definition prior to generation.

[CSharp] Unsupported Media Type

Currently if the server return an unexpected media type, the client will throw a NullReferenceException. This should return something like a UnexpectedMediaTypeApiException and provide access to the body for logging and debugging purpose.

Angular 4 template : generateInterface doesn't work

If I set the generateInterface option to true in the templateOptions, the Interface file is not generated.
In the client file, I have "implements IMyService", but the interface IMyService is not generated.

[Csharp] Advanced Polly Support

More features could be built around polly support.

  • multiple policies which selection would be done base on selectors
    • tags,
    • operation name / path fragments
    • security definitions
  • automatically Wrap matched policies together based on priorities then order

[Templates] Override version

For the project generation flavors which are likely to be published and consumed as package we should provide a way to set the version.

Api method with optional parameter still generates client with mandatory parameter

Writting an api controller action like the following:

        [HttpGet("control")]
        [ProducesResponseType(typeof(Response<DataTransfer.ControlRegister.Control[]>), 200)]
        public async Task<IActionResult> ControlGetAll(bool includeParameters = false)
        {
            var rules = await this.policyService.GetAllControlsAsync(includeParameters);
            return this.Maybe<DataTransfer.ControlRegister.Control[]>(rules.Select(DataTransfer.ControlRegister.Control.From).ToArray());
        }

Should have the parameter includeParameters as optional, but the generated code still requires that parameter to get the correct response.

Typescript Language Pack

Todo :

  • camlCaseFilters
  • languageFilter (without generic support)

Nice to have (lot of work to be done)

  • genericFilter

Angular 2 template

  • Language filter
  • SDK
    • Media formatters
      • Json
      • FormData
    • Base client
      • Basic request support
      • Cancellation support
      • Polly support
  • Template.json
  • Typing partials : _type and _typeCore
  • Definition template
  • Client template

Full support for $ref and external $refs

#5 had to be reverted because it had too much side effects. Investigating the root cause of this, I think we need to postpone this as it requires a bit of design to bring a full support for this part of the specification.

Inconsistent line endings in generated file

Original issue : geeklearningio/gulp-swagger-generator#32

Hi,

I'm using gulp-swagger-generator with the template typescript-angular, and it works like expected, but the generated file has inconsistent line endings.

It seems that Unix line endings (LF) are used in the interfaces and in the client mock, while in the real client there are Windows line endings (CR LF).

Though it is not a big issue, it would be nice to fix it in a next release! :)

Thanks for the great work!

Api with Parameter of type DateTime generates parameter with type DateTimeOffset

Hi guys,

On my api method I have a parameter type of DateTime, on the generated client it changes to DateTimeOffset.

Normally that wouldn't be a problem.
However, I have a generic implementation such as

   var convertedValue = Convert.ChangeType(paramValue, parameter.ParameterType, System.Globalization.CultureInfo.InvariantCulture);
   parameterValues.Add(convertedValue);

And it throws exception because DateTimeOffset does not implement IConvertible

The type should be a developer's choice instead of being enforced by the generator.
Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.