Add operation-paths heyapi plugin
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { defineConfig } from "@hey-api/openapi-ts";
|
||||
import { defaultPlugins } from "@hey-api/openapi-ts";
|
||||
import { defineConfig as operationPathsConfig } from "./src/openapi/plugins/operation-paths";
|
||||
|
||||
export default defineConfig({
|
||||
input: "https://v4.goteo.org/v4/docs.json",
|
||||
@@ -13,5 +14,6 @@ export default defineConfig({
|
||||
{
|
||||
name: "@hey-api/sdk",
|
||||
},
|
||||
operationPathsConfig()
|
||||
],
|
||||
});
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Plugin } from '@hey-api/openapi-ts';
|
||||
|
||||
import { handler } from './plugin';
|
||||
import type { Config } from './types';
|
||||
|
||||
export const defaultConfig: Plugin.Config<Config> = {
|
||||
_dependencies: ['@hey-api/typescript'],
|
||||
_handler: handler,
|
||||
_handlerLegacy: () => { },
|
||||
name: 'operation-paths',
|
||||
output: 'paths',
|
||||
};
|
||||
|
||||
export const defineConfig: Plugin.DefineConfig<Config> = (config) => ({
|
||||
...defaultConfig,
|
||||
...config,
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
export { defaultConfig, defineConfig } from './config';
|
||||
export type { Config } from './types';
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Plugin } from '@hey-api/openapi-ts';
|
||||
|
||||
import type { Config } from './types';
|
||||
|
||||
export const handler: Plugin.Handler<Config> = ({ context, plugin }) => {
|
||||
const file = context.createFile({
|
||||
id: plugin.name,
|
||||
path: plugin.output,
|
||||
});
|
||||
|
||||
context.subscribe('operation', ({ operation }) => {
|
||||
const url = operation.path.replace(/{\w+}/g, (match) => `\${${match.slice(1, -1)}}`);
|
||||
const node = `export const ${operation.id}Url = '${url}';`;
|
||||
|
||||
file.add(node);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface Config {
|
||||
name: 'operation-paths';
|
||||
|
||||
/**
|
||||
* @default 'operation-paths'
|
||||
*/
|
||||
output?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user