Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

3.0 KB
Raw Blame
/**
 * When making changes to this file, remove this the file name from .eslintignore and tsconfig.json
 * The reason this is required because of the moduleResolution being "node". Changing this is a more detailed effort.
 * So, until then, we will keep this file ignored for eslint and typescript.
 */

import { defineConfig } from 'orval';

export default defineConfig({
	signoz: {
		input: {
			target: '../docs/api/openapi.yml',
			// Perses' `common.JSONRef` (used by `DashboardGridItem.content`) has a
			// field tagged `json:"$ref"`, so our spec contains a property literally
			// named `$ref`.
			// Orval v8's validator (`@scalar/openapi-parser`) treats every `$ref` key
			// as a JSON Reference and aborts with `INVALID_REFERENCE` when the value isn't a URI string.
			// Safe to disable: yes, the spec is generated by `cmd/openapi.go` and gated by backend CI, not hand-edited.
			unsafeDisableValidation: true,
		},
		output: {
			target: './src/api/generated/services',
			client: 'react-query',
			httpClient: 'axios',
			mode: 'tags-split',
			prettier: true,
			headers: true,
			clean: true,
			override: {
				query: {
					// Leave useQuery/useMutation unset. Orval's verb tiebreak
					// (`if (verb === GET && isMutation) isQuery = false`) inverts every
					// operation when both are forced to true: GET becomes a mutation and
					// the write verbs become queries.
					useInvalidate: true,
					signal: true,
					useOperationIdAsQueryKey: false,
				},
				useDates: false,
				useNamedParameters: true,
				enumGenerationType: 'enum',
				mutator: {
					path: './src/api/generatedAPIInstance.ts',
					name: 'GeneratedAPIInstance',
				},

				jsDoc: {
					filter: (schema) => {
						const allowlist = [
							'type',
							'format',
							'maxLength',
							'minLength',
							'description',
							'minimum',
							'maximum',
							'exclusiveMinimum',
							'exclusiveMaximum',
							'pattern',
							'nullable',
							'enum',
						];
						return Object.entries(schema || {})
							.filter(([key]) => allowlist.includes(key))
							.map(([key, value]: [string, any]) => ({
								key,
								value,
							}))
							.sort((a, b) => a.key.length - b.key.length);
					},
				},

				components: {
					schemas: {
						suffix: 'DTO',
					},
					responses: {
						suffix: 'Response',
					},
					parameters: {
						suffix: 'Params',
					},
					requestBodies: {
						suffix: 'Body',
					},
				},

				// info is of type InfoObject from openapi spec
				header: (info: { title: string; version: string }): string[] => [
					`! Do not edit manually`,
					`* The file has been auto-generated using Orval for SigNoz`,
					`* regenerate with 'pnpm generate:api'`,
					...(info.title ? [info.title] : []),
					...(info.version ? [`OpenAPI spec version: ${info.version}`] : []),
				],

				// @ts-expect-error
				// propertySortOrder, urlEncodeParameters, aliasCombinedTypes
				// are valid options in the document without types
				propertySortOrder: 'Alphabetical',
				urlEncodeParameters: true,
				aliasCombinedTypes: true,
			},
		},
	},
});