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 for iso3166.CountryCode is not OpenAPI 3.0 compatible (?) #197

Open
flaeppe opened this issue Mar 21, 2022 · 1 comment
Open

Schema for iso3166.CountryCode is not OpenAPI 3.0 compatible (?) #197

flaeppe opened this issue Mar 21, 2022 · 1 comment

Comments

@flaeppe
Copy link
Contributor

flaeppe commented Mar 21, 2022

I have a pydantic model set up like this:

class MyModel(pydantic.BaseModel):
    country_code: CountryCode

Then I run a OpenAPI schema validator against the generated schema found here: https://github.com/p1c2u/openapi-spec-validator

Getting an issue in the anyOf below, on examples. Not sure if it's misplaced?

{
  "type": "string",
  "title": "Alpha2",
  "description": "ISO3166-1 alpha-2 country code",
  "examples": [
    "NR",
    "KZ",
    "ET",
    "VC",
    "AE",
    "NZ",
    "SX",
    "XK",
    "AX"
  ],
  "format": "iso3166-1 alpha-2"
}

Anyways, removing examples from there everything works fine. Perhaps it should move someplace else? I tried moving it on the "root" level of the field object (sibling to anyOf) but that didn't work either.

@antonagestam
Copy link
Owner

As discussed offline, phantom-types advertises support for Pydantic, not for OpenAPI directly.

Pydantic uses "examples" in their documentation so it feels like this should be opened as an issue there. I suspect a framework could be made aware of when and where "examples" is allowed, and omit it when needed, though I have no idea if that is something that's implemented or not.

If it turns out that the combining for instance FastAPI + Pydantic + phantom-types produces an illegal schema due to the "examples" key, I'll consider removing it! 🙂

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