phantom-types icon indicating copy to clipboard operation
phantom-types copied to clipboard

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

Open flaeppe opened this issue 3 years ago • 1 comments

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.

flaeppe avatar Mar 21 '22 08:03 flaeppe

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! 🙂

antonagestam avatar Mar 21 '22 08:03 antonagestam