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 · 0 comments
Open

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

s2quake opened this issue Aug 8, 2024 · 0 comments

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();
}
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

1 participant