New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

oacodesamplegenerator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oacodesamplegenerator

Generate code samples from OpenAPI specifications

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

OACodeSampleGenerator

Build Status

npm

Generate request snippets, a request body, and response models for each operation in a given Swagger/OpenAPI specification.

Currently generated: Java, Python, C#

Part of the purpose for our team of this package is to be able to generate code samples for the Azure REST API and create a statically-generated site which can show the samples. This can be found at this repository.

This package has only been tested on Node.js v14+.

Installation

Install using npm:

npm install oacodesamplegenerator

Example Usage

const generator = require('oacodesamplegenerator');

const specURL =
  'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/resources.json';

(async () => {
  // To generate samples for every operation in the spec
  try {
    const { generated } = await generator(specURL);

    console.log(`Samples generated for:\n${generated.map((op) => op.operationId).join('\n')}\n`);
  } catch (err) {
    console.error(err);
  }

  // To generate samples for just one operation in the spec
  try {
    const singleOperation = 'ResourceGroups_CreateOrUpdate';
    const { generated } = await generator(specURL, singleOperation); // See example/generated.json
    const operationSamples = generated[0];
    // This can also alternatively be done like such:
    // const operationSamples = (await generator(specURL)).generated.find(
    //   (op) => op.operationId === singleOperation
    // );

    [
      'javaSnippet',
      'pythonSnippet',
      'csharpSnippet',
      'requestBody',
      'javaModel',
      'pythonModel',
      'csharpModel',
    ].forEach((sample) => {
      console.log('----------------------------------------------------------\n\n');
      console.log(`${singleOperation} - ${sample}:\n\n${operationSamples[sample]}`);
    });
  } catch (err) {
    console.error(err);
  }
})();

FAQs

Package last updated on 06 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts