Skip to content

Commit

Permalink
fix: remove simple export in v1 schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Sep 10, 2024
1 parent 68c92f8 commit 27d0b92
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
85 changes: 37 additions & 48 deletions src/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export interface Export {
output?: Parameter;
}

export function isExport(e: any): e is Export {
return parser.isSimpleExport(e) || parser.isComplexExport(e)
}

// These are the same for now
export type Import = Export

Expand Down Expand Up @@ -208,58 +204,51 @@ function normalizeV1Schema(parsed: parser.V1Schema): XtpSchema {
for (const name in parsed.exports) {
let ex = parsed.exports[name]

if (parser.isComplexExport(ex)) {
const normEx = ex as Export
normEx.name = name
const normEx = ex as Export
normEx.name = name

if (ex.input?.$ref) {
const path = `#/exports/${name}/input`
if (ex.input?.$ref) {
const path = `#/exports/${name}/input`

normalizeProp(
normEx.input!,
querySchemaRef(schemas, ex.input.$ref, path),
path
)
}
if (ex.input?.items?.$ref) {
const path = `#/exports/${name}/input/items`
normalizeProp(
normEx.input!,
querySchemaRef(schemas, ex.input.$ref, path),
path
)
}
if (ex.input?.items?.$ref) {
const path = `#/exports/${name}/input/items`

normalizeProp(
normEx.input!.items!,
querySchemaRef(schemas, ex.input.items.$ref, path),
path
)
}
normalizeProp(
normEx.input!.items!,
querySchemaRef(schemas, ex.input.items.$ref, path),
path
)
}

if (ex.output?.$ref) {
const path = `#/exports/${name}/output`
if (ex.output?.$ref) {
const path = `#/exports/${name}/output`

normalizeProp(
normEx.output!,
querySchemaRef(schemas, ex.output.$ref, path),
path
)
}
if (ex.output?.items?.$ref) {
const path = `#/exports/${name}/output/items`
normalizeProp(
normEx.output!,
querySchemaRef(schemas, ex.output.$ref, path),
path
)
}
if (ex.output?.items?.$ref) {
const path = `#/exports/${name}/output/items`

normalizeProp(
normEx.output!.items!,
querySchemaRef(schemas, ex.output.items.$ref, path),
path
)
}
normalizeProp(
normEx.output!.items!,
querySchemaRef(schemas, ex.output.items.$ref, path),
path
)
}

validateArrayItems(normEx.input?.items, `#/exports/${name}/input/items`);
validateArrayItems(normEx.output?.items, `#/exports/${name}/output/items`);
validateArrayItems(normEx.input?.items, `#/exports/${name}/input/items`);
validateArrayItems(normEx.output?.items, `#/exports/${name}/output/items`);

exports.push(normEx)
} else if (parser.isSimpleExport(ex)) {
// it's just a name
exports.push({ name })
} else {
throw new ValidationError("Unable to match export to a simple or a complex export", `#/exports/${name}`);
}
exports.push(normEx)
}

// denormalize all the imports
Expand Down
10 changes: 1 addition & 9 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ type VUnknownSchema = V0Schema | V1Schema

export type Version = 'v0' | 'v1-draft';

export type Export = SimpleExport | ComplexExport;
export type Export = ComplexExport;

// for now, imports and exports look the same
export type Import = ComplexExport

export function isComplexExport(exportItem: Export): exportItem is ComplexExport {
return typeof exportItem === 'object' && 'description' in exportItem;
}

export function isSimpleExport(exportItem: Export): exportItem is SimpleExport {
return typeof exportItem === 'object';
}

export type SimpleExport = string;

export interface ComplexExport {
Expand Down

0 comments on commit 27d0b92

Please sign in to comment.