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

Schema type inference should take format into account #528

Open
boneskull opened this issue Jun 1, 2023 · 3 comments
Open

Schema type inference should take format into account #528

boneskull opened this issue Jun 1, 2023 · 3 comments

Comments

@boneskull
Copy link

I'm not sure if support for the ipv6 format was implemented or if it was intended to be implemented, but using a string prop with an anyOf [{format: 'hostname'}, {format: 'ipv6'}], the result is string and {[key: string]: unknown}, where hostname converts to string.

ipv6 should also convert to string.

ref: appium/appium#18690

@bcherny
Copy link
Owner

bcherny commented Jun 10, 2023

We don't take format into account when inferring a schema's type. Without a full example, I'm not sure why you're getting string at all.

To get string, add "type": "string" to your schema:

{
  "type": "object",
  "properties": {
    "a": {
      "format": "hostname",
      "type": "string"
    }
  }
}

Separately, we should improve type inference to select the appropriate type for common values of format.

@bcherny bcherny changed the title format: ipv6 seems unrecognized Schema type inference should take format into account Jun 10, 2023
@boneskull
Copy link
Author

boneskull commented Jun 29, 2023

@bcherny Thanks. The code was:

{
  "type": "string",
  "anyOf": [
    {"format": "hostname"},
    {"format": "ipv6"}
  ]
}

Changing it to this solved the problem:

{
  "type": "string",
  "anyOf": [
    {"format": "hostname", "type": "string"},
    {"format": "ipv6", "type": "string"}
  ]
}

So it looks like the type didn't get "inherited". I'm not sure if that's what should be happening?

@boneskull
Copy link
Author

boneskull commented Jun 29, 2023

though, curiously, hostname did get converted to string, but ipv6 did not. (I can speculate that there's a bug where only the first item in an anyOf inherits its type from its parent)

boneskull added a commit to appium/appium that referenced this issue Jun 29, 2023
This resolves #18716.

For whatever reason, `json-schema-to-typescript` needed `"type": "string"` in there.  See bcherny/json-schema-to-typescript#528 for further discussion
jlipps pushed a commit to appium/appium that referenced this issue Jun 30, 2023
This resolves #18716.

For whatever reason, `json-schema-to-typescript` needed `"type": "string"` in there.  See bcherny/json-schema-to-typescript#528 for further discussion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants