0.0.127 • Published 5 months ago

@pentops/jsonapi-jdef-ts-generator v0.0.127

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

jsonapi-jdef-ts-generator

Generate types and API client functionality from a api.json file served by your registry.

Getting Started

Install @pentops/jsonapi-jdef-ts-generator as a dev dependency and @pentops/jsonapi-request as a dependency (if you are going to use the generated API client).

Configuration

Create a .jdef_config.js file in your project root. This file should default export a configuration object:

const EXCLUDED_NAMESPACES = ['service', 'topic'];

export default {
  typeOutput: {
    fileName: 'index.ts',
    directory: './packages/types/generated',
    importPath: '@yourcompany/types',
  },
  clientOutput: {
    fileName: 'index.ts',
    directory: './packages/api-client/generated',
  },
  client: {
    // Remove the excluded namespaces from the method name and camelCase the result
    methodNameWriter: (method) =>
      method.fullGrpcName
        .split(/[./]/)
        .filter((s) => s && !EXCLUDED_NAMESPACES.includes(s.toLowerCase()))
        .map((s, i) => (i === 0 ? s : s[0].toUpperCase() + s.slice(1)))
        .join(''),
  },
  types: {
    enumType: 'enum',
    // Remove the excluded namespaces from the interface/enum name and camelCase the result
    nameWriter: (x) =>
      x
        .split('.')
        .filter((s) => s && !EXCLUDED_NAMESPACES.includes(s.toLowerCase()))
        .map((s) => s?.[0]?.toUpperCase() + s?.slice(1))
        .join(''),
  },
  jsonSource: {
    path: 'api.json',
  },
};

Source Configuration

You can specify the source of the api.json file using the jsonSource property.

  • The path property should be the path to a local api.json file.
  • The service property should be set for a remote api.json file. It should be an object with the following properties:
    • url: The URL of the remote api.json file.
    • auth: An optional object containing a token if required.

See the configuration definitions for more information.

Generating Types

Add a script to your package.json to run the generator.

{
  "scripts": {
    "generate-types": "jdef-ts-generator"
  }
}

Peer Dependencies

You will need to have @pentops/jsonapi-request installed as a dependency if you're going to use the generated API client.

0.0.117

11 months ago

0.0.116

11 months ago

0.0.115

1 year ago

0.0.119

10 months ago

0.0.118

11 months ago

0.0.127

5 months ago

0.0.126

5 months ago

0.0.125

5 months ago

0.0.120

10 months ago

0.0.124

5 months ago

0.0.123

6 months ago

0.0.122

10 months ago

0.0.121

10 months ago

0.0.114

1 year ago

0.0.113

1 year ago

0.0.112

1 year ago

0.0.111

1 year ago

0.0.110

1 year ago

0.0.109

1 year ago

0.0.108

1 year ago

0.0.107

1 year ago

0.0.106

1 year ago

0.0.105

1 year ago

0.0.104

1 year ago

0.0.103

1 year ago

0.0.102

1 year ago

0.0.101

1 year ago

0.0.100

1 year ago

0.0.95

1 year ago

0.0.96

1 year ago

0.0.97

1 year ago

0.0.98

1 year ago

0.0.99

1 year ago

0.0.93

1 year ago

0.0.94

1 year ago

0.0.84

1 year ago

0.0.40

1 year ago

0.0.85

1 year ago

0.0.41

1 year ago

0.0.86

1 year ago

0.0.42

1 year ago

0.0.87

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.89

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.80

1 year ago

0.0.81

1 year ago

0.0.82

1 year ago

0.0.83

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.73

1 year ago

0.0.74

1 year ago

0.0.30

1 year ago

0.0.75

1 year ago

0.0.31

1 year ago

0.0.76

1 year ago

0.0.32

1 year ago

0.0.77

1 year ago

0.0.33

1 year ago

0.0.78

1 year ago

0.0.34

1 year ago

0.0.79

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.20

1 year ago

0.0.65

1 year ago

0.0.21

1 year ago

0.0.66

1 year ago

0.0.22

1 year ago

0.0.67

1 year ago

0.0.23

1 year ago

0.0.68

1 year ago

0.0.24

1 year ago

0.0.69

1 year ago

0.0.25

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.59

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.10

1 year ago

0.0.55

1 year ago

0.0.11

1 year ago

0.0.56

1 year ago

0.0.12

1 year ago

0.0.57

1 year ago

0.0.13

1 year ago

0.0.58

1 year ago

0.0.14

1 year ago

0.0.90

1 year ago

0.0.91

1 year ago

0.0.92

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.9

1 year ago

0.0.49

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago