Skip to content

Conversation

andreif
Copy link

@andreif andreif commented Jul 4, 2023

Adds support of HTTPS ref in addition to the existing HTTP.

@andreif
Copy link
Author

andreif commented Jul 4, 2023

Tested by adding

    {
        "description": "remote ref, containing refs itself using HTTPS",
        "schema": {"$ref": "https://json-schema.org/draft-04/schema#"},
        "tests": [
            {
                "description": "remote ref valid",
                "data": {"minLength": 1},
                "valid": true
            },
            {
                "description": "remote ref invalid",
                "data": {"minLength": -1},
                "valid": false
            }
        ]
    },

to https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/main/tests/draft4/ref.json#L229

@andreif
Copy link
Author

andreif commented Jul 4, 2023

Workaround:

import Ajv from 'ajv-draft-04';
import { SchemaObject } from 'ajv';

const ajv = new Ajv();

const META_SCHEMA_ID = 'http://json-schema.org/draft-04/schema';

const httpsSchemaId = META_SCHEMA_ID.replace(/^http:/, 'https:');
const httpsSchema = ajv.getSchema(META_SCHEMA_ID)?.schema as SchemaObject;
httpsSchema.id = httpsSchema.$schema = httpsSchemaId + '#';

ajv.addMetaSchema(httpsSchema, httpsSchemaId, false);

@jeremyfiel
Copy link

the official metaschema identifier does not use https. This field is an identifier, not a network reachable resource. https doesn't matter here.

/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants