Skip to content

Commit 84944e8

Browse files
committed
chore: cleanup
1 parent 6342479 commit 84944e8

File tree

8 files changed

+105
-429
lines changed

8 files changed

+105
-429
lines changed

packages/openapi-ts/src/plugins/@hey-api/typescript/operation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { schemaToType } from './plugin';
99
import { typesId } from './ref';
1010
import type { HeyApiTypeScriptPlugin, PluginState } from './types';
1111

12-
const irParametersToIrSchema = ({
12+
// TODO: exported just for @pinia/colada, remove export once that plugin does not depend on it
13+
export const irParametersToIrSchema = ({
1314
parameters,
1415
}: {
1516
parameters: Record<string, IR.ParameterObject>;

packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts

Lines changed: 0 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -482,281 +482,6 @@ const schemaTypeToIdentifier = ({
482482
}
483483
};
484484

485-
export const irParametersToIrSchema = ({
486-
parameters,
487-
}: {
488-
parameters: Record<string, IR.ParameterObject>;
489-
}): IR.SchemaObject => {
490-
const irSchema: IR.SchemaObject = {
491-
type: 'object',
492-
};
493-
494-
if (parameters) {
495-
const properties: Record<string, IR.SchemaObject> = {};
496-
const required: Array<string> = [];
497-
498-
for (const name in parameters) {
499-
const parameter = parameters[name]!;
500-
501-
properties[name] = deduplicateSchema({
502-
schema: parameter.schema,
503-
});
504-
505-
if (parameter.required) {
506-
required.push(name);
507-
}
508-
}
509-
510-
irSchema.properties = properties;
511-
512-
if (required.length) {
513-
irSchema.required = required;
514-
}
515-
}
516-
517-
return irSchema;
518-
};
519-
520-
const operationToDataType = ({
521-
context,
522-
operation,
523-
plugin,
524-
}: {
525-
context: IR.Context;
526-
operation: IR.OperationObject;
527-
plugin: Plugin.Instance<Config>;
528-
}) => {
529-
const file = context.file({ id: typesId })!;
530-
const data: IR.SchemaObject = {
531-
type: 'object',
532-
};
533-
const dataRequired: Array<string> = [];
534-
535-
if (!data.properties) {
536-
data.properties = {};
537-
}
538-
539-
if (operation.body) {
540-
data.properties.body = operation.body.schema;
541-
542-
if (operation.body.required) {
543-
dataRequired.push('body');
544-
}
545-
} else {
546-
data.properties.body = {
547-
type: 'never',
548-
};
549-
}
550-
551-
// TODO: parser - handle cookie parameters
552-
553-
// do not set headers to never so we can always pass arbitrary values
554-
if (operation.parameters?.header) {
555-
data.properties.headers = irParametersToIrSchema({
556-
parameters: operation.parameters.header,
557-
});
558-
559-
if (data.properties.headers.required) {
560-
dataRequired.push('headers');
561-
}
562-
}
563-
564-
if (operation.parameters?.path) {
565-
data.properties.path = irParametersToIrSchema({
566-
parameters: operation.parameters.path,
567-
});
568-
569-
if (data.properties.path.required) {
570-
dataRequired.push('path');
571-
}
572-
} else {
573-
data.properties.path = {
574-
type: 'never',
575-
};
576-
}
577-
578-
if (operation.parameters?.query) {
579-
data.properties.query = irParametersToIrSchema({
580-
parameters: operation.parameters.query,
581-
});
582-
583-
if (data.properties.query.required) {
584-
dataRequired.push('query');
585-
}
586-
} else {
587-
data.properties.query = {
588-
type: 'never',
589-
};
590-
}
591-
592-
data.properties.url = {
593-
const: operation.path,
594-
type: 'string',
595-
};
596-
dataRequired.push('url');
597-
598-
data.required = dataRequired;
599-
600-
const identifier = file.identifier({
601-
$ref: operationIrRef({ id: operation.id, type: 'data' }),
602-
create: true,
603-
namespace: 'type',
604-
});
605-
const type = schemaToType({
606-
context,
607-
plugin,
608-
schema: data,
609-
state:
610-
plugin.readOnlyWriteOnlyBehavior === 'off'
611-
? undefined
612-
: {
613-
accessScope: 'write',
614-
},
615-
});
616-
617-
if (type) {
618-
const node = compiler.typeAliasDeclaration({
619-
exportType: true,
620-
name: identifier.name || '',
621-
type,
622-
});
623-
file.add(node);
624-
}
625-
};
626-
627-
const operationToType = ({
628-
context,
629-
operation,
630-
plugin,
631-
}: {
632-
context: IR.Context;
633-
operation: IR.OperationObject;
634-
plugin: Plugin.Instance<Config>;
635-
}) => {
636-
operationToDataType({
637-
context,
638-
operation,
639-
plugin,
640-
});
641-
642-
const file = context.file({ id: typesId })!;
643-
644-
const { error, errors, response, responses } =
645-
operationResponsesMap(operation);
646-
647-
if (errors) {
648-
const identifierErrors = file.identifier({
649-
$ref: operationIrRef({ id: operation.id, type: 'errors' }),
650-
create: true,
651-
namespace: 'type',
652-
});
653-
if (identifierErrors.name) {
654-
const type = schemaToType({
655-
context,
656-
plugin,
657-
schema: errors,
658-
state:
659-
plugin.readOnlyWriteOnlyBehavior === 'off'
660-
? undefined
661-
: {
662-
accessScope: 'read',
663-
},
664-
});
665-
666-
if (type) {
667-
const node = compiler.typeAliasDeclaration({
668-
exportType: true,
669-
name: identifierErrors.name,
670-
type,
671-
});
672-
file.add(node);
673-
}
674-
675-
if (error) {
676-
const identifierError = file.identifier({
677-
$ref: operationIrRef({ id: operation.id, type: 'error' }),
678-
create: true,
679-
namespace: 'type',
680-
});
681-
if (identifierError.name) {
682-
const errorsType = compiler.typeReferenceNode({
683-
typeName: identifierErrors.name,
684-
});
685-
const keyofType = ts.factory.createTypeOperatorNode(
686-
ts.SyntaxKind.KeyOfKeyword,
687-
errorsType,
688-
);
689-
const node = compiler.typeAliasDeclaration({
690-
exportType: true,
691-
name: identifierError.name,
692-
type: compiler.indexedAccessTypeNode({
693-
indexType: keyofType,
694-
objectType: errorsType,
695-
}),
696-
});
697-
file.add(node);
698-
}
699-
}
700-
}
701-
}
702-
703-
if (responses) {
704-
const identifierResponses = file.identifier({
705-
$ref: operationIrRef({ id: operation.id, type: 'responses' }),
706-
create: true,
707-
namespace: 'type',
708-
});
709-
if (identifierResponses.name) {
710-
const type = schemaToType({
711-
context,
712-
plugin,
713-
schema: responses,
714-
state:
715-
plugin.readOnlyWriteOnlyBehavior === 'off'
716-
? undefined
717-
: {
718-
accessScope: 'read',
719-
},
720-
});
721-
722-
if (type) {
723-
const node = compiler.typeAliasDeclaration({
724-
exportType: true,
725-
name: identifierResponses.name,
726-
type,
727-
});
728-
file.add(node);
729-
}
730-
731-
if (response) {
732-
const identifierResponse = file.identifier({
733-
$ref: operationIrRef({ id: operation.id, type: 'response' }),
734-
create: true,
735-
namespace: 'type',
736-
});
737-
if (identifierResponse.name) {
738-
const responsesType = compiler.typeReferenceNode({
739-
typeName: identifierResponses.name,
740-
});
741-
const keyofType = ts.factory.createTypeOperatorNode(
742-
ts.SyntaxKind.KeyOfKeyword,
743-
responsesType,
744-
);
745-
const node = compiler.typeAliasDeclaration({
746-
exportType: true,
747-
name: identifierResponse.name,
748-
type: compiler.indexedAccessTypeNode({
749-
indexType: keyofType,
750-
objectType: responsesType,
751-
}),
752-
});
753-
file.add(node);
754-
}
755-
}
756-
}
757-
}
758-
};
759-
760485
export const schemaToType = ({
761486
onRef,
762487
plugin,

packages/openapi-ts/src/plugins/@pinia/colada/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { PiniaColadaPlugin } from './types';
44

55
export const defaultConfig: PiniaColadaPlugin['Config'] = {
66
config: {
7-
enableCaching: false,
87
enablePaginationOnKey: undefined,
98
errorHandling: 'specific',
109
exportFromIndex: false,

packages/openapi-ts/src/plugins/@pinia/colada/mutation.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { TypeScriptFile } from '../../../generate/files';
1+
import type { GeneratedFile } from '../../../generate/file';
22
import type { IR } from '../../../ir/types';
3-
import type { Plugin } from '../../types';
4-
import type { Config } from './types';
3+
import type { PiniaColadaPlugin } from './types';
54
import { createComposable } from './utils';
65

76
/**
@@ -14,12 +13,12 @@ export const createMutationFunction = ({
1413
plugin,
1514
}: {
1615
context: IR.Context;
17-
file: TypeScriptFile;
16+
file: GeneratedFile;
1817
operation: IR.OperationObject;
19-
plugin: Plugin.Instance<Config>;
18+
plugin: PiniaColadaPlugin['Instance'];
2019
}) => {
2120
// Allow hooks to customize or skip mutation generation
22-
if (plugin?.onMutation && plugin.onMutation(operation) === false) {
21+
if (plugin.config.onMutation && plugin.config.onMutation(operation) === false) {
2322
return;
2423
}
2524

0 commit comments

Comments
 (0)