1.0.6 • Published 6 months ago

@novice1/api-doc-json-helper v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@novice1/api-doc-json-helper

JSON schemas helpers for @novice1/api-doc-generator enabling compatibility with @novice1/validator-json.

Installation

npm install @novice1/api-doc-json-helper

OpenAPI Specification

import { 
  OpenAPI 
} from '@novice1/api-doc-generator';
import { 
    OpenAPIJsonHelper 
} from '@novice1/api-doc-json-helper';
import routing from '@novice1/routing';

const openapi = new OpenAPI({ helperClass: OpenAPIJsonHelper });

const router = routing()
  .get({
    name: 'Main app',
    path: '/app',
    auth: true,
    tags: ['default'],
    parameters: {
        query: {
            $schema: 'http://json-schema.org/draft-07/schema#',
            type: 'object',
            properties: {
                version: {
                    type: 'string',
                    description: 'version number',
                    enum: ['1','2','3'],
                    default: '2',
                    nullable: true
                }
            }
        }
    }
}, function (req, res) {
    res.json(req.query.version)
});

// ...

Recommended

It's recommended to keep your schemas isolated from other properties of parameters.

import { 
  OpenAPI 
} from '@novice1/api-doc-generator';
import { 
    OpenAPIJsonHelper 
} from '@novice1/api-doc-json-helper';
import routing from '@novice1/routing';

const openapi = new OpenAPI({ 
    helperClass: OpenAPIJsonHelper, 
    helperSchemaProperty: 'schema' // recommended 
});

const router = routing()
  .get({
    name: 'Main app',
    path: '/app',
    auth: true,
    tags: ['default'],
    parameters: {
        // recommended
        schema: {
            query: {
                $schema: 'http://json-schema.org/draft-07/schema#',
                type: 'object',
                properties: {
                    version: {
                        type: 'string',
                        description: 'version number',
                        enum: ['1','2','3'],
                        default: '2',
                        nullable: true
                    }
                }
            }
        }
    }
}, function (req, res) {
    res.json(req.query.version)
});

// ...

Postman Specification

import { 
  Postman 
} from '@novice1/api-doc-generator';
import { 
    PostmanJsonHelper 
} from '@novice1/api-doc-json-helper';
import routing from '@novice1/routing';

const postman = new Postman({ 
    helperClass: PostmanJsonHelper, 
    helperSchemaProperty: 'schema' 
});

const router = routing()
  .get({
    name: 'Main app',
    path: '/app',
    auth: true,
    tags: ['default'],
    parameters: {
        schema: {
            query: {
                $schema: 'http://json-schema.org/draft-07/schema#',
                type: 'object',
                properties: {
                    version: {
                        type: 'string',
                        description: 'version number',
                        enum: ['1','2','3'],
                        default: '2',
                        nullable: true
                    }
                }
            }
        }

    }
}, function (req, res) {
    res.json(req.query.version)
});

// ...

References

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

1.0.0-alpha.1

6 months ago

1.0.0-alpha.0

6 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago