Code Monkey home page Code Monkey logo

api-schema-typescript-generator's People

Contributors

actions-user avatar dependabot[bot] avatar fedorov-xyz avatar mrzillagold avatar rukus67 avatar severecloud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-schema-typescript-generator's Issues

Добавьте подсказку для массивов в Response типах

Если бекенд принимает список через запятую, то есть массив строк. То генерируется тип который указывает что нужно прокидывать строку. Хотелось бы иметь хоть какую-ту подсказку через комментарии, что туда не просто строка прокидывается, а список через запятую или можно алиас.

/** Список элементов через запятую */
type ArrayAsString = string

Добавить мапу с названием метода, его параметрами и ответом

Сейчас типы в функцию вызова апи можно передавать только через дженерики. Хотелось бы иметь мапу с

method_name => method_request_params, (method_response1 | method_response2)

Зачем это нужно? Чтобы лучше контролировать строгость вызовов апи функций, если сделать дженерики обязательными, то люди смогут по ошибке передавать туда неверные параметры респонса, тем самым смысл типизации теряется. С мапой у тебя нет возможности ошибиться

Support minItems and maxItems schema properties

Generate tuple from minItems and maxItems:

minItems:

"propertyName": {
  "type": "array",
  "items": {
    "type": "string"
  },
  "minItems": 2
}
propertyName: [string, string, ...string[]];

maxItems:

"propertyName": {
  "type": "array",
  "items": {
    "type": "string"
  },
  "maxItems": 4
}
propertyName: [string, string, string, string];

Fix empty object type

Schema:

{
  "some_response": {
    "type": "object",
    "properties": {
      "response": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "integer"
          },
          "payload": {
            "type": "object"
          }
        },
        "required": [
          "user_id",
          "payload"
        ]
      }
    },
    "required": [
      "response"
    ]
  }
}

Current output:

export interface SomeResponse {
  user_id: number;
  payload: {};
}

Desired output:

export interface SomeResponse {
  user_id: number;
  payload: {
    [k: string]: unknown;
  };
}

Улучшение генерации констант для ошибок

В #41 предлагалось генерировать константы для ошибок.

Кажется более эффективным способом именования было бы использование кода ошибки в имени.

// было
export const API_ERROR_ACCESS = 15
// стало
export const API_ERROR_15_ACCESS = 15

У этого 2 бенефита:

  1. из имени ошибки было легко понятен и ее код и ее назначение
  2. иногда ты знаешь код ошибки, но не знаешь ее название (например увидел ошибку в девтулзах) в таком случае в новом именовании можно удобно воспользоваться автокомплитом, набрав API_ERROR_15_, без необходимости лазить по исходникам библиотеки

Кроме того, раз уж мы делаем брейкинг чейндж, можно сократить префикс до API_ERR_, чтобы уменьшить длину констант.

Add map with all methods, params and responses

export type RequestMap = {
  'groups.get': {
    params: GroupsGetParams;
    response: GroupsGetResponse | GroupsGetExtendedResponse;
  };
  'friends.get': {
    params: FriendsGetParams;
    response: FriendsGetResponse | FriendsGetFieldsResponse;
  };
}

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.