Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cmd/validate-values.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import $RefParser, { JSONSchema } from '@apidevtools/json-schema-ref-parser'
import Ajv, { ValidateFunction } from 'ajv'
import { unset } from 'lodash'
import { prepareEnvironment } from 'src/common/cli'
import { terminal } from 'src/common/debug'
import { env } from 'src/common/envalid'
import { hfValues } from 'src/common/hf'
import { getFilename, loadYaml, rootDir } from 'src/common/utils'
import { getFilename, rootDir } from 'src/common/utils'
import { getParsedArgs, HelmArguments, helmOptions, setParsedArgs } from 'src/common/yargs'
import { Argv } from 'yargs'
import { chalk } from 'zx'
Expand Down Expand Up @@ -32,7 +33,7 @@ export const validateValues = async (argv: HelmArguments = getParsedArgs(), envD
}

d.info('Loading values-schema.yaml')
const valuesSchema = (await loadYaml(`${rootDir}/values-schema.yaml`)) as Record<string, any>
const valuesSchema = (await $RefParser.dereference(`${rootDir}/values-schema.yaml`)) as Record<string, any>
d.debug('Initializing Ajv')
const ajv = new Ajv({ allErrors: true, strict: false, strictTypes: false, verbose: true })
d.debug('Compiling Ajv validation')
Expand Down
3 changes: 1 addition & 2 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ export const extract = (
let valuesSchema: Record<string, any>
export const getValuesSchema = async (): Promise<Record<string, any>> => {
if (valuesSchema) return valuesSchema
const schema = await loadYaml(`${rootDir}/values-schema.yaml`)
const derefSchema = await $RefParser.dereference(schema as JSONSchema)
const derefSchema = await $RefParser.dereference(`${rootDir}/values-schema.yaml`)
valuesSchema = omit(derefSchema, ['definitions'])

return valuesSchema
Expand Down
7 changes: 3 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import $RefParser, { JSONSchema } from '@apidevtools/json-schema-ref-parser'
import $RefParser from '@apidevtools/json-schema-ref-parser'
import express, { Request, Response } from 'express'
import { copyFile } from 'fs/promises'
import { Server } from 'http'
Expand All @@ -7,7 +7,7 @@ import { decrypt, encrypt } from 'src/common/crypt'
import { terminal } from 'src/common/debug'
import { hfValues } from './common/hf'
import { setValuesFile, unsetValuesFile } from './common/repo'
import { loadYaml, rootDir } from './common/utils'
import { rootDir } from './common/utils'
import { objectToYaml } from './common/values'

const d = terminal('server')
Expand Down Expand Up @@ -88,8 +88,7 @@ app.get('/otomi/values', async (req: Request, res: Response): Promise<void> => {
})

app.get('/apl/schema', async (req: Request, res: Response): Promise<void> => {
const schema = await loadYaml(`${rootDir}/values-schema.yaml`)
const derefSchema = await $RefParser.dereference(schema as JSONSchema)
const derefSchema = await $RefParser.dereference(`${rootDir}/values-schema.yaml`)
res.setHeader('Content-type', 'application/json')
res.status(200).send(derefSchema)
})
Expand Down
Loading
Loading