Download the PHP package jpnut/laravel-typescript-codegen without Composer

On this page you can find all versions of the php package jpnut/laravel-typescript-codegen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-typescript-codegen

Laravel Typescript Codegen

StyleCI GitHub Workflow Status License

This package allows you to generate a typescript schema by getting type information from your Laravel routes and controllers.

For example, you can turn this:

into this:

Installation

You can install the package via composer:

Usage

To generate the schema, use the generate command with the desired file location as the only argument:

In order to generate a function for a given route, you must add the @code-gen tag to the doc-block of the controller method which is used by the route.

This will attempt to get return type information from the doc-block @return tag, or, if that is not present, the return type of the method. If there is no type information present, the return type defaults to any.

Scalar types (e.g. string, int, etc.) will be transformed into the appropriate typescript scalar (e.g. string, number, etc.). If the method returns a class, then the class will be transformed into an interface containing all the public properties of the class.

For example, given the following class:

the generated interfaces will look as follows:

Working with Requests

Generating types for request properties (e.g. the request body) is slightly more involved. The request must implement JPNut\CodeGen\Contracts\CodeGenRequest, and should be resolvable by Laravel's Service Container (typically this means extending Illuminate\Foundation\Http\FormRequest). You should then create and tag methods which create a mapping from the request to the desired type. For example:

In this case the generated interfaces and methods would look similar to the following

Note that the body parameter is serialised for the request automatically. You can change this or serialise other properties by modifying the request_properties config property.

Ignoring Properties

You may have public properties which you do not wish to generate types for. Properties can be ignored by including the @code-gen-ignore tag:

Using a custom stub

By default, this package will generate the schema using a stub. This stub contains a request method which is a wrapper for the fetch api and returns a promise containing the deserialised response data.

If you wish to customise this stub, you should first publish the config file

This will also create a copy of the default stub file located at resource_path('stubs/typescript-codegen-schema.stub'). This file will then be used to generate the schema.

Using a custom interface/method writer

You may wish to change the generated output for interfaces and methods. For example, you might decide to rename the request method within the stub. In this case, you should create your own Interface or Method writer and replace the included writer(s) with your version in the writers array of the config. The writer(s) should implement the JPNut\CodeGen\Contracts\InterfaceWriterContract and JPNut\CodeGen\Contracts\MethodWriterContract interfaces respectively.

Override class resolution

You may wish to resolve certain classes into literals. This is particularly useful for classes which are not part of your codebase. To achieve this, include the class in the default_literals array of the config. The class name should be the key, and the value should be an array of php literal types (e.g. string, int etc.)

For example, by default this package converts the Carbon\Carbon class into a string. This is necessary since the return type of the jsonSerialize method of the class is string|array.

Testing

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-typescript-codegen with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
ext-json Version *
illuminate/contracts Version ^8.0
illuminate/routing Version ^8.0
illuminate/support Version ^8.0
phpdocumentor/reflection-docblock Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jpnut/laravel-typescript-codegen contains the following files

Loading the files please wait ....