Registry / devops / swagger-schema-official

swagger-schema-official

JSON →
library2.0.0-bab6bedjsnpmunverified

JSON Schema files for Swagger/OpenAPI 2.0 specification. Current stable version is 2.0.0-bab6bed, which is the official JSON Schema for Swagger 2.0. This package provides the schema definition for validating Swagger 2.0 API documents. It is used by tools like Swagger UI and Swagger Editor. Note that it does not cover OpenAPI 3.x, which has its own schema packages. Release cadence is low, as it only updates when the Swagger specification changes.

npm install swagger-schema-official
INSTALL
IMPORT
SIG · SWAGGER-SCHEMA-OFF
S
swagger-schema-official
devopsjavascriptv2.0.0-bab6bed
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

swaggerSchema
import swaggerSchema from 'swagger-schema-official'
const swaggerSchema = require('swagger-schema-official')
The package exports a JSON object as default. ESM works but requires 'assert { type: "json" }' in Node.js; CommonJS works directly.
swaggerSchema
const swaggerSchema = require('swagger-schema-official')
CommonJS import, works as expected.
Swagger
import type { Swagger } from 'swagger-schema-official'
import { Swagger } from 'swagger-schema-official'
The package does not export TypeScript types. Developers sometimes expect a 'Swagger' type export, but it is only a JSON schema file.

Validates a Swagger 2.0 document using AJV with the official schema.

const Ajv = require('ajv'); const swaggerSchema = require('swagger-schema-official'); const ajv = new Ajv(); const validate = ajv.compile(swaggerSchema); const valid = validate({ swagger: '2.0', info: { title: 'Test', version: '1.0.0' }, paths: { '/': { get: { responses: { '200': { description: 'OK' } } } } } }); console.log(valid ? 'Valid' : 'Invalid'); console.log(validate.errors);
Debug
Known issues
gotchaThis package only covers Swagger 2.0 (OpenAPI 2.0). Do not use it for OpenAPI 3.x documents.
fix
Use @apidevtools/swagger-parser or openapi-schema-validator for OpenAPI 3.x.
affects: >=2.0.0
gotchaThe version number '2.0.0-bab6bed' is not a semver release. It indicates a build artifact from a specific commit.
fix
Pin to exact version in package.json to avoid unexpected updates.
affects: 2.0.0-bab6bed
deprecatedBower is deprecated. The package still references Bower installation.
fix
Use npm or yarn for package management.
affects: >=2.0.0
gotchaThe schema is a raw JSON file, not a JavaScript module with types. TypeScript users may need to declare a module.
fix
Add a declaration file: declare module 'swagger-schema-official' { const schema: object; export default schema; }
affects: >=2.0.0
gotchaThe schema file is large (~60KB) and may cause performance issues if loaded synchronously in the browser.
fix
Use asynchronous loading or tree-shaking if possible.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'swagger-schema-official'
Package not installed or wrong import path.
fix
Run 'npm install swagger-schema-official'
Unexpected token: punc (.)
Attempting to parse JSON as JavaScript module without proper import syntax.
fix
Use 'require' or add 'assert { type: "json" }' with ESM imports.
Upgrade
Version history
2.0.0-bab6bedlatest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
swagger-schema-official — npm install swagger-schema-official · libregistry