Swagger schema properties ignored - why?

620 Views Asked by At

I'm trying to build a simple Swagger model:

PlayerConfig:
  type: object
  required:
    - kind
    - player_id
  properties:
    kind:
      type: string
      example: PlayerConfig
    player_id:
      type: string
      example: "foo"
      description: "bar"

sports_config:
  oneOf:
    - $ref: '#/components/schemas/PlayerConfig'
  discriminator:
    propertyName: kind

For some reason the generated HTML does not show the player_id's example field. This makes me think I'm not doing this correctly.s

So the question is if using a model as a type can in fact be done as I'm trying to do. example field does get rendered if its parent is parameters: instead of properties:.

Update: I read Object and Property Examples section on https://swagger.io/docs/specification/adding-examples/ and it seems like my code snippet should have worked.

Update #2: I actually downloaded redoc-cli (which is a CLI tool for OpenAPI -> html bundle) and took a sample spec from Swagger Editor that has example field under properties that mimics my problem and it looks like it's expected (see the screenshot I attached): enter image description here

1

There are 1 best solutions below

3
On

If the string value contains spaces (or some other special characters), you should enclose it in quotes. So the line should read

  example: "LeBron James"