@kubb/plugin-oas
Version:
OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.
39 lines (36 loc) • 1.1 kB
text/typescript
import { camelCase } from '@internals/utils'
import type { PluginOas } from '../types.ts'
import { getBanner } from '../utils/getBanner.ts'
import { getFooter } from '../utils/getFooter.ts'
import { createGenerator } from './createGenerator.ts'
export const jsonGenerator = createGenerator<PluginOas>({
name: 'plugin-oas',
async schema({ schema, generator }) {
const { pluginManager, plugin } = generator.context
const file = pluginManager.getFile({
name: camelCase(schema.name),
extname: '.json',
mode: 'split',
pluginKey: plugin.key,
})
return [
{
...file,
sources: [
{
name: camelCase(schema.name),
isExportable: false,
isIndexable: false,
value: JSON.stringify(schema.value),
},
],
banner: getBanner({
oas: generator.context.oas,
output: plugin.options.output,
config: pluginManager.config,
}),
format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),
},
]
},
})