Skip to content

Commit

Permalink
Revert 'Validate parsed yaml file'.
Browse files Browse the repository at this point in the history
We'll instead have the binding generator generate the opt-in spec schema file from spec.yaml in order to list all classes and records with their corresponding methods and fields. The validation would then also provide autocomplete in the opt-in spec file.
  • Loading branch information
elle-j committed Jun 15, 2023
1 parent 05a618f commit 8c7eeb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
12 changes: 1 addition & 11 deletions bindgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,7 @@ add_custom_command(
# (Right now there are no imports)
)

set(OPT_IN_SCHEMA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/generated/opt-in-spec.schema.json)
add_custom_command(
OUTPUT ${OPT_IN_SCHEMA_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${NPX} typescript-json-schema ${CMAKE_CURRENT_SOURCE_DIR}/tsconfig.json OptInSpec --include ${CMAKE_CURRENT_SOURCE_DIR}/src/spec/model.ts --out ${OPT_IN_SCHEMA_FILE} --required --noExtraProps
VERBATIM
MAIN_DEPENDENCY src/spec/model.ts
DEPENDS
)

add_custom_target(BindgenSpecJsonSchema DEPENDS ${SCHEMA_FILE} ${OPT_IN_SCHEMA_FILE})
add_custom_target(BindgenSpecJsonSchema DEPENDS ${SCHEMA_FILE})

# Stash these variables as properties so they can be read from the bindgen() function.
# Using the BindgenSpecJsonSchema target for scoping, not because it actually has anything to do with that.
Expand Down
14 changes: 5 additions & 9 deletions bindgen/src/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ const schemaFile = new URL("../generated/spec.schema.json", import.meta.url);
const schemaJson = JSON.parse(fs.readFileSync(schemaFile, { encoding: "utf8" }));
export const validate = ajv.compile<RelaxedSpec>(schemaJson);

const optInSchemaFile = new URL("../generated/opt-in-spec.schema.json", import.meta.url);
const optInSchemaJson = JSON.parse(fs.readFileSync(optInSchemaFile, { encoding: "utf8" }));
export const validateOptInSpec = ajv.compile<OptInSpec>(optInSchemaJson);

function parseYaml(filePath: string): unknown {
const text = fs.readFileSync(filePath, { encoding: "utf8" });
return yaml.parse(text);
Expand Down Expand Up @@ -117,11 +113,11 @@ export function parseSpec(filePath: string): AnySpec {

export function parseOptInSpec(filePath: string): OptInSpec {
const parsed = parseYaml(filePath);
const isValid = validateOptInSpec(parsed);
if (isValid) {
return parsed;
}
throw new InvalidSpecError(filePath, validateOptInSpec.errors || []);

// TODO:
// Validate parsed spec.

return parsed as OptInSpec;
}

/**
Expand Down

0 comments on commit 8c7eeb0

Please sign in to comment.