Giter Site home page Giter Site logo

thwint / apikana Goto Github PK

View Code? Open in Web Editor NEW

This project forked from swisspost/apikana

0.0 1.0 0.0 2.88 MB

Integrated tools for REST and Messaging API design - アピ

License: Apache License 2.0

JavaScript 99.92% TypeScript 0.07% CSS 0.01% Shell 0.01%

apikana's Introduction

A swisspush project

Apikana

Integrated tools for REST and Messaging API design.

Apikana combines the following tools to facilitate the authoring of contract-first REST APIs:

It basically generates formal schemas and documentation from a mixed swagger/typescript definition that is easy to author and maintain.

It supports also java:

Serialization/Deserialization of java objects:

  • The implementation needs a jackson module for serializing and deserializing the objects as described here.

Usage

Create a new API project

Install apikana npm install -g apikana. Run apikana init.

This starts an interactive wizard that lets you define the main aspects of the API project.

Use as a global tool

When apikana start is executed, it looks in src/openapi for a file named api.yaml. This is an OpenAPI 2.0 file defining the REST API. In the definitions section a $ref can be given which references typescript file(s) defining the data models. $ref can be a comma or newline separated string or an array thereof. The models should be defined as typescript export interfaces.

At the end, the dist directory contains the json schemas and a complete HTML documentation of the API. Just open a browser at http://localhost:8333.

src/openapi/api.yaml

paths:
  /sample/users:
    get:
      operationId: getUser
      responses:
        200:
          description: ok
          schema:
            $ref: "#/definitions/User"
definitions:
  $ref: ../ts/user.ts

src/ts/user.ts

export interface User {
    id: number
    firstName: string // The given name
    lastName: string // the family name @pattern [A-Z][a-z]*
    age?: number
}

Annotations like @pattern can be used to specify more precise constraints. They correspond to the JSON Schema validation keywords.

The src/style directory can contain css and image files which can be used to style the generated HTML document.

The gen directory contain the generated files relative to the enabled plugins. This files can be overwritten by defining a templates directory in the root folder of the project using the following directory structure: root_directory/templates/plugin_name/gen/plugin_name/filename.ext where:

  • root_directory is the root directory of the project,
  • plugin_name is the plugin name (for example maven or dotnet) and
  • filename.ext is the file to copy in the gen directory (for example pom.xml or api.csproj).

Matching filenames will be overwritten. All others will be copied in the gen directory.

Use as a devDependency

Instead of being globally installed, apikana can also be defined as a devDependency of a project. A sample configuration would look like:

{
  "name": "My API project",
  "scripts": {
    "start": "apikana start src"
  },
  "devDependencies": {
    "apikana": "0.7.1"
  }
}

Then simply run npm run start.

Development

Development is done within feature branches in forked repositories. When ready it gets merged to swisspush/develop via merge request (at best including review).

Testing

You can run tests using npm test within projects root directory.

Releasing

Releasing is done by updating the version with npm version patch|minor|major and merging develop into master. Then Travis CI will notice the changes on master and perform the release.

Publishing

To publish to npmjs.org, environment variable NPM_TOKEN must be set. You can accomplish this by executing npm login locally and afterwards extracting corresponding value from ~/.nmprc.

apikana's People

Contributors

nidi3 avatar lbovet avatar mattiamato avatar hiddenalpha avatar naamor avatar thwint avatar

Watchers

James Cloos avatar

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.