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

Handling subschemas #51

Open
gregsdennis opened this issue Jul 9, 2023 · 2 comments
Open

Handling subschemas #51

gregsdennis opened this issue Jul 9, 2023 · 2 comments

Comments

@gregsdennis
Copy link
Member

gregsdennis commented Jul 9, 2023

Subschemas and nested types appear everywhere. Generally, a subschema will represent a new type.

{
  "type": "object",
  "properties": {
    "foo": { "type": "integer" },
    "bar": {
      "type": "object",
      "properties": {
        "numbers": {
          "type": "array",
          "items": { "type": "number" }
        }
      }
    }
  }
}

For this schema, we have four types being represented:

  • the top-level object, with properties foo and bar
  • an integer
  • an object at /properties/bar
  • a number

(#45 discusses built-in types, so we'll leave that out of this issue.)

Specifically, we need to focus on the two custom objects: the top-level and whatever bar is.

I would expect a generator to create two types from this schema. Are there any restrictions that people can see?


What happens when a subschema is duplicated?

{
  "type": "object",
  "properties": {
    "foo": { "type": "integer" },
    "bar": {
      "type": "object",
      "properties": {
        "numbers": {
          "type": "array",
          "items": { "type": "number" }
        }
      }
    },
    "baz": {
      "type": "object",
      "properties": {
        "numbers": {
          "type": "array",
          "items": { "type": "number" }
        }
      }
    }
  }
}

Here, /properties/bar and /properties/baz are identical. Is this the author's intent, or are these two semantically (business rules) different yet functionally (shape/structure) identical? Do we need a way to discern this? Maybe #50 can help identify author intent. For example, if the subschemas have the same title, it was intended that they're the same type.

($ref'd subschemas are obviously the same type.)

@spacether
Copy link

Json schema type integer allows integer and float types with integer values. Should code generation represent that as integer only? If so then that is a departure form json schema definitions.

@gregsdennis
Copy link
Member Author

I think that depends on the lanuage being generated.

Typescript doesn't have an integer type, so it won't care.

C# has both, and the serializer will actually decode 1.0 as an integer.

I don't think we can specify how individual languages support things. We can only generalize.

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