Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I create a schema that uses URLs as $ref value? #1722

Open
s2quake opened this issue Aug 8, 2024 · 1 comment
Open

How can I create a schema that uses URLs as $ref value? #1722

s2quake opened this issue Aug 8, 2024 · 1 comment

Comments

@s2quake
Copy link

s2quake commented Aug 8, 2024

Hi I would like to use NJsonSchema to generate the following schema.
However, no matter what I tried, I was unable to generate the following schema.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "allOf": [
    {
      "$ref": "https://json.schemastore.org/appsettings.json"
    }
  ]
}

The code below is the code I tried to create the schema like above. How can I create a schema like the one above?

public string ToJson()
{
    var appsettingsUrl = "https://json.schemastore.org/appsettings.json";
    var appsettingsSchema = new JsonSchema
    {
        DocumentPath = appsettingsUrl,
        Id = appsettingsUrl,
    };

    var appSchema = new JsonSchema
    {
        SchemaVersion = "http://json-schema.org/draft-07/schema#",
        AllOf =
        {
            new JsonSchema
            {
                Reference = appsettingsSchema,
            },
        },
    };

    return appSchema.ToJson();
}
@sla89
Copy link

sla89 commented Oct 28, 2024

The problem is, that the SchemaVersion is hard coded, see

var oldSchema = SchemaVersion;
SchemaVersion = "http://json-schema.org/draft-04/schema#";
var json = JsonSchemaSerialization.ToJson(this, SerializationSchemaType, ContractResolver.Value, formatting);
SchemaVersion = oldSchema;
return json;

...so it cannot be changed...

Any plan to support a newer version like the latest ones from 2022, see here

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

No branches or pull requests

2 participants