0.37.2 • Published 10 days ago

schema-openapi v0.37.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

schema-openapi

Declarative pipe-able API for OpenAPI specification construction using @effect/schema.

:construction: Under development.

Installation

pnpm add schema-openapi

OpenAPI schema derivation from @effect/schema

The heart of this library is a compiler that derives an OpenAPI schema from an effect-ts Schema declaration. Generated schema can be adjusted using annotations. Following annotations are supported:

  • DescriptionAnnotation
  • JSONSchemaAnnotation

Please, consult the schema API documentation.

API documentation

Top-level

Operations

General

Top-level

import * as OpenApi from 'schema-openapi';

openAPI

Use openAPI('Name of you API', 'version') to initialize a new openAPI specification.

Available setters: info

info

Sets info section of the specification.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.info(OpenApi.description('This is my awesome API'))
);

Available setters: description, license, server

Setter of: openAPI

license

Sets a license in the info section.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.info(
    OpenApi.description('This is my awesome API'),
    OpenApi.license('MIT', 'http://license-url')
  )
);

Setter of: info

server

Sets a server section.

OpenApi.openAPI('My API', '2.0.1', OpenApi.server('http://my-production.com'));

Available setters: description, variable

Setter of: openAPI

variable

Adds a variable to the server section.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.server(
    'http://my-production:{port}.com',
    OpenApi.variable('port', '3000')
  )
);

Available setters: description, enum

Setter of: server

enum

Adds possible values of a server variable.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.server(
    'http://my-production:{port}.com',
    OpenApi.variable('port', '3000', OpenApi.enum('3000', '3001'))
  )
);

Setter of: variable

Operations

path

Add a new path.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.string, 'Returns a pet')
    )
  ),
  OpenApi.path(
    '/note',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.string, 'Returns a note')
    )
  )
);

Available setters: description, operation

Setter of: openAPI

operation

Set operation. Method name can be one of get, put, post, delete, options, head, patch, trace.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.string, 'Returns a pet')
    ),
    OpenApi.operation(
      'post',
      OpenApi.jsonRequest(S.struct({ value: S.number })),
      OpenApi.jsonResponse('200', S.string, 'Returns a pet')
    )
  )
);

Available setters: description, parameter, jsonResponse, jsonRequest, deprecated, operationId

Setter of: path

parameter

Set a parameter. The (second) in parameter is one of query, header, path, cookie. If the in is path, required must be set for the parameter.

Set the operation id using OpenApi.operationId.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.struct({ value: S.number }), 'Returns a pet')
      OpenApi.parameter('id', 'path', S.number, OpenApi.required),
      OpenApi.parameter('name', 'query', S.string),
      OpenApi.operationId('getPet')
    )
  )
);

Setter of: operation

parameter

Set a parameter. The (second) in parameter is one of query, header, path, cookie. If the in is path, required must be set for the parameter.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.struct({ value: S.number }), 'Returns a pet')
      OpenApi.parameter('id', 'path', S.number, OpenApi.required),
      OpenApi.parameter('name', 'query', S.string),
    )
  )
);

Available setters: required, description, deprecated, allowEmptyValue

Setter of: operation

tags

Set tags for an operation.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.struct({ value: S.number }), 'Returns a pet')
      OpenApi.parameter('id', 'path', S.number, OpenApi.required),
      OpenApi.parameter('name', 'query', S.string),
      OpenApi.tags('Pets')
    )
  )
);

Setter of: operation

allowEmptyValue

Configures the parameter.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse('200', S.struct({ value: S.number }), 'Returns a pet')
      OpenApi.parameter('id', 'path', S.number, OpenApi.required),
      OpenApi.parameter('name', 'query', S.string, OpenApi.allowEmptyValue),
    )
  )
);

Setter of: parameter

jsonRequest

Set the JSON request body specification.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'post',
      OpenApi.jsonResponse(
        '200',
        S.struct({ value: S.number }),
        'Returns a pet'
      ),
      OpenApi.jsonRequest(S.struct({ value: S.number }))
    )
  )
);

Available setters: description, required

Setter of: operation

jsonResponse

Set the JSON response specification. The (2nd) schema parameter can be either undefined or Schema<R, I, O>. If it's set to undefined, the content field of the response is ommited.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'post',
      OpenApi.jsonResponse(
        '200',
        S.struct({ value: S.number }),
        'Returns a pet'
      )
    )
  )
);

Available setters: description, responseHeaders

Setter of: operation

responseHeaders

Set the response headers.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'post',
      OpenApi.jsonResponse(
        '200',
        S.struct({ value: S.number }),
        'Returns a pet',
        OpenApi.responseHeaders({ 'My-Header': S.string })
      )
    )
  )
);

Setter of: jsonResponse

General

description

Sets a description field.

Setter of: info, operation, parameter

summary

Sets a summary field.

Setter of: path, operation

deprecated

Sets the spec as deprecated.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'get',
      OpenApi.jsonResponse(
        '200',
        S.struct({ value: S.number }),
        'Returns a pet'
      ),
      OpenApi.parameter('name', 'query', S.string, OpenApi.deprecated),
      OpenApi.deprecated
    ),
    OpenApi.deprecated
  )
);

Setter of: parameter, operation, parameter

required

Sets the parameter as required.

OpenApi.openAPI(
  'My API',
  '2.0.1',
  OpenApi.path(
    '/pet/{id}',
    OpenApi.operation(
      'post',
      OpenApi.jsonRequest(S.struct({ value: S.number }), OpenApi.required),
      OpenApi.jsonResponse(
        '201',
        S.struct({ value: S.literal('success') }),
        'Returns a pet'
      ),
      OpenApi.parameter('name', 'path', S.string, OpenApi.required)
    )
  )
);

Setter of: parameter, jsonRequest

0.37.2

10 days ago

0.37.1

17 days ago

0.37.0

20 days ago

0.36.0

24 days ago

0.35.1

24 days ago

0.35.0

25 days ago

0.34.6

1 month ago

0.34.5

1 month ago

0.34.4

1 month ago

0.34.3

1 month ago

0.34.2

1 month ago

0.34.1

2 months ago

0.34.0

2 months ago

0.33.7

2 months ago

0.33.6

2 months ago

0.33.5

2 months ago

0.33.4

2 months ago

0.33.3

2 months ago

0.33.2

2 months ago

0.33.1

2 months ago

0.33.0

2 months ago

0.32.3

2 months ago

0.32.2

2 months ago

0.32.1

2 months ago

0.32.0

2 months ago

0.31.2

3 months ago

0.31.1

3 months ago

0.31.0

3 months ago

0.30.1

3 months ago

0.30.0

3 months ago

0.29.2

3 months ago

0.29.1

3 months ago

0.29.0

4 months ago

0.28.4

4 months ago

0.28.1

4 months ago

0.28.3

4 months ago

0.28.2

4 months ago

0.28.0

4 months ago

0.27.1

4 months ago

0.27.0

4 months ago

0.26.3

5 months ago

0.26.2

5 months ago

0.26.1

5 months ago

0.26.0

5 months ago

0.25.0

5 months ago

0.20.1

6 months ago

0.20.0

6 months ago

0.19.0

7 months ago

0.19.1

7 months ago

0.17.0

7 months ago

0.23.0

5 months ago

0.21.0

6 months ago

0.18.0

7 months ago

0.24.1

5 months ago

0.24.0

5 months ago

0.22.0

6 months ago

0.15.4

7 months ago

0.15.5

7 months ago

0.15.6

7 months ago

0.15.7

7 months ago

0.15.8

7 months ago

0.15.9

7 months ago

0.15.0

7 months ago

0.15.1

7 months ago

0.15.2

7 months ago

0.15.3

7 months ago

0.16.0

7 months ago

0.16.1

7 months ago

0.11.0

9 months ago

0.13.0

8 months ago

0.0.32

12 months ago

0.0.33

11 months ago

0.1.0

11 months ago

0.3.0

10 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.9.0

10 months ago

0.5.0

10 months ago

0.1.3

11 months ago

0.7.0

10 months ago

0.12.0

9 months ago

0.12.1

9 months ago

0.14.0

8 months ago

0.12.2

9 months ago

0.14.1

8 months ago

0.12.3

9 months ago

0.12.4

9 months ago

0.12.5

9 months ago

0.10.0

9 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.8.1

10 months ago

0.2.7

11 months ago

0.8.0

10 months ago

0.6.2

10 months ago

0.2.6

11 months ago

0.8.3

10 months ago

0.8.2

10 months ago

0.2.3

11 months ago

0.4.0

10 months ago

0.2.2

11 months ago

0.6.1

10 months ago

0.2.5

11 months ago

0.6.0

10 months ago

0.2.4

11 months ago

0.0.31

12 months ago

0.0.30

12 months ago

0.0.29

12 months ago

0.0.28

12 months ago

0.0.27

12 months ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago