-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multiple schema distinction in validation
- Loading branch information
Petr Spacek
committed
Feb 23, 2021
1 parent
f0c5594
commit a000f88
Showing
13 changed files
with
372 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { JSONSchema } from '../jsonSchema'; | ||
|
||
export function getSchemaTypeName(schema: JSONSchema): string { | ||
if (schema.$id) { | ||
const type = getSchemaRefTypeTitle(schema.$id); | ||
return type; | ||
} | ||
if (schema.$ref || schema._$ref) { | ||
const type = getSchemaRefTypeTitle(schema.$ref || schema._$ref); | ||
return type; | ||
} | ||
const typeStr = schema.title || (Array.isArray(schema.type) ? schema.type.join(' | ') : schema.type); //object | ||
return typeStr; | ||
} | ||
|
||
/** | ||
* Get type name from reference url | ||
* @param $ref reference to the same file OR to the another component OR to the section in another component: | ||
* `schema-name.schema.json` -> schema-name | ||
* `custom-scheme://shared-schema.json#/definitions/SomeType` -> SomeType | ||
* `custom-scheme://schema-name.schema.json` -> schema-name | ||
* `shared-schema.schema.json#/definitions/SomeType` -> SomeType | ||
* `file:///Users/user/Documents/project/schemas/schema-name.schema.json` -> schema-name | ||
* `#/definitions/SomeType` -> SomeType | ||
* `#/definitions/io.k8s.api.apps.v1.DaemonSetSpec` => io.k8s.api.apps.v1.DaemonSetSpec | ||
* `file:///default_schema_id.yaml` => default_schema_id.yaml | ||
* test: https://regex101.com/r/ZpuXxk/1 | ||
*/ | ||
export function getSchemaRefTypeTitle($ref: string): string { | ||
const match = $ref.match(/^(?:.*\/)?(.*?)(?:\.schema\.json)?$/); | ||
let type = !!match && match[1]; | ||
if (!type) { | ||
type = 'typeNotFound'; | ||
console.error(`$ref (${$ref}) not parsed properly`); | ||
} | ||
return type; | ||
} |
Oops, something went wrong.