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

Read json schema from IConfiguration #535

Open
patelriki13 opened this issue Jan 8, 2025 · 1 comment
Open

Read json schema from IConfiguration #535

patelriki13 opened this issue Jan 8, 2025 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@patelriki13
Copy link

I am using dotnet core 9 application.
I have appsettings.json config and from that config file our application load all config into IConfiguration object.
one of sub prop. of config file have following json schema.

How to to get json or read json schema from IConfiguration?

"DefaultJsonSchema": {
    "type": "object",
    "required": [ "value", "timestamp", "ts" ],
    "properties": {
      "value": {
        "type": [ "string", "number", "boolean", "object", "array", "null" ],
        "description": "A dynamic property that can accept multiple types",
        "minLength": 1,
        "maxLength": 256
      },
      "timestamp": {
        "type": "string",
        "format": "date-time",
        "description": "A string representing the timestamp in ISO 8601 format"
      },
      "ts": {
        "type": "integer",
        "description": "A Unix timestamp as an integer"
      },
      "quality": {
        "type": "array",
        "items": {
          "type": [ "string", "null" ]
        },
        "description": "An array of strings, allowing null values"
      },
      "others": {
        "type": [ "string", "number", "boolean", "object", "array", "null" ],
        "description": "A dynamic property that can accept multiple types"
      }
    }
  }
@mwadams mwadams self-assigned this Jan 12, 2025
@mwadams mwadams added the question Further information is requested label Jan 12, 2025
@mwadams
Copy link
Contributor

mwadams commented Jan 12, 2025

Unfortunately, this is non-trivial as IConfiguration is entirely dynamic under the covers. It doesn't actually expose "json" to you in any way - at least, not unless you encode the JSON as a string value.
In part, this is because it supports destructuring values e.g. via Environment Variables, and not just "JSON" config files.

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

No branches or pull requests

2 participants